33 #include <boost/program_options/options_description.hpp>
34 #include <boost/program_options/parsers.hpp>
35 #include <boost/program_options/variables_map.hpp>
36 #include <DGtal/kernel/sets/SetPredicate.h>
37 #include <DGtal/io/readers/VolReader.h>
38 #include <DGtal/images/ImageSelector.h>
39 #include <DGtal/images/SimpleThresholdForegroundPredicate.h>
40 #include <DGtal/images/ImageLinearCellEmbedder.h>
41 #include <DGtal/shapes/Shapes.h>
42 #include <DGtal/kernel/CanonicEmbedder.h>
43 #include <DGtal/helpers/StdDefs.h>
44 #include <DGtal/topology/helpers/Surfaces.h>
45 #include <DGtal/topology/DigitalSurface.h>
46 #include <DGtal/topology/SetOfSurfels.h>
47 #include <DGtal/geometry/volumes/KanungoNoise.h>
55 using namespace DGtal;
116 int main(
int argc,
char** argv )
122 std::string inputFileName;
123 std::string outputFileName {
"marching-cubes.off"};
125 double threshold {1.0};
126 unsigned int intAdjacency = 0;
128 app.description(
"Outputs the isosurface of value <threshold> of the volume <fileName.vol> as an OFF file <output.off>. The <adjacency> (0/1) allows to choose between interior (6,18) and exterior (18,6) adjacency.");
129 app.add_option(
"-i,--input,1", inputFileName,
"the volume file (.vol)." )
131 ->check(CLI::ExistingFile);
132 app.add_option(
"--threshold,-t",threshold,
"the value that defines the isosurface in the image (an integer between 0 and 255).",
true);
133 app.add_option(
"--adjacency,-a",intAdjacency,
"0: interior adjacency, 1: exterior adjacency",
true);
134 app.add_option(
"-o,--output,2", outputFileName,
"the output OFF file that represents the geometry of the isosurface",
true );
135 auto noiseOpt = app.add_option(
"--noise,-n", noise,
"Kanungo noise level in ]0,1[. Note that only the largest connected component is considered and that no specific embedder is used.");
137 app.get_formatter()->column_width(40);
138 CLI11_PARSE(app, argc, argv);
144 if (noiseOpt->count() > 0 )
156 ThresholdedImage thresholdedImage( image, threshold );
162 trace.
beginBlock(
"Construct the Khalimsky space from the image domain." );
168 trace.
error() <<
"Error in the Khamisky space construction."<<std::endl;
176 MySurfelAdjacency surfAdj( intAdjacency );
188 trace.
info()<<
"Adding some noise."<<std::endl;
190 std::vector< std::vector<SCell > > vectConnectedSCell;
191 trace.
info()<<
"Extracting all connected components."<<std::endl;
194 if( vectConnectedSCell.size() == 0 )
196 trace.
error()<<
"No surface component exists. Please check the vol file --min and --max parameters." << std::endl;
200 trace.
info()<<vectConnectedSCell.size()<<
" components."<<std::endl;
202 trace.
info()<<
"Extracting the largest one."<<std::endl;
203 int cc_max_size_idx = -1;
204 auto it_max = std::max_element( vectConnectedSCell.begin(), vectConnectedSCell.end(),
205 [] (std::vector<SCell >& v1, std::vector<SCell >& v2)
206 { return v1.size() < v2.size(); } );
207 cc_max_size_idx = std::distance( vectConnectedSCell.begin(), it_max );
208 theSetOfSurfels.surfelSet().insert( vectConnectedSCell[ cc_max_size_idx ].begin(),
209 vectConnectedSCell[ cc_max_size_idx ].end() );
213 theSetOfSurfels.surfelSet(), ks, thresholdedImage,
216 MyDigitalSurface digSurf( theSetOfSurfels );
217 trace.
info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
230 MyEmbedder trivialEmbedder;
238 for(
auto p: image.
domain())
239 largerImage.setValue( p, image(p));
241 std::ofstream out( outputFileName.c_str() );
245 digSurf.exportSurfaceAs3DOFF( out );
248 trace.
error()<<
"IO error while opening the output file"<<std::endl;
254 cellEmbedder.init( ks, image, trivialEmbedder,
255 ( (
double) threshold ) + 0.5 );
258 digSurf.exportEmbeddedSurfaceAs3DOFF( out, cellEmbedder );
261 trace.
error()<<
"IO error while opening the output file"<<std::endl;
int main(int argc, char **argv)
const Point & upperBound() const
const Point & lowerBound() const
const Domain & domain() const
std::set< SCell > SurfelSet
bool init(const Point &lower, const Point &upper, bool isClosed)
static Self diagonal(Component val=1)
static void extractAllConnectedSCell(std::vector< std::vector< SCell > > &aVectConnectedSCell, const KSpace &aKSpace, const SurfelAdjacency< KSpace::dimension > &aSurfelAdj, const PointPredicate &pp, bool forceOrientCellExterior=false)
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
Trace trace(traceWriterTerm)
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())