DGtalTools  1.3.beta
curvatureBC.cpp
1 
31 #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 
54 using namespace DGtal;
55 
56 
57 
107 
109 int main( int argc, char** argv )
110 {
111  // parse command line CLI ----------------------------------------------
112  CLI::App app;
113  std::string fileName;
114  double h {1.0};
115 
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);
119 
120  app.get_formatter()->column_width(40);
121  CLI11_PARSE(app, argc, argv);
122  // END parse command line using CLI ----------------------------------------------
123 
124 
125  typedef Z2i::Space Space;
126  typedef Space::Point Point;
127  typedef Space::Integer Integer;
129  typedef std::vector< Point > Storage;
130  typedef Storage::const_iterator ConstIteratorOnPoints;
131 
132  std::vector< FreemanChain > vectFcs = PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
133 
134 
135  for(unsigned int i=0; i<vectFcs.size(); i++){
136 
137  bool isClosed = vectFcs.at(i).isClosed();
138  std::cout << "# grid curve " << i+1 << "/" << vectFcs.size() << " "
139  << ( (isClosed)?"closed":"open" ) << std::endl;
140 
141  Storage vectPts;
142  FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
143 
144  // Binomial
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;
150  CurvatureBCFct;
152 
153  BCCurvatureEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
154 
155  std::vector <double> curvatures( vectPts.size() );
156  BCCurvatureEstimator.eval( vectPts.begin(), vectPts.end(), curvatures.begin() );
157 
158  // Output
159  std::cout << "# id curvature" << std::endl;
160  unsigned int j = 0;
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;
165  }
166 
167  }
168 
169 
170  return 0;
171 }
172 
DGtal::int32_t Integer
void init(const double h, const ConstIterator &itb, const ConstIterator &ite, const bool isClosed=true)
SpaceND< 2, Integer > Space
int main(int argc, char **argv)
typename Self::Point Point
Quantity eval(const ConstIterator &it)
static void getContourPoints(const FreemanChain &fc, std::vector< Point > &aVContour)