DGtal
1.3.beta
tests
geometry
volumes
distance
testDistanceTransformationND.cpp
Go to the documentation of this file.
1
30
#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 signle 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.getVoronoiVector(*itDom) ) != norm2)
102
{
103
trace
.
error
()<<
"Error at "
<<(*itDom)
104
<<
": expected="
<<norm2<<
" and computed="
105
<<dt.metric()->rawDistance( (*itDom), dt.getVoronoiVector(*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
// //
image
Image image(domain)
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition:
HyperRectDomain.h:99
DGtal::Trace::endBlock
double endBlock()
DGtal::ImageContainerBySTLVector
Definition:
ImageContainerBySTLVector.h:126
DGtal::functors
functors namespace gathers all DGtal functors.
Definition:
BasicBoolFunctors.h:49
DGtal::Trace::error
std::ostream & error()
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition:
Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::SpaceND
Definition:
SpaceND.h:95
DGtal::Trace::info
std::ostream & info()
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition:
testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Domain
HyperRectDomain< Space > Domain
Definition:
testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition:
ImageContainerBySTLVector.h:264
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition:
HyperRectDomain.h:201
Integer
Point::Coordinate Integer
Definition:
examplePlaneProbingParallelepipedEstimator.cpp:44
testDistanceTransformND
bool testDistanceTransformND()
Definition:
testDistanceTransformationND.cpp:56
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition:
Image.h:69
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition:
HyperRectDomain_Iterator.h:142
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition:
ExactPredicateLpSeparableMetric.h:87
domain
Domain domain
Definition:
testProjection.cpp:88
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition:
DistanceTransformation.h:98
main
int main(int argc, char **argv)
Definition:
testDistanceTransformationND.cpp:122
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition:
HyperRectDomain.h:176
Point
MyPointD Point
Definition:
testClone2.cpp:383
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
Definition:
SimpleThresholdForegroundPredicate.h:65
Generated on Sun Jul 31 2022 06:47:20 for DGtal by
1.8.17