Loading [MathJax]/extensions/MathMenu.js
DGtal 2.0.0
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/viewers/PolyscopeViewer.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.

Data Structures

struct  SegmentedPlane

Typedefs

typedef COBANaivePlaneComputer< Z3, InternalIntegerNaivePlaneComputer
typedef DigitalSetBoundary< KSpace, DigitalSetMyDigitalSurfaceContainer
typedef DigitalSurface< MyDigitalSurfaceContainerMyDigitalSurface
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

◆ MyDigitalSurface

◆ MyDigitalSurfaceContainer

◆ NaivePlaneComputer

◆ 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 99 of file greedy-plane-segmentation.cpp.

100{
101
103 trace.info() << "Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl;
104 // Setting default options: ----------------------------------------------
105 // input file used:
106 string inputFilename = examplesPath + "samples/Al.100.vol" ;
107 trace.info() << "input file used " << inputFilename << std::endl;
108 // parameter threshold
109 unsigned int threshold = 0;
110 trace.info() << "the value that defines the isosurface in the image (an integer between 0 and 255)= " << threshold<< std::endl;
111 // parameter widthNum
112 unsigned int widthNum = 1;
113 trace.info() << "the numerator of the rational width (a non-null integer) =" << widthNum<< std::endl;
114 // parameter widthDen
115 unsigned int widthDen = 1;
116 trace.info() << "the denominator of the rational width (a non-null integer)= " << widthDen<< std::endl;
117
119
122 Image image = VolReader<Image>::importVol(inputFilename);
123 DigitalSet set3d (image.domain());
124 SetFromImage<DigitalSet>::append<Image>(set3d, image, threshold,255);
126
128 trace.beginBlock( "Set up digital surface." );
129 // We initializes the cellular grid space used for defining the
130 // digital surface.
131 KSpace ks;
132 bool ok = ks.init( set3d.domain().lowerBound(),
133 set3d.domain().upperBound(), true );
134 if ( ! ok ) std::cerr << "[KSpace.init] Failed." << std::endl;
135 SurfelAdjacency<KSpace::dimension> surfAdj( true ); // interior in all directions.
136 MyDigitalSurfaceContainer* ptrSurfContainer =
137 new MyDigitalSurfaceContainer( ks, set3d, surfAdj );
138 MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
139 trace.endBlock();
141
143 trace.beginBlock( "Segment into planes." );
144 std::set<Vertex> processedVertices;
145 std::vector<SegmentedPlane*> segmentedPlanes;
146 std::map<Vertex,SegmentedPlane*> v2plane;
147 Point p;
148 Dimension axis;
149 unsigned int j = 0;
150 unsigned int nb = digSurf.size();
151 for ( ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
152 {
153 if ( ( (++j) % 50 == 0 ) || ( j == nb ) ) trace.progressBar( j, nb );
154 Vertex v = *it;
155 if ( processedVertices.find( v ) != processedVertices.end() ) // already in set
156 continue; // process to next vertex
157
158 SegmentedPlane* ptrSegment = new SegmentedPlane;
159 segmentedPlanes.push_back( ptrSegment ); // to delete them afterwards.
160 axis = ks.sOrthDir( v );
161 ptrSegment->plane.init( axis, 500, widthNum, widthDen );
162 // The visitor takes care of all the breadth-first traversal.
163 Visitor visitor( digSurf, v );
164 while ( ! visitor.finished() )
165 {
166 Visitor::Node node = visitor.current();
167 v = node.first;
168 if ( processedVertices.find( v ) == processedVertices.end() )
169 { // Vertex is not in processedVertices
170 axis = ks.sOrthDir( v );
171 p = ks.sCoords( ks.sDirectIncident( v, axis ) );
172 bool isExtended = ptrSegment->plane.extend( p );
173 if ( isExtended )
174 { // surfel is in plane.
175 processedVertices.insert( v );
176 v2plane[ v ] = ptrSegment;
177 visitor.expand();
178 }
179 else // surfel is not in plane and should not be used in the visit.
180 visitor.ignore();
181 }
182 else // surfel is already in some plane.
183 visitor.ignore();
184 }
185 // Assign random color for each plane.
186 ptrSegment->color = Color( rand() % 256, rand() % 256, rand() % 256, 255 );
187 }
188 trace.endBlock();
190
192 PolyscopeViewer<> viewer( ks );
193 for ( std::map<Vertex,SegmentedPlane*>::const_iterator
194 it = v2plane.begin(), itE = v2plane.end();
195 it != itE; ++it )
196 {
197 viewer << it->second->color;
198 viewer << ks.unsigns( it->first );
199 }
201
203 for ( std::vector<SegmentedPlane*>::iterator
204 it = segmentedPlanes.begin(), itE = segmentedPlanes.end();
205 it != itE; ++it )
206 delete *it;
207 segmentedPlanes.clear();
208 v2plane.clear();
210
211 viewer.show();
212 return 0;
213}
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:77
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
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])
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
DGtal::uint32_t Dimension
Definition Common.h:119
Trace trace
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())
Image image(domain)
TriMesh::Vertex Vertex

References DGtal::SetFromImage< TSet >::append(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), SegmentedPlane::color, DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::current(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::end(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extend(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::finished(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::ignore(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), SegmentedPlane::plane, DGtal::KhalimskySpaceND< dim, TInteger >::sCoords(), DGtal::KhalimskySpaceND< dim, TInteger >::sDirectIncident(), DGtal::PolyscopeViewer< Space, KSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), DGtal::KhalimskySpaceND< dim, TInteger >::sOrthDir(), DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::unsigns().