DGtal 1.4.0
Loading...
Searching...
No Matches
greedy-plane-segmentation.cpp File Reference
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/Display3D.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/DigitalSetBoundary.h"
#include "DGtal/graph/BreadthFirstVisitor.h"
#include "DGtal/geometry/surfaces/COBANaivePlaneComputer.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
Include dependency graph for greedy-plane-segmentation.cpp:

Go to the source code of this file.

Typedefs

typedef DGtal::int64_t InternalInteger
 
typedef COBANaivePlaneComputer< Z3, InternalIntegerNaivePlaneComputer
 
typedef DigitalSetBoundary< KSpace, DigitalSetMyDigitalSurfaceContainer
 
typedef DigitalSurface< MyDigitalSurfaceContainerMyDigitalSurface
 
typedef MyDigitalSurface::ConstIterator ConstIterator
 
typedef MyDigitalSurface::Vertex Vertex
 
typedef MyDigitalSurface::SurfelSet SurfelSet
 
typedef SurfelSet::iterator SurfelSetIterator
 
typedef BreadthFirstVisitor< MyDigitalSurfaceVisitor
 

Functions

int main (int argc, char **argv)
 [greedy-plane-segmentation-typedefs]
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/10/01

An example file named greedy-plane-segmentation.

This file is part of the DGtal library.

Definition in file greedy-plane-segmentation.cpp.

Typedef Documentation

◆ ConstIterator

◆ InternalInteger

Definition at line 78 of file greedy-plane-segmentation.cpp.

◆ MyDigitalSurface

◆ MyDigitalSurfaceContainer

◆ NaivePlaneComputer

◆ SurfelSet

◆ SurfelSetIterator

typedef SurfelSet::iterator SurfelSetIterator

Definition at line 87 of file greedy-plane-segmentation.cpp.

◆ Vertex

Definition at line 85 of file greedy-plane-segmentation.cpp.

◆ Visitor

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

[greedy-plane-segmentation-typedefs]

[greedy-plane-segmentation-parseCommandLine]

[greedy-plane-segmentation-parseCommandLine]

[greedy-plane-segmentation-loadVolume]

[greedy-plane-segmentation-loadVolume]

[greedy-plane-segmentation-makeSurface]

[greedy-plane-segmentation-makeSurface]

[greedy-plane-segmentation-segment]

[greedy-plane-segmentation-segment]

[greedy-plane-segmentation-visualization]

[greedy-plane-segmentation-visualization]

[greedy-plane-segmentation-freeMemory]

[greedy-plane-segmentation-freeMemory]

Definition at line 101 of file greedy-plane-segmentation.cpp.

