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"
104int main(
int argc,
char** argv )
108 std::string fileName;
111 app.description(
"Estimates tangent using a binomial convolver.\n Typical use example:\n \t tangentBC [options] --input <fileName>\n");
112 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);
113 app.add_option(
"--GridStep", h,
"Grid step (default 1.0)");
115 app.get_formatter()->column_width(40);
116 CLI11_PARSE(app, argc, argv);
119 if(filenameOpt->count()>0){
120 std::string extension = fileName.substr( fileName.find_last_of(
".") + 1 );
121 bool isSDP = extension ==
"sdp";
122 typedef Z2i::Space Space;
123 typedef Space::Point Point;
124 typedef PointVector<2, double> RealPoint;
125 typedef Space::Integer Integer;
126 typedef FreemanChain<Integer> FreemanChain;
127 typedef std::vector< Point > Storage;
128 typedef Storage::const_iterator ConstIteratorOnPoints;
130 std::vector< FreemanChain > vectFcs;
134 PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
136 for(
unsigned int i=0; i<vectFcs.size() || (i==0 && isSDP); i++){
141 isClosed = vectFcs.at(i).isClosed();
142 std::cout <<
"# grid curve " << i <<
"/" << vectFcs.size() <<
" "
143 << ( (isClosed)?
"closed":
"open" ) << std::endl;
144 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
148 vectPts = PointListReader<Z2i::Point>::getPointsFromFile(fileName);
149 Z2i::Point pf =vectPts[0];
150 Z2i::Point pl =vectPts[vectPts.size()-1];
151 isClosed = (pf[0]-pl[0])+(pf[1]-pl[1]) <= 1;
155 std::cout <<
"# Curvature estimation from binomial convolution" << std::endl;
156 typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
157 std::cout <<
"# mask size = " <<
158 MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
160 TangentFromBinomialConvolverFunctor< MyBinomialConvolver, RealPoint >
162 BinomialConvolverEstimator< MyBinomialConvolver, TangentBCFct>
165 BCTangentEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
167 std::vector<RealPoint> tangents( vectPts.size() );
168 BCTangentEstimator.eval( vectPts.begin(), vectPts.end(),
172 std::cout <<
"# id tangent.x tangent.y angle(atan2(y,x)) x y" << std::endl;
174 for ( ConstIteratorOnPoints
175 it = vectPts.begin(), it_end = vectPts.end();
176 it != it_end; ++it, ++j )
178 double x = tangents[ j ][ 0 ];
179 double y = tangents[ j ][ 1 ];
180 std::cout << j << std::setprecision( 15 )
181 <<
" " << x <<
" " << y
182 <<
" " << atan2( y, x ) <<
" " << (*it)[0] <<
" " << (*it)[1]