34 #include "DGtal/base/Common.h"
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"
42 #include "DGtal/geometry/curves/FreemanChain.h"
43 #include "DGtal/geometry/curves/GridCurve.h"
46 #include "DGtal/geometry/curves/BinomialConvolver.h"
54 using namespace DGtal;
109 int main(
int argc,
char** argv )
113 std::string fileName;
116 app.description(
"Estimates curvature using length of most centered segment computers.\n Typical use example:\n \t curvatureMCMS [options] --input <fileName>\n");
117 app.add_option(
"-i,--input,1",fileName,
"Input FreemanChain file name")->required()->check(CLI::ExistingFile);
118 app.add_option(
"--GridStep", h,
"Grid step",
true);
120 app.get_formatter()->column_width(40);
121 CLI11_PARSE(app, argc, argv);
125 typedef Z2i::Space Space;
126 typedef Space::Point Point;
127 typedef Space::Integer Integer;
128 typedef FreemanChain<Integer> FreemanChain;
129 typedef std::vector< Point > Storage;
130 typedef Storage::const_iterator ConstIteratorOnPoints;
132 std::vector< FreemanChain > vectFcs = PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
135 for(
unsigned int i=0; i<vectFcs.size(); i++){
137 bool isClosed = vectFcs.at(i).isClosed();
138 std::cout <<
"# grid curve " << i+1 <<
"/" << vectFcs.size() <<
" "
139 << ( (isClosed)?
"closed":
"open" ) << std::endl;
142 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
145 std::cout <<
"# Curvature estimation from binomial convolution" << std::endl;
146 typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
147 std::cout <<
"# mask size = " <<
148 MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
149 typedef CurvatureFromBinomialConvolverFunctor< MyBinomialConvolver, double >
151 BinomialConvolverEstimator< MyBinomialConvolver, CurvatureBCFct> BCCurvatureEstimator;
153 BCCurvatureEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
155 std::vector <double> curvatures( vectPts.size() );
156 BCCurvatureEstimator.eval( vectPts.begin(), vectPts.end(), curvatures.begin() );
159 std::cout <<
"# id curvature" << std::endl;
161 for ( ConstIteratorOnPoints it = vectPts.begin(), it_end = vectPts.end();
162 it != it_end; ++it, ++j ) {
163 std::cout << j << std::setprecision( 15 )
164 <<
" " << curvatures[ j ] << std::endl;