30#include <DGtal/base/Common.h>
31#include <DGtal/helpers/StdDefs.h>
32#include <DGtal/io/readers/VolReader.h>
36#include <DGtal/images/ImageContainerBySTLVector.h>
37#include <DGtal/images/IntervalForegroundPredicate.h>
87int main(
int argc,
char**argv)
94 int thresholdMax {255};
96 app.description(
"Computes the Euleur Characteristic of a vol to a 8-bit raw file.\n Typical use example:\n \t eulerCharacteristic <volFileName> -m <minlevel> -M <maxlevel>\n");
97 app.add_option(
"--input,-i,1", filename,
"Input vol file." )->required()->check(CLI::ExistingFile);
98 app.add_option(
"--thresholdMin,-m", thresholdMin,
"threshold min (excluded) to define binary shape (default 0)");
99 app.add_option(
"--thresholdMax,-M", thresholdMax,
"threshold max (included) to define binary shape (default 255)");
101 app.get_formatter()->column_width(40);
102 CLI11_PARSE(app, argc, argv);
106 trace.beginBlock(
"Loading the vol file");
107 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
108 MyImageC imageC = VolReader< MyImageC >::importVol ( filename );
109 trace.info()<<imageC<<std::endl;
113 trace.beginBlock(
"Construting the cubical complex");
114 KSpace::CellSet myCellSet;
116 bool space_ok = ks.init( imageC.domain().lowerBound(), imageC.domain().upperBound(),
true );
119 trace.error() <<
"Error in the Khamisky space construction."<<std::endl;
122 functors::IntervalForegroundPredicate<MyImageC> interval(imageC, thresholdMin,thresholdMax);
123 for(MyImageC::Domain::ConstIterator it =imageC.domain().begin(), itend= imageC.domain().end();
128 Domain dom( 2*(*it), 2*(*it) + Point::diagonal(2));
129 for(Domain::ConstIterator itdom = dom.begin(), itdomend = dom.end(); itdom != itdomend; ++itdom)
130 myCellSet.insert( ks.uCell( *itdom) );
133 trace.info() <<
"Got "<< myCellSet.size()<<
" cells"<<std::endl;
136 trace.beginBlock(
"Computing the characteristics");
137 std::vector<int> cells(4,0);
139 for(KSpace::CellSet::const_iterator it = myCellSet.begin(), itend = myCellSet.end(); it !=itend; ++it)
140 cells[ ks.uDim(*it) ] ++;
142 trace.info() <<
"Got "<< cells[0]<<
" pointels "<<cells[1]<<
" linels "<< cells[2]<<
" surfels and "<<cells[3]<<
" bells"<<std::endl;
145 trace.info() <<
"Volumetric Euler Characteristic = "<<cells[0] - cells[1] + cells[2] - cells[3]<<std::endl;