DGtalTools  0.9.4
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 
49 #include <boost/program_options/options_description.hpp>
50 #include <boost/program_options/parsers.hpp>
51 #include <boost/program_options/variables_map.hpp>
52 
53 #include <vector>
54 #include <string>
55 #include <iomanip>
56 
57 using namespace DGtal;
58 
59 
60 
105 namespace po = boost::program_options;
107 
108 int main( int argc, char** argv )
109 {
110  // parse command line ----------------------------------------------
111  po::options_description general_opt("Allowed options are: ");
112  general_opt.add_options()
113  ("help,h", "display this message")
114  ("input,i", po::value<std::string>(), "input FreemanChain file name")
115  ("GridStep,step", po::value<double>()->default_value(1.0), "Grid step");
116 
117 
118  bool parseOK=true;
119  po::variables_map vm;
120  try{
121  po::store(po::parse_command_line(argc, argv, general_opt), vm);
122  }catch(const std::exception& ex){
123  parseOK=false;
124  trace.info()<< "Error checking program options: "<< ex.what()<< std::endl;
125  }
126  po::notify(vm);
127  if(!parseOK || vm.count("help")||argc<=1 || (!(vm.count("input"))) )
128  {
129  trace.info()<< "Curvature using a binomial convolver " <<std::endl << "Basic usage: "<<std::endl
130  << "\t curvatureBC [options] --input <fileName> "<<std::endl
131  << general_opt << "\n";
132  return 0;
133  }
134 
135 
136  double h = vm["GridStep"].as<double>();
137 
138 
139 
140  if(vm.count("input")){
141  std::string fileName = vm["input"].as<std::string>();
142 
143  typedef Z2i::Space Space;
144  typedef Space::Point Point;
145  typedef Space::Integer Integer;
147  typedef std::vector< Point > Storage;
148  typedef Storage::const_iterator ConstIteratorOnPoints;
149 
150  std::vector< FreemanChain > vectFcs = PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
151 
152 
153  for(unsigned int i=0; i<vectFcs.size(); i++){
154 
155  bool isClosed = vectFcs.at(i).isClosed();
156  std::cout << "# grid curve " << i+1 << "/" << vectFcs.size() << " "
157  << ( (isClosed)?"closed":"open" ) << std::endl;
158 
159  Storage vectPts;
160  FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
161 
162  // Binomial
163  std::cout << "# Curvature estimation from binomial convolution" << std::endl;
164  typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
165  std::cout << "# mask size = " <<
166  MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
168  CurvatureBCFct;
170 
171  BCCurvatureEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
172 
173  std::vector <double> curvatures( vectPts.size() );
174  BCCurvatureEstimator.eval( vectPts.begin(), vectPts.end(), curvatures.begin() );
175 
176  // Output
177  std::cout << "# id curvature" << std::endl;
178  unsigned int j = 0;
179  for ( ConstIteratorOnPoints it = vectPts.begin(), it_end = vectPts.end();
180  it != it_end; ++it, ++j ) {
181  std::cout << j << std::setprecision( 15 )
182  << " " << curvatures[ j ] << std::endl;
183  }
184 
185  }
186 
187  }
188 
189  return 0;
190 }
191 
DGtal::int32_t Integer
void init(const double h, const ConstIterator &itb, const ConstIterator &ite, const bool isClosed=true)
SpaceND< 2, Integer > Space
Trace trace(traceWriterTerm)
std::ostream & info()
typename Self::Point Point
Quantity eval(const ConstIterator &it)
static void getContourPoints(const FreemanChain &fc, std::vector< Point > &aVContour)