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"
110int main(
int argc,
char** argv )
114 std::string fileName;
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");
121 app.get_formatter()->column_width(40);
122 CLI11_PARSE(app, argc, argv);
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;
133 std::vector< FreemanChain > vectFcs = PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
136 for(
unsigned int i=0; i<vectFcs.size(); i++){
138 bool isClosed = vectFcs.at(i).isClosed();
139 std::cout <<
"# grid curve " << i+1 <<
"/" << vectFcs.size() <<
" "
140 << ( (isClosed)?
"closed":
"open" ) << std::endl;
143 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
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 >
152 BinomialConvolverEstimator< MyBinomialConvolver, CurvatureBCFct> BCCurvatureEstimator;
154 BCCurvatureEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
156 std::vector <double> curvatures( vectPts.size() );
157 BCCurvatureEstimator.eval( vectPts.begin(), vectPts.end(), curvatures.begin() );
160 std::cout <<
"# id curvature" << std::endl;
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;