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/ArithmeticalDSSComputer.h"
47 #include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
48 #include "DGtal/geometry/curves/estimation/SegmentComputerEstimators.h"
57 using namespace DGtal;
117 template<
typename I,
typename O>
118 void estimationFromLength(
double h,
const I& itb,
const I& ite,
const O& ito )
120 typedef ArithmeticalDSSComputer<I,int,4> SegmentComputer;
122 typedef CurvatureFromDSSLengthEstimator<SegmentComputer> SCEstimator;
124 typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> Estimator;
125 Estimator CurvatureEstimator(sc, f);
127 CurvatureEstimator.eval( itb, ite, ito, h );
138 template<
typename I,
typename O>
139 void estimationFromLengthAndWidth(
double h,
const I& itb,
const I& ite,
const O& ito )
141 typedef ArithmeticalDSSComputer<I,int,4> SegmentComputer;
143 typedef CurvatureFromDSSEstimator<SegmentComputer> SCEstimator;
145 typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> Estimator;
146 Estimator CurvatureEstimator(sc, f);
148 CurvatureEstimator.eval( itb, ite, ito, h );
154 int main(
int argc,
char** argv )
161 app.description(
"Estimates curvature using length of most centered segment computers.\n Typical use example:\n \t curvatureMCMS [options] --input <fileName>\n");
162 app.add_option(
"-i,--input, 1",fileName,
"Input FreemanChain file name")->required()->check(CLI::ExistingFile);
163 app.add_option(
"--GridStep", h,
"Grid step",
true);
165 app.get_formatter()->column_width(40);
166 CLI11_PARSE(app, argc, argv);
169 typedef Z2i::Space Space;
170 typedef Space::Point Point;
171 typedef Space::Integer Integer;
172 typedef Z2i::KSpace KSpace;
173 typedef FreemanChain<Integer> FreemanChain;
175 vector< FreemanChain > vectFcs = PointListReader< Point >::getFreemanChainsFromFile<Integer> (fileName);
177 for(
unsigned int i=0; i<vectFcs.size(); i++){
180 FreemanChain fc = vectFcs.at(i);
182 GridCurve<> gridcurve;
183 gridcurve.initFromPointsRange( fc.begin(), fc.end() );
185 cout <<
"# grid curve " << i+1 <<
"/"
186 << gridcurve.size() <<
" "
187 << ( (gridcurve.isClosed())?
"closed":
"open" ) << endl;
190 typedef GridCurve<KSpace>::PointsRange Range;
191 Range r = gridcurve.getPointsRange();
194 cout <<
"# Curvature estimation from maximal segments" << endl;
195 std::vector<double> estimations1;
196 std::vector<double> estimations2;
197 if (gridcurve.isOpen())
199 cout <<
"# open grid curve" << endl;
200 estimationFromLength( h, r.begin(), r.end(), back_inserter(estimations1) );
201 estimationFromLengthAndWidth( h, r.begin(), r.end(), back_inserter(estimations2) );
205 cout <<
"# closed grid curve" << endl;
206 estimationFromLength( h, r.c(), r.c(), back_inserter(estimations1) );
207 estimationFromLengthAndWidth( h, r.c(), r.c(), back_inserter(estimations2) );
211 cout <<
"# id curvatureFromLength curvatureFromLengthAndWidth" << endl;
213 for ( Range::ConstIterator it = r.begin(), itEnd = r.end();
214 it != itEnd; ++it, ++j ) {
215 cout << j << setprecision( 15 )
216 <<
" " << estimations1[ j ]
217 <<
" " << estimations2[ j ] << endl;