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