37#include "DGtal/base/Common.h"
38#include "DGtal/io/readers/VolReader.h"
40#include "DGtal/io/viewers/PolyscopeViewer.h"
41#include "DGtal/images/ImageSelector.h"
42#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
43#include "DGtal/topology/DigitalSurface.h"
44#include "DGtal/topology/DigitalSetBoundary.h"
45#include "DGtal/graph/BreadthFirstVisitor.h"
46#include "DGtal/geometry/surfaces/COBANaivePlaneComputer.h"
47#include "DGtal/helpers/StdDefs.h"
48#include "ConfigExamples.h"
80 :
v( aV ),
size( aSize )
96 trace.
info() <<
"Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl;
99 string inputFilename = examplesPath +
"samples/Al.100.vol" ;
100 trace.
info() <<
"input file used " << inputFilename << std::endl;
102 unsigned int threshold = 0;
103 trace.
info() <<
"the value that defines the isosurface in the image (an integer between 0 and 255)= " << threshold<< std::endl;
105 unsigned int widthNum = 1;
106 trace.
info() <<
"the numerator of the rational width (a non-null integer) =" << widthNum<< std::endl;
108 unsigned int widthDen = 1;
109 trace.
info() <<
"the denominator of the rational width (a non-null integer)= " << widthDen<< std::endl;
124 bool ok = ks.
init( set3d.
domain().lowerBound(),
125 set3d.
domain().upperBound(),
true );
126 if ( ! ok ) std::cerr <<
"[KSpace.init] Failed." << std::endl;
138 unsigned int nb = digSurf.
size();
141 trace.
beginBlock(
"1) Segmentation first pass. Computes all planes so as to sort vertices by the plane size." );
142 std::map<Vertex,unsigned int> v2size;
144 std::priority_queue<VertexSize> Q;
145 std::vector<Point> layer;
151 planeComputer.
init( axis, 500, widthNum, widthDen );
155 Visitor::Size currentSize = visitor.current().second;
156 while ( ! visitor.finished() )
158 Visitor::Node node = visitor.current();
162 if ( node.second != currentSize )
165 bool isExtended = planeComputer.
extend( layer.begin(), layer.end() );
169 currentSize = node.second;
171 layer.push_back( p );
179 trace.
beginBlock(
"2) Segmentation second pass. Visits vertices from the one with biggest plane to the one with smallest plane." );
180 std::set<Vertex> processedVertices;
181 std::map<Vertex,SegmentedPlane*> v2plane;
182 std::vector<SegmentedPlane*> segmentedPlanes;
184 while ( ! Q.empty() )
189 if ( processedVertices.find( v ) != processedVertices.end() )
193 segmentedPlanes.push_back( ptrSegment );
195 ptrSegment->
plane.
init( axis, 500, widthNum, widthDen );
198 while ( ! visitor.finished() )
200 Visitor::Node node = visitor.current();
202 if ( processedVertices.find( v ) == processedVertices.end() )
209 processedVertices.insert( v );
210 v2plane[ v ] = ptrSegment;
220 ptrSegment->
color =
Color( rand() % 256, rand() % 256, rand() % 256, 255 );
227 Color col( 255, 255, 120 );
228 for ( std::map<Vertex,SegmentedPlane*>::const_iterator
229 it = v2plane.begin(), itE = v2plane.end();
232 viewer << it->second->color;
233 viewer << ks.
unsigns( it->first );
238 for ( std::vector<SegmentedPlane*>::iterator
239 it = segmentedPlanes.begin(), itE = segmentedPlanes.end();
242 segmentedPlanes.clear();
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Aim: A class that contains the COBA algorithm (Emilie Charrier, Lilian Buzer, DGCI2008) for recognizi...
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.
const Domain & domain() const
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 show() override
Starts the event loop and display of elements.
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
void progressBar(const double currentValue, const double maximalValue)
MyDigitalSurface::ConstIterator ConstIterator
BreadthFirstVisitor< MyDigitalSurface > Visitor
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
SurfelSet::iterator SurfelSetIterator
MyDigitalSurface::Vertex Vertex
COBANaivePlaneComputer< Z3, InternalInteger > NaivePlaneComputer
MyDigitalSurface::ConstIterator ConstIterator
MyDigitalSurface::SurfelSet SurfelSet
BreadthFirstVisitor< MyDigitalSurface > Visitor
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
int main()
[greedy-plane-segmentation-ex3-typedefs]
DGtal::int64_t InternalInteger
DGtal is the top-level namespace which contains all DGtal functions and types.
std::int64_t int64_t
signed 94-bit integer.
bool operator<(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (LesserThan).
DGtal::uint32_t Dimension
ImageContainerBySTLVector< Domain, Value > Type
Aim: Define utilities to convert a digital set into an image.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
VertexSize(const Vertex &aV, unsigned int aSize)