DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testDistanceTransformationND.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/base/Common.h"
34
#include "DGtal/kernel/SpaceND.h"
35
#include "DGtal/kernel/domains/HyperRectDomain.h"
36
#include "DGtal/images/ImageSelector.h"
37
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
38
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
39
#include "DGtal/io/colormaps/HueShadeColorMap.h"
40
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
41
#include "DGtal/io/boards/Board2D.h"
42
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
44
45
using namespace
std
;
46
using namespace
DGtal
;
47
using namespace
DGtal::functors
;
48
50
// Functions for testing class DistanceTransformND.
52
56
bool
testDistanceTransformND
()
57
{
58
unsigned
int
nbok = 0;
59
unsigned
int
nb = 0;
60
61
trace
.
beginBlock
(
"Testing dT dim=5 ..."
);
62
63
typedef
SpaceND<5>
TSpace;
64
typedef
TSpace::Point
Point
;
65
typedef
HyperRectDomain<TSpace>
Domain
;
66
TSpace::Integer t[5] = {0,0,0,0,0};
67
Point
a ( t );
68
TSpace::Integer t2[5] = {15,15,15,15,15};
69
Point
b ( t2 );
70
TSpace::Integer t3[5] = {3,3,3,3,3};
71
Point
c ( t3 );
72
Point
d;
73
74
typedef
ImageSelector<Domain, unsigned int>::Type
Image
;
75
Domain
domain
(a,b);
76
Image
image
(
domain
);
77
78
//We create an object image with a single background point (set to 0)
79
for
(
Image::Iterator
it=
image
.begin(),itend=
image
.end(); it!=itend; ++it)
80
*it = 128;
81
image
.
setValue
( c , 0 );
82
83
typedef
SimpleThresholdForegroundPredicate<Image>
Predicate;
84
Predicate aPredicate(
image
,0);
85
86
typedef
ExactPredicateLpSeparableMetric<TSpace, 2>
L2Metric;
87
L2Metric l2;
88
DistanceTransformation<TSpace,Predicate,L2Metric>
dt
(&
domain
,&aPredicate, &l2 );
89
90
//We check the result
91
bool
res=
true
;
92
for
(
Domain::ConstIterator
itDom =
domain
.begin(), itDomend =
domain
.end();
93
itDom != itDomend; ++itDom)
94
{
95
//distance from the point to the seed
96
d = (*itDom) - c;
97
L2Metric::RawValue norm2=0;
98
for
(Point::Iterator itd=d.begin(), itdend=d.end(); itd!=itdend; ++itd)
99
norm2+= (*itd)*(*itd);
100
101
if
(
dt
.metric()->rawDistance( (*itDom),
dt
.getVoronoiSite(*itDom) ) != norm2)
102
{
103
trace
.
error
()<<
"Error at "
<<(*itDom)
104
<<
": expected="
<<norm2<<
" and computed="
105
<<
dt
.metric()->rawDistance( (*itDom),
dt
.getVoronoiSite(*itDom) )
106
<<endl;
107
res=
false
;
108
}
109
}
110
nbok += res ? 1 : 0;
111
nb++;
112
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
113
<<
"true == true"
<< std::endl;
114
trace
.
endBlock
();
115
116
return
nbok == nb;
117
}
118
120
// Standard services - public :
121
122
int
main
(
int
argc,
char
** argv )
123
{
124
trace
.
beginBlock
(
"Testing class DistanceTransformND"
);
125
trace
.
info
() <<
"Args:"
;
126
for
(
int
i = 0; i < argc; ++i )
127
trace
.
info
() <<
" "
<< argv[ i ];
128
trace
.
info
() << endl;
129
130
bool
res =
testDistanceTransformND
();
// && ... other tests
131
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
132
trace
.
endBlock
();
133
return
res ? 0 : 1;
134
}
135
// //
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< Space >::ConstIterator
Iterator ConstIterator
Definition
HyperRectDomain.h:125
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition
ImageContainerBySTLVector.h:264
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition
Image.h:247
DGtal::SpaceND
Definition
SpaceND.h:96
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::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single threshold....
Definition
SimpleThresholdForegroundPredicate.h:66
dt
float dt
Definition
dgtalCalculus-geodesic.cpp:63
DGtal::functors
functors namespace gathers all DGtal functors.
Definition
BasicBoolFunctors.h:49
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::ImageSelector::Type
ImageContainerBySTLVector< Domain, Value > Type
Definition
ImageSelector.h:84
testDistanceTransformND
bool testDistanceTransformND()
Definition
testDistanceTransformationND.cpp:56
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
image
Image image(domain)
tests
geometry
volumes
distance
testDistanceTransformationND.cpp
Generated on
for DGtal by
1.18.0