29 #include <DGtal/base/Common.h>    30 #include <DGtal/helpers/StdDefs.h>    31 #include <DGtal/io/readers/VolReader.h>    32 #include <boost/program_options/options_description.hpp>    33 #include <boost/program_options/parsers.hpp>    34 #include <boost/program_options/variables_map.hpp>    35 #include <DGtal/images/ImageContainerBySTLVector.h>    36 #include <DGtal/images/IntervalForegroundPredicate.h>    39 using namespace DGtal;
    42 namespace po = boost::program_options;
    92 void missingParam ( std::string param )
    94   trace.error() <<
" Parameter: "<<param<<
" is required..";
    95   trace.info() <<std::endl;
   100 int main(
int argc, 
char**argv)
   104   po::options_description general_opt ( 
"Allowed options are: " );
   105   general_opt.add_options()
   106     ( 
"help,h", 
"display this message." )
   107     ( 
"input,i", po::value<std::string>(), 
"Input vol file." )
   108     (
"thresholdMin,m",  po::value<int>()->default_value(0), 
"threshold min (excluded) to define binary shape" )
   109     (
"thresholdMax,M",  po::value<int>()->default_value(255), 
"threshold max (included) to define binary shape" );
   111   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()<< endl;
   122   if (!parseOK || vm.count ( 
"help" ) ||argc<=1 )
   124       trace.info() << 
"Compute the Euleur Characteristic of  a vol to a 8-bit raw file. The vol file is first binarized using interval [m,M[ thresholds and the Eucler characteristic is given from the cubical complex."<<std::endl
   125                    << std::endl << 
"Basic usage: "<<std::endl
   126                    << 
"\t eulerCharacteristic --input <volFileName> -m <minlevel> -M <maxlevel> "<<std::endl
   127                    << general_opt << 
"\n";
   132   if ( ! ( vm.count ( 
"input" ) ) ) missingParam ( 
"--input" );
   133   std::string filename = vm[
"input"].as<std::string>();
   134   int thresholdMin = vm[
"thresholdMin"].as<
int>();
   135   int thresholdMax = vm[
"thresholdMax"].as<
int>();
   138   trace.beginBlock(
"Loading the vol file");
   139   typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char>  MyImageC;
   140   MyImageC  imageC = VolReader< MyImageC >::importVol ( filename );
   141   trace.info()<<imageC<<std::endl;
   145   trace.beginBlock(
"Construting the cubical complex");
   146   KSpace::CellSet myCellSet;
   148   bool space_ok = ks.init( imageC.domain().lowerBound(), imageC.domain().upperBound(), true );
   151       trace.error() << 
"Error in the Khamisky space construction."<<std::endl;
   154   functors::IntervalForegroundPredicate<MyImageC> interval(imageC, thresholdMin,thresholdMax);  
   155   for(MyImageC::Domain::ConstIterator it =imageC.domain().begin(), itend= imageC.domain().end();
   160           Domain dom( 2*(*it), 2*(*it) + Point::diagonal(2));
   161           for(Domain::ConstIterator itdom = dom.begin(), itdomend = dom.end(); itdom != itdomend; ++itdom)
   162             myCellSet.insert( ks.uCell( *itdom) );
   165   trace.info() << 
"Got "<< myCellSet.size()<< 
" cells"<<std::endl;
   168   trace.beginBlock(
"Computing the characteristics");
   169   std::vector<int> cells(4,0);
   171   for(KSpace::CellSet::const_iterator it = myCellSet.begin(), itend = myCellSet.end(); it !=itend; ++it)
   172     cells[ ks.uDim(*it) ] ++; 
   174   trace.info() << 
"Got "<< cells[0]<< 
" pointels "<<cells[1]<<
" linels  "<< cells[2]<<
" surfels and "<<cells[3]<<
"  bells"<<std::endl;
   177   trace.info() << 
"Volumetric Euler Characteristic = "<<cells[0] - cells[1] + cells[2] - cells[3]<<std::endl;