DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testExpander.cpp
Go to the documentation of this file.
1
16
29
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/DomainAdjacency.h"
41
#include "DGtal/topology/DigitalTopology.h"
42
#include "DGtal/topology/Object.h"
43
#include "DGtal/graph/Expander.h"
45
46
using namespace
std
;
47
using namespace
DGtal
;
48
49
#define INBLOCK_TEST(x) \
50
nbok += ( x ) ? 1 : 0; \
51
nb++; \
52
trace.info() << "(" << nbok << "/" << nb << ") " \
53
<< #x << std::endl;
54
55
#define INBLOCK_TEST2(x,y) \
56
nbok += ( x ) ? 1 : 0; \
57
nb++; \
58
trace.info() << "(" << nbok << "/" << nb << ") " \
59
<< y << std::endl;
60
62
// Functions for testing class Expander.
64
68
bool
testExpander()
69
{
70
unsigned
int
nbok = 0;
71
unsigned
int
nb = 0;
72
73
// ------------------------------ Types ------------------------------
74
typedef
SpaceND< 3 >
Z3;
75
typedef
Z3::Point
Point
;
76
typedef
Point::Coordinate
Coordinate
;
77
typedef
HyperRectDomain< Z3 >
Domain
;
78
typedef
Domain::ConstIterator
DomainConstIterator;
79
80
typedef
MetricAdjacency< Z3, 1 >
MetricAdj6;
81
typedef
MetricAdjacency< Z3, 2 >
MetricAdj18;
82
typedef
DomainAdjacency< Domain, MetricAdj6 >
Adj6;
83
typedef
DomainAdjacency< Domain, MetricAdj18 >
Adj18;
84
// typedef MetricAdjacency< Z3, 1 > Adj6;
85
// typedef MetricAdjacency< Z3, 2 > Adj18;
86
87
typedef
DigitalTopology< Adj6, Adj18 >
DT6_18;
88
89
typedef
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type
DigitalSet
;
90
typedef
Object<DT6_18, DigitalSet>
ObjectType;
91
typedef
Expander< ObjectType >
ObjectExpander;
92
// ----------------------- Domain, Topology ------------------------------
93
Point
p1( -50, -50, -50 );
94
Point
p2( 50, 50, 50 );
95
Domain
domain
( p1, p2 );
96
97
MetricAdj6 madj6;
98
MetricAdj18 madj18;
99
Adj6 adj6(
domain
, madj6 );
100
Adj18 adj18(
domain
, madj18 );
101
// Adj6 adj6;
102
// Adj18 adj18;
103
104
DT6_18 dt6_18( adj6, adj18,
JORDAN_DT
);
105
// ------------------------------- Object ------------------------------
106
Coordinate
r = 9;
107
double
radius = (double) (r+1);
108
Point
c( 0, 0 );
109
Point
l( r, 0 );
110
DigitalSet
ball_set(
domain
);
111
ostringstream sstr;
112
sstr <<
"Creating 3D ball( r < "
<< radius <<
" ) ..."
;
113
trace
.
beginBlock
( sstr.str() );
114
for
( DomainConstIterator it =
domain
.begin();
115
it !=
domain
.end();
116
++it )
117
{
118
if
( (*it - c ).norm() < radius )
119
// insertNew is very important for vector container.
120
ball_set.
insertNew
( *it );
121
}
122
trace
.
endBlock
();
123
124
trace
.
beginBlock
(
"Testing Object instantiation and smart copy ..."
);
125
ObjectType ball( dt6_18, ball_set );
126
ObjectType ball2( ball );
127
INBLOCK_TEST
( ball.size() == 4139 );
128
trace
.
info
() <<
"ball.size() = "
<< ball.size()
129
<<
" 4/3*pi*r^3 = "
<< ( 4.0*M_PI*radius*radius*radius/3.0 )
130
<< endl;
131
trace
.
info
() <<
"ball = "
<< ball << endl;
132
trace
.
info
() <<
"ball2 = "
<< ball2 << endl;
133
trace
.
endBlock
();
134
135
trace
.
beginBlock
(
"Testing border extraction ..."
);
136
ObjectType sphere = ball.border();
137
INBLOCK_TEST
( sphere.size() == 1434 );
138
trace
.
info
() << sphere << endl;
139
trace
.
info
() <<
"sphere.size() = "
<< sphere.size()
140
<<
" 4*pi*r^2 = "
<< ( 4.0*M_PI*radius*radius )
141
<< endl;
142
trace
.
endBlock
();
143
144
trace
.
beginBlock
(
"Testing expansion by layers in the ball from center..."
);
145
ObjectExpander expander( ball, c );
146
while
( ! expander.finished() )
147
{
148
trace
.
info
() << expander << std::endl;
149
expander.nextLayer();
150
}
151
nbok += expander.distance() <= sqrt(3.0)*radius ? 1 : 0;
152
nb++;
153
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
154
<<
"expander.distance() = "
<< expander.distance()
155
<<
" <= "
<< sqrt(3.0)*radius << std::endl;
156
trace
.
endBlock
();
157
158
trace
.
beginBlock
(
"Testing expansion by layers on the sphere from a point ..."
);
159
ObjectExpander expander2( sphere, l );
160
while
( ! expander2.finished() )
161
{
162
trace
.
info
() << expander2 << std::endl;
163
expander2.nextLayer();
164
}
165
nbok += expander2.distance() <= sqrt(2.0)*M_PI*radius ? 1 : 0;
166
nb++;
167
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
168
<<
"expander2.distance() = "
<< expander2.distance()
169
<<
" <= "
<< sqrt(2.0)*M_PI*radius << std::endl;
170
trace
.
endBlock
();
171
172
173
return
nbok == nb;
174
}
175
177
// Standard services - public :
178
179
int
main
(
int
argc,
char
** argv )
180
{
181
trace
.
beginBlock
(
"Testing class Expander"
);
182
trace
.
info
() <<
"Args:"
;
183
for
(
int
i = 0; i < argc; ++i )
184
trace
.
info
() <<
" "
<< argv[ i ];
185
trace
.
info
() << endl;
186
187
bool
res = testExpander();
// && ... other tests
188
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
189
trace
.
endBlock
();
190
return
res ? 0 : 1;
191
}
192
// //
DGtal::DigitalSetByAssociativeContainer::insertNew
void insertNew(const Point &p)
DGtal::DigitalTopology< Adj6, Adj18 >
DGtal::DomainAdjacency
Aim: Given a domain and an adjacency, limits the given adjacency to the specified domain for all adja...
Definition
DomainAdjacency.h:74
DGtal::Expander
Aim: This class is useful to visit an object by adjacencies, layer by layer.
Definition
Expander.h:98
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::HyperRectDomain< Space >::ConstIterator
Iterator ConstIterator
Definition
HyperRectDomain.h:125
DGtal::MetricAdjacency
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
Definition
MetricAdjacency.h:80
DGtal::Object
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition
Object.h:120
DGtal::SpaceND
Definition
SpaceND.h:96
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::Domain
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
DGtal::JORDAN_DT
@ JORDAN_DT
Definition
DigitalTopology.h:57
std
STL namespace.
DGtal::DigitalSetSelector::Type
DigitalSetByAssociativeContainer< Domain, std::unordered_set< typename Domain::Point > > Type
Definition
DigitalSetSelector.h:102
DGtal::Coordinate
INBLOCK_TEST
#define INBLOCK_TEST(x)
Definition
testBasicBoolFunctors.cpp:40
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
DigitalSet
Z2i::DigitalSet DigitalSet
Definition
testVoronoiMapComplete.cpp:40
tests
graph
testExpander.cpp
Generated on
for DGtal by
1.18.0