DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testMetricBalls.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/ExactPredicateLpSeparableMetric.h"
35
#include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
36
#include "DGtal/io/boards/Board2D.h"
37
#include "DGtal/kernel/BasicPointPredicates.h"
38
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
39
#include "DGtal/io/colormaps/HueShadeColorMap.h"
41
42
using namespace
std
;
43
using namespace
DGtal
;
44
using namespace
DGtal::functors
;
45
47
// Functions for testing class MetricBalls.
49
50
51
template
<
int
norm>
52
bool
testExactMetricBalls
()
53
{
54
unsigned
int
nbok = 0;
55
unsigned
int
nb = 0;
56
57
Z2i::Domain
domain
(
Z2i::Point
(0,0),
Z2i::Point
(64,64));
58
typedef
ExactPredicateLpSeparableMetric<Z2i::Space, norm>
Metric;
59
Z2i::DigitalSet
set(
domain
);
60
61
set.insertNew(
Z2i::Point
(32,32));
62
typedef
NotPointPredicate< Z2i::DigitalSet >
NegPred;
63
// SetPredicate<Z2i::DigitalSet> setpred(set);
64
NegPred predicate( set );
65
66
typedef
DistanceTransformation< Z2i::Space, NegPred, Metric>
DT;
67
Metric metric;
68
DT
dt
( &
domain
, &predicate, &metric);
69
70
71
Board2D
board;
72
typedef
HueShadeColorMap<typename DT::Value,2>
Hue;
73
board.
setUnit
(
LibBoard::Board::UCentimeter
);
74
Display2DFactory::drawImage<Hue>
(board,
dt
,
75
0.0,
76
32*sqrt(2)/2.0);
77
78
std::string title =
"image-ball-"
+ boost::lexical_cast<string>( norm )+
".png"
;
79
#ifdef DGTAL_WITH_CAIRO
80
board.
saveCairo
(title.c_str(),
Board2D::CairoPNG
);
81
#endif
82
return
nbok == nb;
83
}
84
85
bool
testInexactMetricBalls
(
double
norm)
86
{
87
unsigned
int
nbok = 0;
88
unsigned
int
nb = 0;
89
90
Z2i::Domain
domain
(
Z2i::Point
(0,0),
Z2i::Point
(64,64));
91
typedef
InexactPredicateLpSeparableMetric<Z2i::Space>
Metric;
92
Z2i::DigitalSet
set(
domain
);
93
94
set.insertNew(
Z2i::Point
(32,32));
95
typedef
NotPointPredicate< Z2i::DigitalSet >
NegPred;
96
// SetPredicate<Z2i::DigitalSet> setpred(set);
97
NegPred predicate( set );
98
99
typedef
DistanceTransformation< Z2i::Space, NegPred, Metric>
DT;
100
Metric metric(norm);
101
DT
dt
( &
domain
, &predicate, &metric);
102
103
104
Board2D
board;
105
typedef
HueShadeColorMap< DT::Value,2>
Hue;
106
board.
setUnit
(
LibBoard::Board::UCentimeter
);
107
Display2DFactory::drawImage<Hue>
(board,
dt
,
108
0.0,
109
32*sqrt(2)/2.0);
110
111
std::string title =
"image-ball-"
+ boost::lexical_cast<string>( norm )+
".png"
;
112
#ifdef DGTAL_WITH_CAIRO
113
board.
saveCairo
(title.c_str(),
Board2D::CairoPNG
);
114
#endif
115
return
nbok == nb;
116
}
117
119
// Standard services - public :
120
121
int
main
(
int
argc,
char
** argv )
122
{
123
trace
.
beginBlock
(
"Testing class MetricBalls"
);
124
trace
.
info
() <<
"Args:"
;
125
for
(
int
i = 0; i < argc; ++i )
126
trace
.
info
() <<
" "
<< argv[ i ];
127
trace
.
info
() << endl;
128
129
bool
res =
testExactMetricBalls<2>
()
130
&&
testExactMetricBalls<1>
()
131
&&
testExactMetricBalls<4>
()
132
&&
testExactMetricBalls<8>
()
133
&&
testInexactMetricBalls
(1.4)
134
&&
testInexactMetricBalls
(43.1)
135
&&
testInexactMetricBalls
(0.8)
136
;
// && ... other tests
137
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
138
trace
.
endBlock
();
139
return
res ? 0 : 1;
140
}
141
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
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::HueShadeColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
HueShadeColorMap.h:91
DGtal::InexactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with approximated predicates.
Definition
InexactPredicateLpSeparableMetric.h:82
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()
LibBoard::Board::UCentimeter
@ UCentimeter
Definition
Board.h:43
LibBoard::Board::CairoPNG
@ CairoPNG
Definition
Board.h:40
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition
Board.cpp:239
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1138
dt
float dt
Definition
dgtalCalculus-geodesic.cpp:63
DGtal::Z2i::Point
Space::Point Point
Definition
StdDefs.h:95
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition
StdDefs.h:100
DGtal::Z2i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:99
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::Display2DFactory::drawImage
static void drawImage(DGtal::Board2D &board, const Image &i, const typename Image::Value &minV, const typename Image::Value &maxV)
DGtal::functors::NotPointPredicate
Aim: The predicate returns true when the point predicate given at construction return false....
Definition
BasicPointPredicates.h:208
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testInexactMetricBalls
bool testInexactMetricBalls(double norm)
Definition
testMetricBalls.cpp:85
testExactMetricBalls
bool testExactMetricBalls()
Definition
testMetricBalls.cpp:52
domain
Domain domain
Definition
testProjection.cpp:88
tests
geometry
volumes
distance
testMetricBalls.cpp
Generated on
for DGtal by
1.18.0