37 #include "DGtal/base/Common.h"
38 #include "DGtal/io/readers/VolReader.h"
40 #include "DGtal/io/Display3D.h"
41 #include "DGtal/io/viewers/Viewer3D.h"
42 #include "DGtal/io/DrawWithDisplay3DModifier.h"
43 #include "DGtal/images/ImageSelector.h"
44 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
45 #include "DGtal/topology/DigitalSurface.h"
46 #include "DGtal/topology/DigitalSetBoundary.h"
47 #include "DGtal/graph/BreadthFirstVisitor.h"
48 #include "DGtal/geometry/surfaces/COBANaivePlaneComputer.h"
49 #include "DGtal/helpers/StdDefs.h"
50 #include "ConfigExamples.h"
55 using namespace DGtal;
74 struct SegmentedPlane {
81 inline VertexSize(
const Vertex & aV,
unsigned int aSize )
82 : v( aV ), size( aSize )
87 bool operator<(
const VertexSize & vs1,
const VertexSize & vs2 )
89 return vs1.size < vs2.size;
95 int main(
int argc,
char** argv )
98 trace.
info() <<
"Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl;
101 string inputFilename = examplesPath +
"samples/Al.100.vol" ;
102 trace.
info() <<
"input file used " << inputFilename << std::endl;
104 unsigned int threshold = 0;
105 trace.
info() <<
"the value that defines the isosurface in the image (an integer between 0 and 255)= " << threshold<< std::endl;
107 unsigned int widthNum = 1;
108 trace.
info() <<
"the numerator of the rational width (a non-null integer) =" << widthNum<< std::endl;
110 unsigned int widthDen = 1;
111 trace.
info() <<
"the denominator of the rational width (a non-null integer)= " << widthDen<< std::endl;
115 QApplication application(argc,argv);
127 bool ok = ks.
init( set3d.
domain().lowerBound(),
128 set3d.
domain().upperBound(),
true );
129 if ( ! ok ) std::cerr <<
"[KSpace.init] Failed." << std::endl;
141 unsigned int nb = digSurf.
size();
144 trace.
beginBlock(
"1) Segmentation first pass. Computes all planes so as to sort vertices by the plane size." );
145 std::map<Vertex,unsigned int> v2size;
147 std::priority_queue<VertexSize> Q;
148 std::vector<Point> layer;
154 planeComputer.
init( axis, 500, widthNum, widthDen );
165 if ( node.second != currentSize )
168 bool isExtended = planeComputer.
extend( layer.begin(), layer.end() );
172 currentSize = node.second;
174 layer.push_back( p );
178 Q.push( VertexSize( v, planeComputer.
size() ) );
182 trace.
beginBlock(
"2) Segmentation second pass. Visits vertices from the one with biggest plane to the one with smallest plane." );
183 std::set<Vertex> processedVertices;
184 std::map<Vertex,SegmentedPlane*> v2plane;
185 std::vector<SegmentedPlane*> segmentedPlanes;
187 while ( ! Q.empty() )
192 if ( processedVertices.find( v ) != processedVertices.end() )
195 SegmentedPlane* ptrSegment =
new SegmentedPlane;
196 segmentedPlanes.push_back( ptrSegment );
198 ptrSegment->plane.init( axis, 500, widthNum, widthDen );
205 if ( processedVertices.find( v ) == processedVertices.end() )
209 bool isExtended = ptrSegment->plane.extend( p );
212 processedVertices.insert( v );
213 v2plane[ v ] = ptrSegment;
223 ptrSegment->color =
Color( rand() % 256, rand() % 256, rand() % 256, 255 );
231 Color col( 255, 255, 120 );
232 for ( std::map<Vertex,SegmentedPlane*>::const_iterator
233 it = v2plane.begin(), itE = v2plane.end();
237 viewer << ks.
unsigns( it->first );
239 viewer << Viewer3D<>::updateDisplay;
243 for ( std::vector<SegmentedPlane*>::iterator
244 it = segmentedPlanes.begin(), itE = segmentedPlanes.end();
247 segmentedPlanes.clear();
251 return application.exec();
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
const Node & current() const
std::pair< Vertex, Data > Node
FIXME.
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
bool extend(const Point &p)
Structure representing an RGB triple with alpha component.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of a given...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
const Domain & domain() const
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Surfel Vertex
Defines the type for a vertex.
ConstIterator begin() const
ConstIterator end() const
KSpace::SurfelSet SurfelSet
Aim: implements association bewteen points lying in a digital domain and values.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
Point sCoords(const SCell &c) const
Return its digital coordinates.
SCell sDirectIncident(const SCell &p, Dimension k) const
Return the direct incident cell of [p] along [k] (the incident cell along [k])
void beginBlock(const std::string &keyword="")
void progressBar(const double currentValue, const double maximalValue)
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
MyDigitalSurface::ConstIterator ConstIterator
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
bool operator<(const VertexSize &vs1, const VertexSize &vs2)
SurfelSet::iterator SurfelSetIterator
int main(int argc, char **argv)
[greedy-plane-segmentation-ex3-typedefs]
MyDigitalSurface::Vertex Vertex
COBANaivePlaneComputer< Z3, InternalInteger > NaivePlaneComputer
MyDigitalSurface::ConstIterator ConstIterator
MyDigitalSurface::SurfelSet SurfelSet
BreadthFirstVisitor< MyDigitalSurface > Visitor
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DGtal::int64_t InternalInteger
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
DGtal::uint32_t Dimension
Aim: Define utilities to convert a digital set into an image.
Aim: implements methods to read a "Vol" file format.
ImageContainerBySTLVector< Domain, Value > Image