DGtal 1.4.0
Loading...
Searching...
No Matches
testExpander-benchmark.cpp
1
31#include <iostream>
32#include <sstream>
33#include "DGtal/base/Common.h"
34#include "DGtal/kernel/SpaceND.h"
35#include "DGtal/kernel/domains/DomainPredicate.h"
36#include "DGtal/kernel/domains/HyperRectDomain.h"
37#include "DGtal/kernel/sets/DigitalSetSelector.h"
38#include "DGtal/kernel/sets/DigitalSetConverter.h"
39#include "DGtal/topology/MetricAdjacency.h"
40#include "DGtal/topology/DomainMetricAdjacency.h"
41#include "DGtal/topology/DomainAdjacency.h"
42#include "DGtal/topology/DigitalTopology.h"
43#include "DGtal/topology/Object.h"
44#include "DGtal/graph/Expander.h"
46
47using namespace std;
48using namespace DGtal;
49
50#define INBLOCK_TEST(x) \
51 nbok += ( x ) ? 1 : 0; \
52 nb++; \
53 trace.info() << "(" << nbok << "/" << nb << ") " \
54 << #x << std::endl;
55
56#define INBLOCK_TEST2(x,y) \
57 nbok += ( x ) ? 1 : 0; \
58 nb++; \
59 trace.info() << "(" << nbok << "/" << nb << ") " \
60 << y << std::endl;
61
63// Functions for testing class Expander.
65
69bool testExpander()
70{
71 unsigned int nbok = 0;
72 unsigned int nb = 0;
73
74 // ------------------------------ Types ------------------------------
75 typedef SpaceND< 3 > Z3;
76 typedef Z3::Point Point;
77 typedef Point::Coordinate Coordinate;
79 typedef Domain::ConstIterator DomainConstIterator;
80
81 typedef MetricAdjacency< Z3, 1 > MetricAdj6;
82 typedef MetricAdjacency< Z3, 2 > MetricAdj18;
85 // typedef MetricAdjacency< Z3, 1 > Adj6;
86 // typedef MetricAdjacency< Z3, 2 > Adj18;
87
89
91 typedef Object<DT6_18, DigitalSet> ObjectType;
92 typedef Expander< ObjectType > ObjectExpander;
93 // ----------------------- Domain, Topology ------------------------------
94 Point p1( -50, -50, -50 );
95 Point p2( 50, 50, 50 );
96 Domain domain( p1, p2 );
97
98 MetricAdj6 madj6;
99 MetricAdj18 madj18;
100 Adj6 adj6( domain, madj6 );
101 Adj18 adj18( domain, madj18 );
102 // Adj6 adj6;
103 // Adj18 adj18;
104
105 DT6_18 dt6_18( adj6, adj18, JORDAN_DT );
106 // ------------------------------- Object ------------------------------
107 Coordinate r = 49;
108 double radius = (double) (r+1);
109 Point c( 0, 0 );
110 Point l( r, 0 );
111 DigitalSet ball_set( domain );
112 ostringstream sstr;
113 sstr << "Creating 3D ball( r < " << radius << " ) ...";
114 trace.beginBlock ( sstr.str() );
115 for ( DomainConstIterator it = domain.begin();
116 it != domain.end();
117 ++it )
118 {
119 if ( (*it - c ).norm() < radius )
120 // insertNew is very important for vector container.
121 ball_set.insertNew( *it );
122 }
123 trace.endBlock();
124
125 trace.beginBlock ( "Testing Object instanciation and smart copy ..." );
126 ObjectType ball( dt6_18, ball_set );
127 ObjectType ball2( ball );
128 INBLOCK_TEST( ball.size() == 523155 );
129 trace.info() << "ball.size() = " << ball.size()
130 << " 4/3*pi*r^3 = " << ( 4.0*M_PI*radius*radius*radius/3.0 )
131 << endl;
132 trace.info() << "ball = " << ball << endl;
133 trace.info() << "ball2 = " << ball2 << endl;
134 trace.endBlock();
135
136 trace.beginBlock ( "Testing border extraction ..." );
137 ObjectType sphere = ball.border();
138 INBLOCK_TEST( sphere.size() == 39546 );
139 trace.info() << sphere << endl;
140 trace.info() << "sphere.size() = " << sphere.size()
141 << " 4*pi*r^2 = " << ( 4.0*M_PI*radius*radius )
142 << endl;
143 trace.endBlock();
144
145 trace.beginBlock ( "Testing expansion by layers in the ball from center..." );
146 ObjectExpander expander( ball, c );
147 while ( ! expander.finished() )
148 {
149 trace.info() << expander << std::endl;
150 expander.nextLayer();
151 }
152 nbok += expander.distance() <= sqrt(3.0)*radius ? 1 : 0;
153 nb++;
154 trace.info() << "(" << nbok << "/" << nb << ") "
155 << "expander.distance() = " << expander.distance()
156 << " <= " << sqrt(3.0)*radius << std::endl;
157 trace.endBlock();
158
159 trace.beginBlock ( "Testing expansion by layers on the sphere from a point ..." );
160 ObjectExpander expander2( sphere, l );
161 while ( ! expander2.finished() )
162 {
163 trace.info() << expander2 << std::endl;
164 expander2.nextLayer();
165 }
166 nbok += expander2.distance() <= sqrt(2.0)*M_PI*radius ? 1 : 0;
167 nb++;
168 trace.info() << "(" << nbok << "/" << nb << ") "
169 << "expander2.distance() = " << expander2.distance()
170 << " <= " << sqrt(2.0)*M_PI*radius << std::endl;
171 trace.endBlock();
172
173
174 return nbok == nb;
175}
176
178// Standard services - public :
179
180int main( int argc, char** argv )
181{
182 trace.beginBlock ( "Testing class Expander" );
183 trace.info() << "Args:";
184 for ( int i = 0; i < argc; ++i )
185 trace.info() << " " << argv[ i ];
186 trace.info() << endl;
187
188 bool res = testExpander(); // && ... other tests
189 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
190 trace.endBlock();
191 return res ? 0 : 1;
192}
193// //
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents a digital topology as a couple of adjacency relations.
Aim: Given a domain and an adjacency, limits the given adjacency to the specified domain for all adja...
Aim: This class is useful to visit an object by adjacencies, layer by layer.
Definition Expander.h:98
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition Object.h:120
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
MetricAdjacency< Space, 2 > Adj18
Definition StdDefs.h:161
Space Z3
Definition StdDefs.h:145
MetricAdjacency< Space, 1 > Adj6
Definition StdDefs.h:159
DigitalTopology< Adj6, Adj18 > DT6_18
Definition StdDefs.h:164
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
#define INBLOCK_TEST(x)
int main()
Definition testBits.cpp:56
MyPointD Point
Domain domain
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet