38 #include "DGtal/base/Common.h"
39 #include "DGtal/helpers/StdDefs.h"
40 #include "DGtal/io/readers/PointListReader.h"
43 #include "DGtal/geometry/curves/FreemanChain.h"
44 #include "DGtal/geometry/curves/GridCurve.h"
47 #include "DGtal/geometry/curves/BinomialConvolver.h"
49 using namespace DGtal;
102 int main(
int argc,
char** argv )
106 std::string fileName;
109 app.description(
"Estimates tangent using a binomial convolver.\n Typical use example:\n \t tangentBC [options] --input <fileName>\n");
110 auto filenameOpt = app.add_option(
"--input,-i,1",fileName,
"input file name: FreemanChain (.fc) or a sequence of discrete points (.sdp).")->required()->check(CLI::ExistingFile);
111 app.add_option(
"--GridStep", h,
"Grid step (default 1.0)",
true);
113 app.get_formatter()->column_width(40);
114 CLI11_PARSE(app, argc, argv);
117 if(filenameOpt->count()>0){
118 std::string extension = fileName.substr( fileName.find_last_of(
".") + 1 );
119 bool isSDP = extension ==
"sdp";
120 typedef Z2i::Space Space;
121 typedef Space::Point Point;
122 typedef PointVector<2, double> RealPoint;
123 typedef Space::Integer Integer;
124 typedef FreemanChain<Integer> FreemanChain;
125 typedef std::vector< Point > Storage;
126 typedef Storage::const_iterator ConstIteratorOnPoints;
128 std::vector< FreemanChain > vectFcs;
132 PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
134 for(
unsigned int i=0; i<vectFcs.size() || (i==0 && isSDP); i++){
139 isClosed = vectFcs.at(i).isClosed();
140 std::cout <<
"# grid curve " << i <<
"/" << vectFcs.size() <<
" "
141 << ( (isClosed)?
"closed":
"open" ) << std::endl;
142 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
146 vectPts = PointListReader<Z2i::Point>::getPointsFromFile(fileName);
147 Z2i::Point pf =vectPts[0];
148 Z2i::Point pl =vectPts[vectPts.size()-1];
149 isClosed = (pf[0]-pl[0])+(pf[1]-pl[1]) <= 1;
153 std::cout <<
"# Curvature estimation from binomial convolution" << std::endl;
154 typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
155 std::cout <<
"# mask size = " <<
156 MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
158 TangentFromBinomialConvolverFunctor< MyBinomialConvolver, RealPoint >
160 BinomialConvolverEstimator< MyBinomialConvolver, TangentBCFct>
163 BCTangentEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
165 std::vector<RealPoint> tangents( vectPts.size() );
166 BCTangentEstimator.eval( vectPts.begin(), vectPts.end(),
170 std::cout <<
"# id tangent.x tangent.y angle(atan2(y,x)) x y" << std::endl;
172 for ( ConstIteratorOnPoints
173 it = vectPts.begin(), it_end = vectPts.end();
174 it != it_end; ++it, ++j )
176 double x = tangents[ j ][ 0 ];
177 double y = tangents[ j ][ 1 ];
178 std::cout << j << std::setprecision( 15 )
179 <<
" " << x <<
" " << y
180 <<
" " << atan2( y, x ) <<
" " << (*it)[0] <<
" " << (*it)[1]