32 #include "DGtal/base/Common.h"
34 #include "DGtal/kernel/SpaceND.h"
35 #include "DGtal/kernel/domains/HyperRectDomain.h"
36 #include "DGtal/topology/KhalimskySpaceND.h"
37 #include "DGtal/topology/SurfelAdjacency.h"
38 #include "DGtal/topology/SurfelNeighborhood.h"
40 #include "DGtal/shapes/Shapes.h"
41 #include "DGtal/shapes/ShapeFactory.h"
42 #include "DGtal/shapes/GaussDigitizer.h"
43 #include "DGtal/geometry/curves/GridCurve.h"
45 #include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
46 #include "DGtal/geometry/curves/GeometricalDCA.h"
51 using namespace DGtal;
53 #include <boost/program_options/options_description.hpp>
54 #include <boost/program_options/parsers.hpp>
55 #include <boost/program_options/variables_map.hpp>
57 namespace po = boost::program_options;
60 template <
typename Shape,
typename RealPo
int>
62 estimatorOnShapeDigitization(
const string& name,
64 const RealPoint& low,
const RealPoint& up,
75 dig.init( low, up, h );
79 Domain domain = dig.getDomain();
83 bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
86 std::cerr <<
"[estimatorOnShapeDigitization]"
87 <<
" error in creating KSpace." << std::endl;
95 std::vector<Point> points;
99 gridcurve.initFromVector( points );
102 typedef Range::ConstIterator ClassicIterator;
103 typedef Range::ConstCirculator CircularIterator;
104 Range r = gridcurve.getIncidentPointsRange();
106 std::vector<double> estimations;
107 if (gridcurve.isOpen())
114 CurvatureEstimator estimator(sc, sce);
115 std::cout <<
"# open grid curve" << endl;
116 estimator.init( h, r.
begin(), r.
end() );
117 estimator.eval( r.
begin(), r.
end(), std::back_inserter(estimations) );
126 CurvatureEstimator estimator(sc, sce);
127 std::cout <<
"# closed grid curve" << endl;
128 estimator.init( h, r.c(), r.c() );
129 estimator.eval( r.c(), r.c(), std::back_inserter(estimations) );
132 std::cout <<
"# idx kappa" << endl;
134 for ( ClassicIterator it = r.
begin(), ite = r.
end();
135 it != ite; ++it, ++i )
137 std::cout << i <<
" " << estimations.at(i) << std::endl;
142 std::cerr <<
"[estimatorOnShapeDigitization]"
143 <<
" error in finding a bel." << std::endl;
146 trace.
emphase() << ( ok ?
"Passed." :
"Error." ) << endl;
152 int main(
int argc,
char** argv )
157 po::options_description general_opt(
"Allowed options are");
158 general_opt.add_options()
159 (
"help,h",
"display this message")
160 (
"shape,s", po::value<string>()->default_value(
"flower"),
"Shape to digitize: flower, ellipse, ball" )
161 (
"gridStep,g", po::value<double>()->default_value(0.01),
"Grid step" );
163 po::variables_map vm;
164 po::store(po::parse_command_line(argc, argv, general_opt), vm);
166 trace.
info()<<
"curvature estimation" << std::endl
167 <<
"Basic usage: "<<std::endl
168 << argv[0] <<
" [other options] -i <vol file> -t <threshold> " << std::endl
169 << general_opt <<
"\n";
172 double h = vm[
"gridStep"].as<
double>();
174 string shapeName = vm[
"shape"].as<
string>();
180 typedef Space::RealPoint RealPoint;
181 if (shapeName ==
"flower")
184 res = estimatorOnShapeDigitization(
"flower", flower,
185 RealPoint::diagonal(-10),
186 RealPoint::diagonal(10),
189 else if (shapeName ==
"ellipse")
192 res = estimatorOnShapeDigitization(
"ellipse", ellipse,
193 RealPoint::diagonal(-10),
194 RealPoint::diagonal(10),
197 else if (shapeName ==
"ball")
200 res = estimatorOnShapeDigitization(
"ball", ball,
201 RealPoint::diagonal(-10),
202 RealPoint::diagonal(10),
207 trace.
error() <<
"Unknown shape. Use option -h" << std::endl;