DGtalTools  1.3.beta
eulerCharacteristic.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/helpers/StdDefs.h>
31 #include <DGtal/io/readers/VolReader.h>
32 
33 #include "CLI11.hpp"
34 
35 #include <DGtal/images/ImageContainerBySTLVector.h>
36 #include <DGtal/images/IntervalForegroundPredicate.h>
37 
38 using namespace std;
39 using namespace DGtal;
40 using namespace Z3i;
41 
84 int main(int argc, char**argv)
85 {
86 
87  // parse command line CLI ----------------------------------------------
88  CLI::App app;
89  std::string filename;
90  int thresholdMin {0};
91  int thresholdMax {255};
92 
93  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");
94  app.add_option("--input,-i,1", filename, "Input vol file." )->required()->check(CLI::ExistingFile);
95  app.add_option("--thresholdMin,-m", thresholdMin, "threshold min (excluded) to define binary shape (default 0)", true);
96  app.add_option("--thresholdMax,-M", thresholdMax, "threshold max (included) to define binary shape (default 255)", true);
97 
98  app.get_formatter()->column_width(40);
99  CLI11_PARSE(app, argc, argv);
100  // END parse command line using CLI ----------------------------------------------
101 
102  //Importing the Vol
103  trace.beginBlock("Loading the vol file");
105  MyImageC imageC = VolReader< MyImageC >::importVol ( filename );
106  trace.info()<<imageC<<std::endl;
107  trace.endBlock();
108 
109  //Constructing the cubical complex
110  trace.beginBlock("Construting the cubical complex");
111  KSpace::CellSet myCellSet;
112  KSpace ks;
113  bool space_ok = ks.init( imageC.domain().lowerBound(), imageC.domain().upperBound(), true );
114  if (!space_ok)
115  {
116  trace.error() << "Error in the Khamisky space construction."<<std::endl;
117  return 2;
118  }
119  functors::IntervalForegroundPredicate<MyImageC> interval(imageC, thresholdMin,thresholdMax);
120  for(MyImageC::Domain::ConstIterator it =imageC.domain().begin(), itend= imageC.domain().end();
121  it != itend; ++it)
122  {
123  if (interval( *it ))
124  {
125  Domain dom( 2*(*it), 2*(*it) + Point::diagonal(2));
126  for(Domain::ConstIterator itdom = dom.begin(), itdomend = dom.end(); itdom != itdomend; ++itdom)
127  myCellSet.insert( ks.uCell( *itdom) );
128  }
129  }
130  trace.info() << "Got "<< myCellSet.size()<< " cells"<<std::endl;
131  trace.endBlock();
132 
133  trace.beginBlock("Computing the characteristics");
134  std::vector<int> cells(4,0);
135 
136  for(KSpace::CellSet::const_iterator it = myCellSet.begin(), itend = myCellSet.end(); it !=itend; ++it)
137  cells[ ks.uDim(*it) ] ++;
138 
139  trace.info() << "Got "<< cells[0]<< " pointels "<<cells[1]<<" linels "<< cells[2]<<" surfels and "<<cells[3]<<" bells"<<std::endl;
140  trace.endBlock();
141 
142  trace.info() << "Volumetric Euler Characteristic = "<<cells[0] - cells[1] + cells[2] - cells[3]<<std::endl;
143 
144  return 0;
145 }
void beginBlock(const std::string &keyword="")
STL namespace.
double endBlock()
Dimension uDim(const Cell &p) const
int main(int argc, char **argv)
Cell uCell(const PreCell &c) const
bool init(const Point &lower, const Point &upper, bool isClosed)
std::set< Cell > CellSet
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()
typename Self::Domain Domain