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