34 #include "DGtal/base/Common.h"    36 #include "DGtal/shapes/ShapeFactory.h"    37 #include "DGtal/shapes/Shapes.h"    38 #include "DGtal/helpers/StdDefs.h"    39 #include "DGtal/topology/helpers/Surfaces.h"    42 #include "DGtal/geometry/curves/FreemanChain.h"    45 #include "DGtal/geometry/curves/BinomialConvolver.h"    49 #include "DGtal/images/ImageContainerBySTLVector.h"    50 #include "DGtal/io/writers/GenericWriter.h"    51 #include "DGtal/io/colormaps/GradientColorMap.h"    52 #include "DGtal/io/writers/PPMWriter.h"    55 #include <boost/program_options/options_description.hpp>    56 #include <boost/program_options/parsers.hpp>    57 #include <boost/program_options/variables_map.hpp>    64 using namespace DGtal;
   108 computeCurvatureBCC(
double h, 
const FreemanChain<Z2i::Integer> &fc, std::vector<double> &resCurvature, 
   110   std::vector<Z2i::Point> vectPoints;
   111   FreemanChain<Z2i::Integer>::getContourPoints( fc, vectPoints ); 
   113   typedef BinomialConvolver<std::vector<Z2i::Point>::const_iterator, 
double> MyBinomialConvolver;
   114   typedef CurvatureFromBinomialConvolverFunctor< MyBinomialConvolver, double >   CurvatureBCFct;
   115   BinomialConvolverEstimator< MyBinomialConvolver, CurvatureBCFct> BCCurvatureEstimator;
   116   BCCurvatureEstimator.init( h, vectPoints.begin(), vectPoints.end(), isClosed );
   117   resCurvature.clear();
   118   resCurvature.resize(vectPoints.size());
   119   BCCurvatureEstimator.eval( vectPoints.begin(), vectPoints.end(), resCurvature.begin() ); 
   125 namespace po = boost::program_options;
   127 int main( 
int argc, 
char** argv )
   131   po::options_description general_opt(
"Allowed options are: ");
   132   general_opt.add_options()
   133     (
"help,h", 
"display this message")
   134     (
"input,i", po::value<std::string>(), 
"Input FreemanChain file name")
   135     (
"gridStepInit", po::value<double>()->default_value(1.0), 
"Grid step initial")
   136     (
"gridStepIncrement", po::value<double>()->default_value(1.0), 
"Grid step increment ")
   137     (
"output,o ", po::value<std::string>(), 
"set the output name ")
   138     (
"gridStepFinal", po::value<double>()->default_value(1.0), 
"Grid step final")
   139     (
"curvatureCutOff,c", po::value<double>()->default_value(10.0), 
"set the curvature limits to better display");
   142   typedef ImageContainerBySTLVector<Z2i::Domain, double > Image2D;
   146   po::variables_map vm;
   148     po::store(po::parse_command_line(argc, argv, general_opt), vm);  
   149   }
catch(
const std::exception& ex){
   151     trace.info()<< 
"Error checking program options: "<< ex.what()<< std::endl;
   154   if(!parseOK || vm.count(
"help")||argc<=1 || (!(vm.count(
"input"))) )
   156       trace.info()<< 
"Generate the Curvature Scale Space image using a binomial convolver based estimator." <<std::endl
   157                   << 
"The x axis is associated to the contour point and the y axis to the scale. The colors represent the curvature values included between the cutoff values (set to 10 by default)."   158                   <<std::endl << 
"Basic usage: "<<std::endl
   159       << 
"\t curvatureScaleSpaceBCC --input <filename>  --output <filename> "<<std::endl
   160                   << general_opt << 
"\n"   161                   << 
"Example: "<<std::endl
   162                   << 
"\t curvatureScaleSpaceBCC -i ${DGtal}/examples/samples/contourS.fc --gridStepInit 0.001 --gridStepIncrement  0.0005 --gridStepFinal 0.05 -o cssResu.ppm"<< std::endl;
   166   double h_initial = vm[
"gridStepInit"].as<
double>();
   167   double h_increment = vm[
"gridStepIncrement"].as<
double>();
   168   double h_final = vm[
"gridStepFinal"].as<
double>();
   169   double curvatureCutOff = vm[
"curvatureCutOff"].as<
double>();
   172   if(vm.count(
"input")){
   173     std::string fileName = vm[
"input"].as<std::string>();    
   174     std::vector< DGtal::FreemanChain<Z2i::Integer>  > vectFcs =  PointListReader< Z2i::Point >:: getFreemanChainsFromFile<Z2i::Integer> (fileName);     
   175     bool isClosed = vectFcs.at(0).isClosed(); 
   179     unsigned int height =  (int)((h_final-h_initial)/h_increment);
   181     Z2i::Domain domain (Z2i::Point(0,0), Z2i::Point(vectFcs.at(0).size()+(isClosed? 0: 1), height-1));
   182     Image2D cssImage(domain);    
   183     HueShadeColorMap<double>  gradCurvature (-curvatureCutOff, curvatureCutOff);
   185     trace.progressBar(0, height);
   187     for(
double l= 0; l < height; l++ ){
   189       trace.progressBar(l, height);
   190       std::vector<double> curvaturesBCC;
   191       computeCurvatureBCC(h, vectFcs.at(0), curvaturesBCC, isClosed);
   194       for ( std::vector<double>::const_iterator it = curvaturesBCC.begin(), it_end = curvaturesBCC.end();
   195             it != it_end; ++it, ++j ) {
   197         c = c<-curvatureCutOff? -curvatureCutOff: c;
   198         c = c>curvatureCutOff? curvatureCutOff: c;
   199         cssImage.setValue(Z2i::Point(j, l), c); 
   203     trace.progressBar(height, height);
   204     trace.info() <<std::endl;
   205     DGtal::GenericWriter<Image2D, 2, double, HueShadeColorMap<double> >::exportFile(vm[
"output"].as<std::string>(), cssImage, gradCurvature );