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";
121 typedef Space::Point
Point;
123 typedef Space::Integer
Integer;
125 typedef std::vector< Point > Storage;
126 typedef Storage::const_iterator ConstIteratorOnPoints;
128 std::vector< FreemanChain > vectFcs;
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;
149 isClosed = (pf[0]-pl[0])+(pf[1]-pl[1]) <= 1;
153 std::cout <<
"# Curvature estimation from binomial convolution" << std::endl;
155 std::cout <<
"# mask size = " <<
156 MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
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]
int main(int argc, char **argv)
void init(const double h, const ConstIterator &itb, const ConstIterator &ite, const bool isClosed=true)
Quantity eval(const ConstIterator &it)
static void getContourPoints(const FreemanChain &fc, std::vector< Point > &aVContour)
typename Self::Point Point
SpaceND< 2, Integer > Space
static std::vector< TPoint > getPointsFromFile(const std::string &filename, std::vector< unsigned int > aVectPosition=std::vector< unsigned int >())