DGtal
1.4.0
Loading...
Searching...
No Matches
testReducedMedialAxis.cpp
Go to the documentation of this file.
1
31
#include <iostream>
32
#include <array>
33
34
#include "DGtal/base/Common.h"
35
#include "DGtal/helpers/StdDefs.h"
36
#include "DGtal/geometry/volumes/distance/PowerMap.h"
37
#include "DGtal/geometry/volumes/distance/ReducedMedialAxis.h"
38
#include "DGtal/geometry/volumes/distance/ExactPredicateLpPowerSeparableMetric.h"
39
#include "DGtal/kernel/sets/DigitalSetDomain.h"
40
#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
42
43
using namespace
std
;
44
using namespace
DGtal
;
45
47
// Functions for testing class PowerMap.
49
53
bool
testReducedMedialAxis
( std::array<bool, 2>
const
& aPeriodicity = {{
false
,
false
}} )
54
{
55
unsigned
int
nbok = 0;
56
unsigned
int
nb = 0;
57
58
trace
.
beginBlock
(
"Testing PowerMap2D ..."
);
59
60
Z2i::Domain
domain
(
Z2i::Point
(0,0),
Z2i::Point
(10,10));
61
Z2i::Domain
domainLarge(
Z2i::Point
(0,0),
Z2i::Point
(10,10));
62
63
DigitalSetBySTLSet<Z2i::Domain >
set(
domain
);
64
set.insertNew(
Z2i::Point
(3,3));
65
//set.insertNew(Z2i::Point(3,7));
66
set.insertNew(
Z2i::Point
(7,7));
67
68
using
SetDomain =
DigitalSetDomain< DigitalSetBySTLSet<Z2i::Domain >
>;
69
using
Image
=
ImageContainerBySTLMap< SetDomain , DGtal::int64_t>
;
70
Image
image(
new
SetDomain( set ) );
71
72
//Setting some values
73
image.setValue(
Z2i::Point
(3,3), 9);
74
// image.setValue(Z2i::Point(3,7), 0);
75
image.setValue(
Z2i::Point
(7,7), 16);
76
77
Z2i::L2PowerMetric
l2power;
78
PowerMap<Image, Z2i::L2PowerMetric>
power
(&domainLarge, &image, &l2power, aPeriodicity );
79
80
for
(
unsigned
int
i=0; i<11; i++)
81
{
82
for
(
unsigned
int
j=0; j<11; j++)
83
if
(image.domain().isInside(
Z2i::Point
(i,j)))
84
trace
.
info
()<< image(
Z2i::Point
(i,j))<<
" "
;
85
else
86
trace
.
info
()<<
"0 "
;
87
88
trace
.
info
()<<std::endl;
89
}
90
trace
.
info
()<<std::endl;
91
92
//Power Map
93
for
(
unsigned
int
i=0; i<11; i++)
94
{
95
for
(
unsigned
int
j=0; j<11; j++)
96
trace
.
info
()<<
power
(
Z2i::Point
(i,j))[0]<<
","
<<
power
(
Z2i::Point
(i,j))[1]<<
" "
;
97
trace
.
info
()<<std::endl;
98
}
99
100
trace
.
info
()<<std::endl;
101
//Reconstruction
102
for
(
unsigned
int
i=0; i<11; i++)
103
{
104
for
(
unsigned
int
j=0; j<11; j++)
105
{
106
Z2i::Point
p(i,j);
107
auto
dist = (i-
power
(p)[0])*(i-
power
(p)[0]) +
108
( j-
power
(p)[1])*(j-
power
(p)[1]) - image(
power
.projectPoint(
power
(p)));
109
trace
.
info
()<< dist;
110
}
111
std::cerr<<std::endl;
112
}
113
trace
.
info
()<<std::endl;
114
115
//Medial Axis extraction
116
ReducedMedialAxis<PowerMap<Image, Z2i::L2PowerMetric>
>::Type rdma =
ReducedMedialAxis< PowerMap<Image, Z2i::L2PowerMetric>
>::getReducedMedialAxisFromPowerMap(power);
117
118
//Reconstruction
119
for
(
unsigned
int
i=0; i<11; i++)
120
{
121
for
(
unsigned
int
j=0; j<11; j++)
122
{
123
Z2i::Point
p(i,j);
124
if
(rdma.domain().isInside(p) )
125
trace
.
info
()<< rdma(p);
126
else
127
trace
.
info
()<<
" - "
;
128
129
}
130
std::cerr<<std::endl;
131
}
132
trace
.
info
()<<std::endl;
133
134
135
++nbok;
136
nb++;
137
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
138
<<
"true == true"
<< std::endl;
139
trace
.
endBlock
();
140
141
bool
isEqual
=
true
;
142
for
(
auto
const
& pt :
domain
)
143
{
144
const
Image::Value
a = image.domain().isInside(pt) ? image(pt) : 0;
145
const
Image::Value
b = rdma.domain().isInside(pt) ? rdma(pt) : 0;
146
if
( a != b )
147
{
148
isEqual
=
false
;
149
break
;
150
}
151
}
152
153
trace
.
info
() <<
"Equality ? "
<<
isEqual
<< std::endl;
154
155
return
nbok == nb;
156
}
157
159
// Standard services - public :
160
161
int
main
(
int
argc,
char
** argv )
162
{
163
trace
.
beginBlock
(
"Testing class ReducedMedialAxis"
);
164
trace
.
info
() <<
"Args:"
;
165
for
(
int
i = 0; i < argc; ++i )
166
trace
.
info
() <<
" "
<< argv[ i ];
167
trace
.
info
() << endl;
168
169
bool
res =
170
testReducedMedialAxis
()
171
&&
testReducedMedialAxis
( {{
true
,
false
}} )
172
&&
testReducedMedialAxis
( {{
false
,
true
}} )
173
&&
testReducedMedialAxis
( {{
true
,
true
}} )
174
;
// && ... other tests
175
176
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
177
trace
.
endBlock
();
178
return
res ? 0 : 1;
179
}
180
// //
DGtal::DigitalSetBySTLSet
Aim: A container class for storing sets of digital points within some given domain.
Definition
DigitalSetBySTLSet.h:85
DGtal::DigitalSetDomain
Aim: Constructs a domain limited to the given digital set.
Definition
DigitalSetDomain.h:60
DGtal::ExactPredicateLpPowerSeparableMetric
Aim: implements weighted separable l_p metrics with exact predicates.
Definition
ExactPredicateLpPowerSeparableMetric.h:88
DGtal::HyperRectDomain< Space >
DGtal::ImageContainerBySTLMap
Definition
ImageContainerBySTLMap.h:98
DGtal::ImageContainerBySTLVector< Domain, Value >::Value
Value Value
Definition
ImageContainerBySTLVector.h:153
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition
Image.h:70
DGtal::PointVector< dim, Integer >
DGtal::PowerMap
Aim: Implementation of the linear in time Power map construction.
Definition
PowerMap.h:111
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::functions::power
T power(const T &aVal, const unsigned int exponent)
Definition
BasicMathFunctions.h:73
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
Definition
Common.h:153
std
STL namespace.
DGtal::ReducedMedialAxis
Aim: Implementation of the separable medial axis extraction.
Definition
ReducedMedialAxis.h:98
main
int main()
Definition
testBits.cpp:56
isEqual
bool isEqual(Container1 &c1, Container2 &c2)
Definition
testIndexedListWithBlocks.cpp:45
domain
Domain domain
Definition
testProjection.cpp:88
testReducedMedialAxis
bool testReducedMedialAxis(std::array< bool, 2 > const &aPeriodicity={{ false, false }})
Definition
testReducedMedialAxis.cpp:53
tests
geometry
volumes
distance
testReducedMedialAxis.cpp
Generated on Mon Jun 10 2024 17:36:11 for DGtal by
1.11.0