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"
51 #include <boost/program_options/options_description.hpp>
52 #include <boost/program_options/parsers.hpp>
53 #include <boost/program_options/variables_map.hpp>
60 using namespace DGtal;
117 template<
typename I,
typename O>
118 void estimationFromLength(
double h,
const I& itb,
const I& ite,
const O& ito )
125 Estimator CurvatureEstimator(sc, f);
127 CurvatureEstimator.init( h, itb, ite );
128 CurvatureEstimator.eval( itb, ite, ito );
139 template<
typename I,
typename O>
140 void estimationFromLengthAndWidth(
double h,
const I& itb,
const I& ite,
const O& ito )
147 Estimator CurvatureEstimator(sc, f);
149 CurvatureEstimator.init( h, itb, ite );
150 CurvatureEstimator.eval( itb, ite, ito );
155 namespace po = boost::program_options;
157 int main(
int argc,
char** argv )
160 po::options_description general_opt(
"Allowed options are");
161 general_opt.add_options()
162 (
"help,h",
"display this message")
163 (
"input,i", po::value<std::string>(),
"input FreemanChain file name")
164 (
"GridStep,step", po::value<double>()->default_value(1.0),
"Grid step");
168 po::variables_map vm;
170 po::store(po::parse_command_line(argc, argv, general_opt), vm);
171 }
catch(
const std::exception& ex){
173 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
177 if(!parseOK || vm.count(
"help")||argc<=1 || (!(vm.count(
"input"))) )
179 trace.
info() <<
"Estimates curvature using length of most centered segment computers. " << std::endl;
180 trace.
info() <<
"Basic usage: " << std::endl
181 <<
"\t curvatureMCMS [options] --input <fileName> "<< std::endl
182 << general_opt <<
"\n";
187 double h = vm[
"GridStep"].as<
double>();
189 if(vm.count(
"input")){
190 string fileName = vm[
"input"].as<
string>();
193 typedef Space::Point
Point;
194 typedef Space::Integer
Integer;
200 for(
unsigned int i=0; i<vectFcs.size(); i++){
203 FreemanChain fc = vectFcs.at(i);
208 cout <<
"# grid curve " << i+1 <<
"/"
209 << gridcurve.
size() <<
" "
210 << ( (gridcurve.
isClosed())?
"closed":
"open" ) << endl;
217 cout <<
"# Curvature estimation from maximal segments" << endl;
218 std::vector<double> estimations1;
219 std::vector<double> estimations2;
222 cout <<
"# open grid curve" << endl;
223 estimationFromLength( h, r.begin(), r.end(), back_inserter(estimations1) );
224 estimationFromLengthAndWidth( h, r.begin(), r.end(), back_inserter(estimations2) );
228 cout <<
"# closed grid curve" << endl;
229 estimationFromLength( h, r.c(), r.c(), back_inserter(estimations1) );
230 estimationFromLengthAndWidth( h, r.c(), r.c(), back_inserter(estimations2) );
234 cout <<
"# id curvatureFromLength curvatureFromLengthAndWidth" << endl;
236 for ( Range::ConstIterator it = r.begin(), itEnd = r.end();
237 it != itEnd; ++it, ++j ) {
238 cout << j << setprecision( 15 )
239 <<
" " << estimations1[ j ]
240 <<
" " << estimations2[ j ] << endl;
PointsRange getPointsRange() const
SpaceND< 2, Integer > Space
ConstIterator begin() const
bool initFromPointsRange(const TIterator &itb, const TIterator &ite)
ConstIterator end() const
Storage::size_type size() const
Trace trace(traceWriterTerm)
typename Self::Point Point