102{
103
105 trace.info() << "Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl;
106 // Setting default options: ----------------------------------------------
107 // input file used:
108 string inputFilename = examplesPath + "samples/Al.100.vol" ;
109 trace.info() << "input file used " << inputFilename << std::endl;
110 // parameter threshold
111 unsigned int threshold = 0;
112 trace.info() << "the value that defines the isosurface in the image (an integer between 0 and 255)= " << threshold<< std::endl;
113 // parameter widthNum
114 unsigned int widthNum = 1;
115 trace.info() << "the numerator of the rational width (a non-null integer) =" << widthNum<< std::endl;
116 // parameter widthDen
117 unsigned int widthDen = 1;
118 trace.info() << "the denominator of the rational width (a non-null integer)= " << widthDen<< std::endl;
119
121
123 QApplication application(argc,argv);
125 Image image = VolReader<Image>::importVol(inputFilename);
126 DigitalSet set3d (image.domain());
127 SetFromImage<DigitalSet>::append<Image>(set3d, image, threshold,255);
129
131 trace.beginBlock( "Set up digital surface." );
132 // We initializes the cellular grid space used for defining the
133 // digital surface.
134 KSpace ks;
135 bool ok = ks.init( set3d.domain().lowerBound(),
136 set3d.domain().upperBound(), true );
137 if ( ! ok ) std::cerr << "[KSpace.init] Failed." << std::endl;
138 SurfelAdjacency<KSpace::dimension> surfAdj( true ); // interior in all directions.
139 MyDigitalSurfaceContainer* ptrSurfContainer =
140 new MyDigitalSurfaceContainer( ks, set3d, surfAdj );
141 MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
142 trace.endBlock();
144
146 trace.beginBlock( "Segment into planes." );
147 std::set<Vertex> processedVertices;
148 std::vector<SegmentedPlane*> segmentedPlanes;
149 std::map<Vertex,SegmentedPlane*> v2plane;
150 Point p;
151 Dimension axis;
152 unsigned int j = 0;
153 unsigned int nb = digSurf.size();
154 for ( ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
155 {
156 if ( ( (++j) % 50 == 0 ) || ( j == nb ) ) trace.progressBar( j, nb );
157 Vertex v = *it;
158 if ( processedVertices.find( v ) != processedVertices.end() ) // already in set
159 continue; // process to next vertex
160
161 SegmentedPlane* ptrSegment = new SegmentedPlane;
162 segmentedPlanes.push_back( ptrSegment ); // to delete them afterwards.
163 axis = ks.sOrthDir( v );
164 ptrSegment->plane.init( axis, 500, widthNum, widthDen );
165 // The visitor takes care of all the breadth-first traversal.
166 Visitor visitor( digSurf, v );
167 while ( ! visitor.finished() )
168 {
169 Visitor::Node node = visitor.current();
170 v = node.first;
171 if ( processedVertices.find( v ) == processedVertices.end() )
172 { // Vertex is not in processedVertices
173 axis = ks.sOrthDir( v );
174 p = ks.sCoords( ks.sDirectIncident( v, axis ) );
175 bool isExtended = ptrSegment->plane.extend( p );
176 if ( isExtended )
177 { // surfel is in plane.
178 processedVertices.insert( v );
179 v2plane[ v ] = ptrSegment;
180 visitor.expand();
181 }
182 else // surfel is not in plane and should not be used in the visit.
183 visitor.ignore();
184 }
185 else // surfel is already in some plane.
186 visitor.ignore();
187 }
188 // Assign random color for each plane.
189 ptrSegment->color = Color( rand() % 256, rand() % 256, rand() % 256, 255 );
190 }
191 trace.endBlock();
193
195 Viewer3D<> viewer( ks );
196 viewer.show();
197 for ( std::map<Vertex,SegmentedPlane*>::const_iterator
198 it = v2plane.begin(), itE = v2plane.end();
199 it != itE; ++it )
200 {
201 viewer << CustomColors3D( it->second->color, it->second->color );
202 viewer << ks.unsigns( it->first );
203 }
204 viewer << Viewer3D<>::updateDisplay;
206
208 for ( std::vector<SegmentedPlane*>::iterator
209 it = segmentedPlanes.begin(), itE = segmentedPlanes.end();
210 it != itE; ++it )
211 delete *it;
212 segmentedPlanes.clear();
213 v2plane.clear();
215
216 return application.exec();
217}
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
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.
Definition Color.h:68
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...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
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])
static Dimension size()
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
std::ostream & info()
void progressBar(const double currentValue, const double maximalValue)
double endBlock()
MyDigitalSurface::ConstIterator ConstIterator
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DGtal::uint32_t Dimension
Definition Common.h:136
Trace trace
Definition Common.h:153
ImageContainerBySTLVector< Domain, Value > Type
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
ImageContainerBySTLVector< Domain, Value > Image
TriMesh::Vertex Vertex

References DGtal::SetFromImage< TSet >::append(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::current(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::end(), DGtal::Trace::endBlock(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extend(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::finished(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::ignore(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Trace::info(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::Trace::progressBar(), DGtal::KhalimskySpaceND< dim, TInteger >::sCoords(), DGtal::KhalimskySpaceND< dim, TInteger >::sDirectIncident(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), DGtal::KhalimskySpaceND< dim, TInteger >::sOrthDir(), DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::unsigns().