DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testDistanceTransformationMetrics.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/helpers/StdDefs.h"
34
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
35
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
36
#include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
37
#include "DGtal/images/ImageContainerBySTLVector.h"
38
#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
40
41
using namespace
std
;
42
using namespace
DGtal
;
43
44
45
//Generate Random seeds
46
template
<
typename
Image>
47
void
randomSeeds
(
Image
&input,
const
unsigned
int
nb,
const
int
value)
48
{
49
typename
Image::Point
p, low = input.
domain
().
lowerBound
(), up = input.
domain
().
upperBound
();
50
typename
Image::Vector
ext;
51
52
for
(
Dimension
i = 0; i < Image::Domain::dimension; i++)
53
ext[i] = up[i] - low[i] + 1;
54
55
56
for
(
unsigned
int
k = 0 ; k < nb; k++)
57
{
58
for
(
unsigned
int
dim
= 0;
dim
< Image::dimension;
dim
++)
59
{
60
p[
dim
] = rand() % (ext[
dim
]) + low[
dim
];
61
}
62
input.
setValue
(p, value);
63
}
64
}
65
66
//Bruteforce quadratic computation of the distance map
67
template
<
typename
Image,
typename
Pred,
typename
Metric>
68
bool
checkVoronoi
(
Image
&result,Pred &pointPredicate, Metric &metric)
69
{
70
typedef
typename
Image::Domain
Domain
;
71
72
for
(
typename
Domain::ConstIterator
it = result.
domain
().
begin
(),
73
itend=result.
domain
().
end
();
74
it != itend; ++it)
75
{
76
typename
Metric::Value dist = result(*it);
77
78
for
(
typename
Domain::ConstIterator
itbis = result.
domain
().
begin
(),
79
itendbis=result.
domain
().
end
();
80
itbis != itendbis; ++itbis)
81
{
82
if
(!pointPredicate(*itbis) && (metric(*it, *itbis) < dist))
83
{
84
trace
.
error
()<<
"Error in Voronoi map at "
<< *it<<
" computed="
<<dist<<
" but find="
<<metric(*it, *itbis) << std::endl;
85
return
false
;
86
}
87
}
88
}
89
return
true
;
90
}
91
92
93
template
<
typename
Space,
int
norm>
94
bool
testCompareExactBruteForce
(
unsigned
int
size,
unsigned
int
nb)
95
{
96
trace
.
beginBlock
(
"Checking Exact/Inexct predicate metrics"
);
97
typedef
ExactPredicateLpSeparableMetric<Space, norm>
MetricEx;
98
typedef
HyperRectDomain<Space>
Domain
;
99
typedef
typename
Space::Point
Point
;
100
typedef
DigitalSetBySTLSet<Domain>
Set;
101
typedef
functors::NotPointPredicate<Set>
NegPredicate;
102
103
Point
low=Point::diagonal(0),
104
up=Point::diagonal(size);
105
106
Domain
domain
(low,up);
107
Set set(
domain
);
108
109
for
(
unsigned
int
i = 0; i<nb; ++i)
110
{
111
Point
p;
112
for
(
unsigned
int
dim
=0;
dim
<
Space::dimension
;++
dim
)
113
p[
dim
] = rand() % size;
114
set.insert(p);
115
}
116
117
trace
.
info
()<<
"Testing metrics "
<<MetricEx()<<std::endl;
118
trace
.
info
()<<
"Testing space dimension "
<<
Space::dimension
<<std::endl;
119
trace
.
info
()<<
"Inserting "
<<set.size() <<
" points."
<<std::endl;
120
121
NegPredicate negPred(set);
122
123
typedef
DistanceTransformation<Space, NegPredicate, MetricEx>
DTEx;
124
MetricEx metricEx;
125
DTEx dtex(&
domain
, &negPred, &metricEx);
126
127
bool
res=
checkVoronoi
(dtex, negPred, metricEx);
128
129
trace
.
endBlock
();
130
return
res;
131
}
132
133
134
135
template
<
typename
Space>
136
bool
testCompareInexactBruteForce
(
double
norm,
unsigned
int
size,
unsigned
int
nb)
137
{
138
trace
.
beginBlock
(
"Checking Exact/Inexct predicate metrics"
);
139
typedef
InexactPredicateLpSeparableMetric<Space>
MetricInex;
140
typedef
HyperRectDomain<Space>
Domain
;
141
typedef
typename
Space::Point
Point
;
142
typedef
DigitalSetBySTLSet<Domain>
Set;
143
typedef
functors::NotPointPredicate<Set>
NegPredicate;
144
145
Point
low=Point::diagonal(0),
146
up=Point::diagonal(size);
147
148
Domain
domain
(low,up);
149
Set set(
domain
);
150
151
for
(
unsigned
int
i = 0; i<nb; ++i)
152
{
153
Point
p;
154
for
(
unsigned
int
dim
=0;
dim
<
Space::dimension
;++
dim
)
155
p[
dim
] = rand() % size;
156
set.insert(p);
157
}
158
159
trace
.
info
()<<
"Testing metrics "
<<MetricInex(norm)<<std::endl;
160
trace
.
info
()<<
"Testing space dimension "
<<
Space::dimension
<<std::endl;
161
trace
.
info
()<<
"Inserting "
<<set.size() <<
" points."
<<std::endl;
162
163
NegPredicate negPred(set);
164
165
typedef
DistanceTransformation<Space, NegPredicate, MetricInex>
DTIn;
166
MetricInex metricInex(norm);
167
DTIn dtinex(&
domain
, &negPred, &metricInex);
168
169
bool
res=
checkVoronoi
(dtinex, negPred, metricInex);
170
171
trace
.
endBlock
();
172
return
res;
173
}
174
176
// Standard services - public :
177
178
int
main
(
int
argc,
char
** argv )
179
{
180
trace
.
beginBlock
(
"Testing class DistanceTransformationMetrics"
);
181
trace
.
info
() <<
"Args:"
;
182
for
(
int
i = 0; i < argc; ++i )
183
trace
.
info
() <<
" "
<< argv[ i ];
184
trace
.
info
() << endl;
185
186
bool
res =
testCompareExactBruteForce<Z2i::Space, 2>
(16, 8)
187
&&
testCompareExactBruteForce<Z2i::Space, 1>
(16, 8)
188
&&
testCompareExactBruteForce<Z3i::Space, 2>
(16, 8)
189
&&
testCompareExactBruteForce<Z2i::Space, 4>
(16, 8)
190
&&
testCompareInexactBruteForce<Z2i::Space>
(2.0,16, 8)
191
&&
testCompareInexactBruteForce<Z2i::Space>
(1.33,16, 8)
192
&&
testCompareInexactBruteForce<Z2i::Space>
(2.6,16, 8)
193
&&
testCompareInexactBruteForce<Z3i::Space>
(2.44,10, 5)
194
&&
testCompareInexactBruteForce<Z3i::Space>
(12.3,10, 5);
195
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
196
trace
.
endBlock
();
197
return
res ? 0 : 1;
198
}
199
// //
DGtal::DigitalSetBySTLSet
Aim: A container class for storing sets of digital points within some given domain.
Definition
DigitalSetBySTLSet.h:85
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition
DistanceTransformation.h:99
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition
ExactPredicateLpSeparableMetric.h:88
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition
HyperRectDomain.h:176
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition
HyperRectDomain.h:201
DGtal::HyperRectDomain< Space >::ConstIterator
Iterator ConstIterator
Definition
HyperRectDomain.h:125
DGtal::ImageContainerBySTLVector< Domain, Value >::Domain
Domain Domain
Definition
ImageContainerBySTLVector.h:137
DGtal::ImageContainerBySTLVector< Domain, Value >::Vector
Domain::Vector Vector
Definition
ImageContainerBySTLVector.h:139
DGtal::ImageContainerBySTLVector< Domain, Value >::Point
Domain::Point Point
Definition
ImageContainerBySTLVector.h:138
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::domain
const Domain & domain() const
Definition
Image.h:192
DGtal::Image::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition
Image.h:247
DGtal::InexactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with approximated predicates.
Definition
InexactPredicateLpSeparableMetric.h:82
DGtal::Point
DGtal::SpaceND< 3, Integer >::Point
PointVector< dim, Integer > Point
Definition
SpaceND.h:110
DGtal::SpaceND< 3, Integer >::dimension
static const Dimension dimension
Definition
SpaceND.h:132
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::error
std::ostream & error()
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::Dimension
DGtal::uint32_t Dimension
Definition
Common.h:119
DGtal::trace
Trace trace
std
STL namespace.
DGtal::functors::NotPointPredicate
Aim: The predicate returns true when the point predicate given at construction return false....
Definition
BasicPointPredicates.h:208
testCompareExactBruteForce
bool testCompareExactBruteForce(unsigned int size, unsigned int nb)
Definition
testDistanceTransformationMetrics.cpp:94
checkVoronoi
bool checkVoronoi(Image &result, Pred &pointPredicate, Metric &metric)
Definition
testDistanceTransformationMetrics.cpp:68
testCompareInexactBruteForce
bool testCompareInexactBruteForce(double norm, unsigned int size, unsigned int nb)
Definition
testDistanceTransformationMetrics.cpp:136
randomSeeds
void randomSeeds(Image &input, const unsigned int nb, const int value)
Definition
testDistanceTransformation.cpp:60
dim
#define dim
Definition
testImageContainerByHashTree.cpp:40
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
tests
geometry
volumes
distance
testDistanceTransformationMetrics.cpp
Generated on
for DGtal by
1.18.0