36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/parsers.hpp>
38 #include <boost/program_options/variables_map.hpp>
40 #include <QtGui/qapplication.h>
41 #include "DGtal/base/Common.h"
42 #include "DGtal/io/readers/VolReader.h"
43 #include "DGtal/io/viewers/Viewer3D.h"
44 #include "DGtal/io/Display3D.h"
46 #include "DGtal/io/DrawWithDisplay3DModifier.h"
47 #include "DGtal/images/ImageSelector.h"
48 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
49 #include "DGtal/topology/DigitalSurface.h"
50 #include "DGtal/topology/DigitalSetBoundary.h"
51 #include "DGtal/topology/BreadthFirstVisitor.h"
52 #include "DGtal/geometry/surfaces/COBANaivePlane.h"
53 #include "DGtal/helpers/StdDefs.h"
54 #include "ConfigExamples.h"
59 using namespace DGtal;
60 namespace po = boost::program_options;
73 typedef SurfelSet::iterator SurfelSetIterator;
86 inline VertexSize(
const Vertex & aV,
unsigned int aSize )
87 : v( aV ), size( aSize )
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-file,i", po::value<std::string>()->default_value( examplesPath +
"samples/Al.100.vol" ),
"the volume file (.vol)" )
108 (
"threshold,t", po::value<unsigned int>()->default_value(1),
"the value that defines the isosurface in the image (an integer between 0 and 255)." )
109 (
"width-num,w", po::value<unsigned int>()->default_value(1),
"the numerator of the rational width (a non-null integer)." )
110 (
"width-den,d", po::value<unsigned int>()->default_value(1),
"the denominator of the rational width (a non-null integer)." );
113 po::variables_map vm;
115 po::store(po::parse_command_line(argc, argv, general_opt), vm);
116 }
catch (
const std::exception & ex ) {
118 trace.
info() <<
"Error checking program options: "<< ex.what()<< endl;
121 if ( ! parseOK || vm.count(
"help") || ( argc <= 1 ) )
123 std::cout <<
"Usage: " << argv[0]
124 <<
" [-i <fileName.vol>] [-t <threshold>] [-w <num>] [-d <den>]" << std::endl
125 <<
"Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl
126 << general_opt << std::endl;
129 string inputFilename = vm[
"input-file"].as<std::string>();
130 unsigned int threshold = vm[
"threshold"].as<
unsigned int>();
131 unsigned int widthNum = vm[
"width-num"].as<
unsigned int>();
132 unsigned int widthDen = vm[
"width-den"].as<
unsigned int>();
136 QApplication application(argc,argv);
148 bool ok = ks.
init( set3d.domain().lowerBound(),
149 set3d.domain().upperBound(), true );
150 if ( ! ok ) std::cerr <<
"[KSpace.init] Failed." << std::endl;
162 unsigned int nb = digSurf.
size();
165 trace.
beginBlock(
"1) Segmentation first pass. Computes all planes so as to sort vertices by the plane size." );
166 std::map<Vertex,unsigned int> v2size;
168 std::priority_queue<VertexSize> Q;
169 for ( ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
174 planeComputer.
init( axis, 500, widthNum, widthDen );
177 while ( ! visitor.finished() )
183 bool isExtended = planeComputer.
extend( p );
194 trace.
beginBlock(
"2) Segmentation second pass. Visits vertices from the one with biggest plane to the one with smallest plane." );
195 std::set<Vertex> processedVertices;
196 std::vector<SegmentedPlane*> segmentedPlanes;
197 std::map<Vertex,SegmentedPlane*> v2plane;
199 while ( ! Q.empty() )
202 Vertex v = Q.top().v;
204 if ( processedVertices.find( v ) != processedVertices.end() )
208 segmentedPlanes.push_back( ptrSegment );
210 ptrSegment->
plane.
init( axis, 500, widthNum, widthDen );
213 while ( ! visitor.finished() )
217 if ( processedVertices.find( v ) == processedVertices.end() )
224 processedVertices.insert( v );
225 v2plane[ v ] = ptrSegment;
235 ptrSegment->
color =
Color( random() % 256, random() % 256, random() % 256, 255 );
243 for ( std::map<Vertex,SegmentedPlane*>::const_iterator
244 it = v2plane.begin(), itE = v2plane.end();
248 viewer << ks.
unsigns( it->first );
250 viewer << Display3D::updateDisplay;
254 for ( std::vector<SegmentedPlane*>::iterator
255 it = segmentedPlanes.begin(), itE = segmentedPlanes.end();
258 segmentedPlanes.clear();
262 return application.exec();