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"
118template<
typename I,
typename O>
119void estimationFromLength(
double h,
const I& itb,
const I& ite,
const O& ito )
121 typedef ArithmeticalDSSComputer<I,int,4> SegmentComputer;
123 typedef CurvatureFromDSSLengthEstimator<SegmentComputer> SCEstimator;
125 typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> Estimator;
126 Estimator CurvatureEstimator(sc, f);
128 CurvatureEstimator.eval( itb, ite, ito, h );
139template<
typename I,
typename O>
140void estimationFromLengthAndWidth(
double h,
const I& itb,
const I& ite,
const O& ito )
142 typedef ArithmeticalDSSComputer<I,int,4> SegmentComputer;
144 typedef CurvatureFromDSSEstimator<SegmentComputer> SCEstimator;
146 typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> Estimator;
147 Estimator CurvatureEstimator(sc, f);
149 CurvatureEstimator.eval( itb, ite, ito, h );
155int main(
int argc,
char** argv )
162 app.description(
"Estimates curvature using length of most centered segment computers.\n Typical use example:\n \t curvatureMCMS [options] --input <fileName>\n");
163 app.add_option(
"-i,--input, 1",fileName,
"Input FreemanChain file name")->required()->check(CLI::ExistingFile);
164 app.add_option(
"--GridStep", h,
"Grid step");
166 app.get_formatter()->column_width(40);
167 CLI11_PARSE(app, argc, argv);
170 typedef Z2i::Space Space;
171 typedef Space::Point Point;
172 typedef Space::Integer Integer;
173 typedef Z2i::KSpace KSpace;
174 typedef FreemanChain<Integer> FreemanChain;
176 vector< FreemanChain > vectFcs = PointListReader< Point >::getFreemanChainsFromFile<Integer> (fileName);
178 for(
unsigned int i=0; i<vectFcs.size(); i++){
181 FreemanChain fc = vectFcs.at(i);
183 GridCurve<> gridcurve;
184 gridcurve.initFromPointsRange( fc.begin(), fc.end() );
186 cout <<
"# grid curve " << i+1 <<
"/"
187 << gridcurve.size() <<
" "
188 << ( (gridcurve.isClosed())?
"closed":
"open" ) << endl;
191 typedef GridCurve<KSpace>::PointsRange Range;
192 Range r = gridcurve.getPointsRange();
195 cout <<
"# Curvature estimation from maximal segments" << endl;
196 std::vector<double> estimations1;
197 std::vector<double> estimations2;
198 if (gridcurve.isOpen())
200 cout <<
"# open grid curve" << endl;
201 estimationFromLength( h, r.begin(), r.end(), back_inserter(estimations1) );
202 estimationFromLengthAndWidth( h, r.begin(), r.end(), back_inserter(estimations2) );
206 cout <<
"# closed grid curve" << endl;
207 estimationFromLength( h, r.c(), r.c(), back_inserter(estimations1) );
208 estimationFromLengthAndWidth( h, r.c(), r.c(), back_inserter(estimations2) );
212 cout <<
"# id curvatureFromLength curvatureFromLengthAndWidth" << endl;
214 for ( Range::ConstIterator it = r.begin(), itEnd = r.end();
215 it != itEnd; ++it, ++j ) {
216cout << j << setprecision( 15 )
217 <<
" " << estimations1[ j ]
218 <<
" " << estimations2[ j ] << endl;