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" 44 #include "DGtal/geometry/curves/FreemanChain.h" 45 #include "DGtal/geometry/curves/GridCurve.h" 48 #include "DGtal/geometry/curves/BinomialConvolver.h" 50 using namespace DGtal;
53 namespace po = boost::program_options;
102 int main(
int argc,
char** argv )
105 po::options_description general_opt(
"Allowed options are: ");
106 general_opt.add_options()
107 (
"help,h",
"display this message")
108 (
"input,i", po::value<std::string>(),
"input FreemanChain file name")
109 (
"GridStep,step", po::value<double>()->default_value(1.0),
"Grid step");
113 po::variables_map vm;
115 po::store(po::parse_command_line(argc, argv, general_opt), vm);
116 }
catch(
const std::exception& ex){
118 trace.info()<<
"Error checking program options: "<< ex.what()<< std::endl;
122 if(!parseOK || vm.count(
"help")||argc<=1 || (!(vm.count(
"input"))) )
124 trace.info()<<
"Tangent using a binomial convolver " <<std::endl <<
"Basic usage: "<<std::endl
125 <<
"\t tangentBC [options] --input <fileName> "<<std::endl
126 << general_opt <<
"\n" 127 <<
"NB: the file may contain several freeman chains." <<
"\n";
132 double h = vm[
"GridStep"].as<
double>();
136 if(vm.count(
"input")){
137 std::string fileName = vm[
"input"].as<std::string>();
139 typedef Z2i::Space Space;
140 typedef Space::Point Point;
141 typedef PointVector<2, double> RealPoint;
142 typedef Space::Integer Integer;
143 typedef FreemanChain<Integer> FreemanChain;
144 typedef std::vector< Point > Storage;
145 typedef Storage::const_iterator ConstIteratorOnPoints;
147 std::vector< FreemanChain > vectFcs =
148 PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
150 for(
unsigned int i=0; i<vectFcs.size(); i++){
152 bool isClosed = vectFcs.at(i).isClosed();
153 std::cout <<
"# grid curve " << i <<
"/" << vectFcs.size() <<
" " 154 << ( (isClosed)?
"closed":
"open" ) << std::endl;
157 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
160 std::cout <<
"# Curvature estimation from binomial convolution" << std::endl;
161 typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
162 std::cout <<
"# mask size = " <<
163 MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
165 TangentFromBinomialConvolverFunctor< MyBinomialConvolver, RealPoint >
167 BinomialConvolverEstimator< MyBinomialConvolver, TangentBCFct>
170 BCTangentEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );
172 std::vector<RealPoint> tangents( vectPts.size() );
173 BCTangentEstimator.eval( vectPts.begin(), vectPts.end(),
177 std::cout <<
"# id tangent.x tangent.y angle(atan2(y,x))" << std::endl;
179 for ( ConstIteratorOnPoints
180 it = vectPts.begin(), it_end = vectPts.end();
181 it != it_end; ++it, ++j )
183 double x = tangents[ j ][ 0 ];
184 double y = tangents[ j ][ 1 ];
185 std::cout << j << std::setprecision( 15 )
186 <<
" " << x <<
" " << y
187 <<
" " << atan2( y, x )