DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testUmbrellaComputer.cpp File Reference
#include <iostream>
#include <fstream>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/UmbrellaComputer.h"

Go to the source code of this file.

Functions

bool testUmbrellaComputer ()
 
bool testCombinatorialSurface ()
 
int main (int argc, char **argv)
 

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/02/02

Functions for testing class UmbrellaComputer.

This file is part of the DGtal library.

Definition in file testUmbrellaComputer.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 274 of file testUmbrellaComputer.cpp.

275{
276 trace.beginBlock ( "Testing class UmbrellaComputer" );
277 trace.info() << "Args:";
278 for ( int i = 0; i < argc; ++i )
279 trace.info() << " " << argv[ i ];
280 trace.info() << endl;
281
282 bool res = testUmbrellaComputer()
283 && testCombinatorialSurface(); // && ... other tests
284 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
285 trace.endBlock();
286 return res ? 0 : 1;
287}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testCombinatorialSurface()
bool testUmbrellaComputer()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testCombinatorialSurface(), testUmbrellaComputer(), and DGtal::trace.

◆ testCombinatorialSurface()

bool testCombinatorialSurface ( )

Definition at line 139 of file testUmbrellaComputer.cpp.

140{
141 using namespace Z3i;
142
144 typedef ImplicitBall<Space> EuclideanShape;
148 typedef Boundary::SurfelConstIterator ConstIterator;
149 //typedef Boundary::Tracker Tracker;
150 typedef Boundary::Surfel Surfel;
151 //typedef Boundary::DigitalSurfaceTracker DigitalSurfaceTracker;
153 //typedef UmbrellaComputer<DigitalSurfaceTracker> MyUmbrellaComputer;
157
158 unsigned int nbok = 0;
159 unsigned int nb = 0;
160 trace.beginBlock ( "Testing block ... Combinatorial surface" );
161 // Creating shape
162 Point c( 0, 0, 0 );
163 EuclideanShape ball( c, 8 ); // ball r=4
164 DigitalShape shape;
165 shape.attach( ball );
166 shape.init( RealPoint( -2.0, -3.0, -10.0 ),
167 RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
168 // Creating cellular grid space around.
169 Domain domain = shape.getDomain();
170 KSpace K;
171 nbok += K.init( domain.lowerBound(), domain.upperBound(), true ) ? 1 : 0;
172 nb++;
173 trace.info() << "(" << nbok << "/" << nb << ") "
174 << "K.init() is ok" << std::endl;
175 // Find start surfel on surface.
176 Surfel bel = Surfaces<KSpace>::findABel( K, shape, 10000 );
177 // Define surface container then surface itself.
178 Boundary boundary( K, // cellular space
179 shape, // point predicate
180 SurfelAdjacency<KSpace::dimension>( true ), // adjacency
181 bel // starting surfel
182 );
183 MyDigitalSurface digSurf( boundary ); // boundary is cloned
184
185
186 trace.beginBlock ( "Testing block ... Digital surface faces." );
187 MyDigitalSurface::FaceSet all_faces = digSurf.allFaces();
188 for ( MyDigitalSurface::FaceSet::const_iterator it = all_faces.begin(),
189 it_end = all_faces.end(); it != it_end; ++it )
190 {
191 std::cerr << " face=" << K.sKCoords( digSurf.pivot( *it ) ) << ":";
192 std::cerr << "(" << it->nbVertices << ")" << (it->isClosed() ? "C": "O");
193 MyDigitalSurface::VertexRange vtx = digSurf.verticesAroundFace( *it );
194 for ( unsigned int i = 0; i < vtx.size(); ++i )
195 {
196 std::cerr << " " << K.sKCoords( vtx[ i ] );
197 }
198 std::cerr << std::endl;
199 }
200 trace.endBlock();
201
202 // Checks that vertices of a face are in the same order as the
203 // incident arcs.
204 trace.beginBlock( "Testing block ...Check order faces/arcs" );
205 unsigned int nbvtcs = 0;
206 unsigned int nbarcs = 0;
207 unsigned int nbfaces = 0;
208 for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
209 it != it_end; ++it, ++nbvtcs )
210 {
211 const Vertex & vtx = *it;
212 MyDigitalSurface::ArcRange arcs = digSurf.outArcs( vtx );
213 for ( unsigned int i = 0; i < arcs.size(); ++i, ++nbarcs )
214 {
215 const Arc & arc = arcs[ i ];
217 faces = digSurf.facesAroundArc( arc );
218 for ( unsigned int j = 0; j < faces.size(); ++j, ++nbfaces )
219 {
220 const Face & face = faces[ j ];
221 // search vertex in face.
223 vertices = digSurf.verticesAroundFace( face );
224 unsigned int k = 0;
225 while ( ( k < vertices.size() ) && ( vertices[ k ] != vtx ) )
226 ++k;
227 ++nb;
228 if ( k == vertices.size() )
229 trace.info() << "Error at vertex " << vtx
230 << ". Vertex not found in incident face."
231 << std::endl;
232 else ++nbok;
233 ++nb;
234 if ( digSurf.head( arc ) != vertices[ (k+1) % vertices.size() ] )
235 trace.info() << "Error at vertex " << vtx
236 << ". Arc is not in incident face."
237 << std::endl;
238 else ++nbok;
239 }
240 }
241 }
242 trace.info() << "(" << nbok << "/" << nb << ") "
243 << "Tested nbvtcs=" << nbvtcs
244 << " nbarcs=" << nbarcs
245 << " nbfaces=" << nbfaces
246 << std::endl;
247 trace.endBlock();
248
249 trace.beginBlock( "Testing block ... export as OFF: ex-digital-surface.off" );
250 ofstream fout( "ex-digital-surface.off" );
251 if ( fout.good() )
252 digSurf.exportSurfaceAs3DOFF( fout );
253 fout.close();
254 trace.endBlock();
255
256
257
258 unsigned int nbsurfels = 0;
259 for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
260 it != it_end; ++it )
261 {
262 ++nbsurfels;
263 }
264 trace.info() << nbsurfels << " surfels found." << std::endl;
265 trace.endBlock();
266
267 return nbok == nb;
268}
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Surfel Vertex
Defines the type for a vertex.
std::vector< Vertex > VertexRange
The range of vertices is defined as a vector.
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
std::vector< Face > FaceRange
The range of faces is defined as a vector.
std::set< Face > FaceSet
The set of faces is defined as set.
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
void attach(ConstAlias< EuclideanShape > shape)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Domain getDomain() const
const Point & lowerBound() const
const Point & upperBound() const
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:65
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.
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::ConstIterator ConstIterator
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Z2i::RealPoint RealPoint
MyPointD Point
Definition: testClone2.cpp:383
KSpace K
Domain domain
HyperRectDomain< Space > Domain
TriMesh::Face Face
TriMesh::Vertex Vertex

