35 #include <boost/program_options/options_description.hpp>
36 #include <boost/program_options/parsers.hpp>
37 #include <boost/program_options/variables_map.hpp>
40 #include "DGtal/base/Common.h"
41 #include "DGtal/helpers/StdDefs.h"
42 #include "DGtal/io/readers/PointListReader.h"
45 #include "DGtal/geometry/curves/FreemanChain.h"
46 #include "DGtal/geometry/curves/GridCurve.h"
49 #include "DGtal/geometry/curves/BinomialConvolver.h"
51 using namespace DGtal;
54 namespace po = boost::program_options;
103 int main(
int argc,
char** argv )
106 po::options_description general_opt(
"Allowed options are: ");
107 general_opt.add_options()
108 (
"help,h",
"display this message")
109 (
"input,i", po::value<std::string>(),
"input file name: FreemanChain (.fc) or a sequence of discrete points (.sdp).")
110 (
"GridStep,step", po::value<double>()->default_value(1.0),
"Grid step");
114 po::variables_map vm;
116 po::store(po::parse_command_line(argc, argv, general_opt), vm);
117 }
catch(
const std::exception& ex){
119 trace.
info()<<
"Error checking program options: "<< ex.what()<< std::endl;
123 if(!parseOK || vm.count(
"help")||argc<=1 || (!(vm.count(
"input"))) )
125 trace.
info()<<
"Tangent using a binomial convolver " <<std::endl <<
"Basic usage: "<<std::endl
126 <<
"\t tangentBC [options] --input <fileName> "<<std::endl
127 << general_opt <<
"\n"
128 <<
"NB: the file may contain several freeman chains." <<
"\n";
133 double h = vm[
"GridStep"].as<
double>();
137 if(vm.count(
"input")){
138 std::string fileName = vm[
"input"].as<std::string>();
139 std::string extension = fileName.substr( fileName.find_last_of(
".") + 1 );
140 bool isSDP = extension ==
"sdp";
142 typedef Space::Point
Point;
144 typedef Space::Integer
Integer;
146 typedef std::vector< Point > Storage;
147 typedef Storage::const_iterator ConstIteratorOnPoints;
149 std::vector< FreemanChain > vectFcs;
155 for(
unsigned int i=0; i<vectFcs.size() || (i==0 && isSDP); i++){
160 isClosed = vectFcs.at(i).isClosed();
161 std::cout <<
"# grid curve " << i <<
"/" << vectFcs.size() <<
" "
162 << ( (isClosed)?
"closed":
"open" ) << std::endl;
170 isClosed = (pf[0]-pl[0])+(pf[1]-pl[1]) <= 1;
174 std::cout <<
"# Curvature estimation from binomial convolution" << std::endl;
176 std::cout <<
"# mask size = " <<
177 MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
184 BCTangentEstimator.
init( h, vectPts.begin(), vectPts.end(), isClosed );
186 std::vector<RealPoint> tangents( vectPts.size() );
187 BCTangentEstimator.
eval( vectPts.begin(), vectPts.end(),
191 std::cout <<
"# id tangent.x tangent.y angle(atan2(y,x)) x y" << std::endl;
193 for ( ConstIteratorOnPoints
194 it = vectPts.begin(), it_end = vectPts.end();
195 it != it_end; ++it, ++j )
197 double x = tangents[ j ][ 0 ];
198 double y = tangents[ j ][ 1 ];
199 std::cout << j << std::setprecision( 15 )
200 <<
" " << x <<
" " << y
201 <<
" " << atan2( y, x ) <<
" " << (*it)[0] <<
" " << (*it)[1]
void init(const double h, const ConstIterator &itb, const ConstIterator &ite, const bool isClosed=true)
SpaceND< 2, Integer > Space
static std::vector< TPoint > getPointsFromFile(const std::string &filename, std::vector< unsigned int > aVectPosition=std::vector< unsigned int >())
Trace trace(traceWriterTerm)
typename Self::Point Point
Quantity eval(const ConstIterator &it)
static void getContourPoints(const FreemanChain &fc, std::vector< Point > &aVContour)