DGtalTools 2.0.0
Loading...
Searching...
No Matches
curvatureBC.cpp
1
32#include <iostream>
33
34#include "DGtal/base/Common.h"
35
36#include "DGtal/shapes/ShapeFactory.h"
37#include "DGtal/shapes/Shapes.h"
38#include "DGtal/helpers/StdDefs.h"
39#include "DGtal/topology/helpers/Surfaces.h"
40
41//Grid curve
42#include "DGtal/geometry/curves/FreemanChain.h"
43#include "DGtal/geometry/curves/GridCurve.h"
44
45//Estimators
46#include "DGtal/geometry/curves/BinomialConvolver.h"
47
48#include "CLI11.hpp"
49
50#include <vector>
51#include <string>
52#include <iomanip>
53
54using namespace DGtal;
55
56
57
109
110int main( int argc, char** argv )
111{
112 // parse command line CLI ----------------------------------------------
113 CLI::App app;
114 std::string fileName;
115 double h {1.0};
116
117 app.description("Estimates curvature using length of most centered segment computers.\n Typical use example:\n \t curvatureMCMS [options] --input <fileName>\n");
118 app.add_option("-i,--input,1",fileName,"Input FreemanChain file name")->required()->check(CLI::ExistingFile);
119 app.add_option("--GridStep", h, "Grid step");
120
121 app.get_formatter()->column_width(40);
122 CLI11_PARSE(app, argc, argv);
123 // END parse command line using CLI ----------------------------------------------
124
125
126 typedef Z2i::Space Space;
127 typedef Space::Point Point;
128 typedef Space::Integer Integer;
129 typedef FreemanChain<Integer> FreemanChain;
130 typedef std::vector< Point > Storage;
131 typedef Storage::const_iterator ConstIteratorOnPoints;
132
133 std::vector< FreemanChain > vectFcs = PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
134
135
136 for(unsigned int i=0; i<vectFcs.size(); i++){
137
138 bool isClosed = vectFcs.at(i).isClosed();
139 std::cout << "# grid curve " << i+1 << "/" << vectFcs.size() << " "
140 << ( (isClosed)?"closed":"open" ) << std::endl;
141
142 Storage vectPts;
143 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
144
145 // Binomial
146 std::cout << "# Curvature estimation from binomial convolution" << std::endl;
147 typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
148 std::cout << "# mask size = " <<
149 MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
150 typedef CurvatureFromBinomialConvolverFunctor< MyBinomialConvolver, double >
151 CurvatureBCFct;
152 BinomialConvolverEstimator< MyBinomialConvolver, CurvatureBCFct> BCCurvatureEstimator;
153
154 BCCurvatureEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
155
156 std::vector <double> curvatures( vectPts.size() );
157 BCCurvatureEstimator.eval( vectPts.begin(), vectPts.end(), curvatures.begin() );
158
159 // Output
160 std::cout << "# id curvature" << std::endl;
161 unsigned int j = 0;
162 for ( ConstIteratorOnPoints it = vectPts.begin(), it_end = vectPts.end();
163 it != it_end; ++it, ++j ) {
164 std::cout << j << std::setprecision( 15 )
165 << " " << curvatures[ j ] << std::endl;
166 }
167
168 }
169
170
171 return 0;
172}
173
Definition ATu0v1.h:57