References DGtal::DigitalSurface< TDigitalSurfaceContainer >::allFaces(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::Trace::beginBlock(), domain, DGtal::Trace::endBlock(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::exportSurfaceAs3DOFF(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::facesAroundArc(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getDomain(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::head(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), K, DGtal::HyperRectDomain< TSpace >::lowerBound(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::outArcs(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::pivot(), DGtal::KhalimskySpaceND< dim, TInteger >::sKCoords(), DGtal::trace, DGtal::HyperRectDomain< TSpace >::upperBound(), and DGtal::DigitalSurface< TDigitalSurfaceContainer >::verticesAroundFace().

Referenced by main().

◆ testUmbrellaComputer()

bool testUmbrellaComputer ( )

Definition at line 48 of file testUmbrellaComputer.cpp.

49{
50 using namespace Z3i;
51
53 typedef ImplicitBall<Space> EuclideanShape;
57 typedef Boundary::SurfelConstIterator ConstIterator;
58 //typedef Boundary::Tracker Tracker;
59 typedef Boundary::Surfel Surfel;
60 typedef Boundary::DigitalSurfaceTracker DigitalSurfaceTracker;
62 typedef UmbrellaComputer<DigitalSurfaceTracker> MyUmbrellaComputer;
63
64 unsigned int nbok = 0;
65 unsigned int nb = 0;
66 trace.beginBlock ( "Testing block ... UmbrellaComputer" );
67 // Creating shape
68 Point c( 0, 0, 0 );
69 EuclideanShape ball( c, 2 ); // ball r=4
70 DigitalShape shape;
71 shape.attach( ball );
72 shape.init( RealPoint( -10.0, -10.0, -10.0 ),
73 RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
74 // Creating cellular grid space around.
75 Domain domain = shape.getDomain();
76 KSpace K;
77 nbok += K.init( domain.lowerBound(), domain.upperBound(), true ) ? 1 : 0;
78 nb++;
79 trace.info() << "(" << nbok << "/" << nb << ") "
80 << "K.init() is ok" << std::endl;
81 // Find start surfel on surface.
82 Surfel bel = Surfaces<KSpace>::findABel( K, shape, 10000 );
83 // Define surface container then surface itself.
84 Boundary boundary( K, // cellular space
85 shape, // point predicate
86 SurfelAdjacency<KSpace::dimension>( true ), // adjacency
87 bel // starting surfel
88 );
89 MyDigitalSurface digSurf( boundary ); // boundary is cloned
90
91 // Get tracker on surface.
92 DigitalSurfaceTracker* ptrTracker = boundary.newTracker( bel );
93 MyUmbrellaComputer umbrella;
94 KSpace::DirIterator dirIt = K.sDirs( bel );
95 Dimension k = *dirIt;
96 Dimension j = *(++dirIt);
97 trace.beginBlock ( "Testing block ... forward umbrella" );
98 umbrella.init( *ptrTracker, k, true, j );
99 unsigned int nb_forward = 0;
100 Surfel init_bel = bel;
101 do {
102 Point x = K.sKCoords( bel );
103 trace.info() << x << std::endl;
104 umbrella.next();
105 ++nb_forward;
106 bel = umbrella.surfel();
107 } while ( bel != init_bel );
108 trace.endBlock();
109 trace.beginBlock ( "Testing block ... backward umbrella" );
110 unsigned int nb_backward = 0;
111 do {
112 Point x = K.sKCoords( bel );
113 trace.info() << x << std::endl;
114 umbrella.previous();
115 ++nb_backward;
116 bel = umbrella.surfel();
117 } while ( bel != init_bel );
118 nb++; nbok += nb_forward == nb_backward ? 1 : 0;
119
120 trace.info() << "(" << nbok << "/" << nb << ") "
121 << " nb_forward(" << nb_forward
122 << ") == nb_backward(" << nb_backward << ")"
123 << std::endl;
124 trace.endBlock();
125 unsigned int nbsurfels = 0;
126 for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
127 it != it_end; ++it )
128 {
129 ++nbsurfels;
130 }
131 trace.info() << nbsurfels << " surfels found." << std::endl;
132
133 trace.endBlock();
134
135 delete ptrTracker;
136 return nbok == nb;
137}
DirIterator sDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell spans.
typename PreCellularGridSpace::DirIterator DirIterator
Aim: Useful for computing umbrellas on 'DigitalSurface's, ie set of n-1 cells around a n-3 cell.
DGtal::uint32_t Dimension
Definition: Common.h:137

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::Trace::beginBlock(), domain, DGtal::Trace::endBlock(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getDomain(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), K, DGtal::HyperRectDomain< TSpace >::lowerBound(), DGtal::KhalimskySpaceND< dim, TInteger >::sDirs(), DGtal::KhalimskySpaceND< dim, TInteger >::sKCoords(), DGtal::trace, and DGtal::HyperRectDomain< TSpace >::upperBound().

Referenced by main().