DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testStabbingLineComputer.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/kernel/PointVector.h"
34
#include "DGtal/topology/KhalimskySpaceND.h"
35
#include "DGtal/geometry/curves/GridCurve.h"
36
37
#include "DGtal/geometry/curves/CBidirectionalSegmentComputer.h"
38
39
#include "DGtal/geometry/curves/StabbingLineComputer.h"
40
41
#include "DGtal/geometry/curves/GreedySegmentation.h"
42
#include "DGtal/geometry/curves/SaturatedSegmentation.h"
43
44
#include "DGtal/io/boards/Board2D.h"
45
#include "DGtal/io/boards/CDrawableWithBoard2D.h"
46
47
#include "ConfigTest.h"
48
50
51
using namespace
std
;
52
using namespace
DGtal
;
53
55
// Functions for testing class StabbingLineComputer.
57
60
template
<
typename
TCurve>
61
bool
testStabbingLineComputer
(
const
TCurve& curve)
62
{
63
64
typedef
typename
TCurve::IncidentPointsRange
Range
;
//range
65
typedef
typename
Range::ConstIterator
ConstIterator
;
//iterator
66
typedef
typename
Range::ConstReverseIterator
ConstReverseIterator;
//reverse iterator
67
68
unsigned
int
nbok = 0;
69
unsigned
int
nb = 0;
70
71
trace
.
beginBlock
(
"Constructors, copy, assignment"
);
72
{
73
Range
r = curve.getIncidentPointsRange();
//range
74
75
StabbingLineComputer<ConstIterator>
s1, s2, s3;
76
s2.
init
(r.
begin
());
77
s3.
init
(++r.
begin
());
78
StabbingLineComputer<ConstIterator>
s4(s2);
79
StabbingLineComputer<ConstIterator>
s5(s3);
80
s3 = s1;
81
82
trace
.
info
() << s1.
isValid
() << s1 << endl;
83
trace
.
info
() << s2.
isValid
() << s2 << endl;
84
trace
.
info
() << s3.
isValid
() << s3 << endl;
85
trace
.
info
() << s4.
isValid
() << s4 << endl;
86
trace
.
info
() << s5.
isValid
() << s5 << endl;
87
88
bool
myFlag = (!s1.
isValid
())&&(!s3.
isValid
())
89
&&(s2.
isValid
())&&(s4.
isValid
())&&(s5.
isValid
())
90
&&(s2 == s4)&&(s3 != s5)&&(s1 == s3)&&(s2 != s5);
91
92
nbok += myFlag ? 1 : 0;
93
nb++;
94
}
95
trace
.
endBlock
();
96
97
trace
.
beginBlock
(
"Extension operations"
);
98
{
99
Range
r = curve.getIncidentPointsRange();
//range
100
101
StabbingLineComputer<ConstIterator>
s, t;
102
103
trace
.
info
() <<
"forward extension "
<< endl;
104
ConstIterator
itBegin (r.
begin
());
105
ConstIterator
itEnd (r.
end
());
106
s.
init
( itBegin+1 );
107
while
( (s.
end
() != itEnd) && (s.
isExtendableFront
()) && (s.
extendFront
()) ) {}
108
trace
.
info
() << s << endl;
109
double
a, b, c;
110
s.
getParameters
(a,b,c);
111
trace
.
info
() << a <<
" "
<< b <<
" "
<< c << endl;
112
113
t.
init
( (itBegin + (itEnd - itBegin)/2) );
114
while
( (t.
end
() != itEnd) && (t.
extendFront
())
115
&& (t.
begin
() != itBegin) && (t.
extendBack
()) ) {}
116
trace
.
info
() << t << endl;
117
118
trace
.
info
() <<
"backward extension "
<< endl;
119
typename
StabbingLineComputer<ConstIterator>::Reverse
rs = s.
getReverse
();
120
ConstReverseIterator ritBegin (t.
end
());
121
ConstReverseIterator ritEnd (r.
rend
());
122
rs.
init
( ritBegin );
123
while
( (rs.
end
() != ritEnd) && (rs.
isExtendableFront
()) && (rs.
extendFront
()) ) {}
124
trace
.
info
() << rs << endl;
125
double
ap, bp, cp;
126
rs.
getParameters
(ap,bp,cp);
127
trace
.
info
() << ap <<
" "
<< bp <<
" "
<< cp << endl;
128
129
typename
StabbingLineComputer<ConstIterator>::Reverse
rt = t.
getReverse
();
130
rt.
init
( (ritBegin + (ritEnd - ritBegin)/2) );
131
while
( (rt.
begin
() != ritBegin) && (rt.
extendBack
())
132
&& (rt.
end
() != ritEnd) && (rt.
extendFront
()) ) {}
133
trace
.
info
() << rt << endl;
134
135
trace
.
info
() <<
"comparison... "
<< endl;
136
bool
myFlag = ( (s == t)&&(rs == rt) )
137
&& ( s.
Uf
() == rs.
Uf
() )
138
&& ( s.
Ul
() == rs.
Ul
() )
139
&& ( s.
Lf
() == rs.
Lf
() )
140
&& ( s.
Ll
() == rs.
Ll
() )
141
&& (a == ap)
142
&& (b == bp)
143
&& (c == cp)
144
;
145
146
nbok += myFlag ? 1 : 0;
147
nb++;
148
}
149
trace
.
endBlock
();
150
151
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
152
return
nbok == nb;
153
}
154
155
/*
156
* simple drawing
157
*/
158
template
<
typename
TCurve>
159
bool
drawingTestStabbingLineComputer
(
const
TCurve& curve)
160
{
161
162
typedef
typename
TCurve::IncidentPointsRange
Range
;
//range
163
typedef
typename
Range::ConstIterator
ConstIterator
;
//iterator
164
165
Range
r = curve.getIncidentPointsRange();
//range
166
167
StabbingLineComputer<ConstIterator>
s;
168
ConstIterator
itEnd (r.
end
());
169
s.
init
( r.
begin
() );
170
while
( (s.
end
() != itEnd) && (s.
extendFront
()) ) {}
171
172
double
a, b, c;
173
s.
getParameters
(a,b,c);
174
175
Board2D
board;
176
board << r << s;
177
board.
saveEPS
(
"StabbingLineComputerdrawingTest.eps"
);
178
return
true
;
179
}
180
181
void
testStabbingLineComputerConceptChecking
()
182
{
183
typedef
std::pair<PointVector<2,int>,
PointVector<2,int>
> Pair;
184
typedef
std::vector<Pair>::const_iterator
ConstIterator
;
185
typedef
StabbingLineComputer<ConstIterator>
GeomDSS;
186
BOOST_CONCEPT_ASSERT((
concepts::CDrawableWithBoard2D<GeomDSS>
));
187
BOOST_CONCEPT_ASSERT((
concepts::CBidirectionalSegmentComputer<GeomDSS>
));
188
}
189
190
template
<
typename
TCurve>
191
bool
testSegmentation
(
const
TCurve& curve)
192
{
193
194
typedef
typename
TCurve::IncidentPointsRange
Range
;
//range
195
Range
r = curve.getIncidentPointsRange();
//range
196
197
typedef
typename
Range::ConstIterator
ConstIterator
;
//iterator
198
typedef
StabbingLineComputer<ConstIterator>
SegmentComputer
;
//segment computer
199
200
unsigned
int
nbok = 0;
201
unsigned
int
nb = 0;
202
203
204
trace
.
beginBlock
(
"Greedy segmentation"
);
205
{
206
typedef
GreedySegmentation<SegmentComputer>
Segmentation
;
207
Segmentation
theSegmentation( r.
begin
(), r.
end
(),
SegmentComputer
() );
208
209
Board2D
board;
210
board << r;
211
212
typename
Segmentation::SegmentComputerIterator it = theSegmentation.
begin
();
213
typename
Segmentation::SegmentComputerIterator itEnd = theSegmentation.
end
();
214
unsigned
int
n = 0;
215
unsigned
int
suml = 0;
216
for
( ; it != itEnd; ++it, ++n) {
217
board << (*it);
218
for
(
ConstIterator
i = it->begin(); i != it->end(); ++i)
219
suml += 1;
220
}
221
222
board.
saveEPS
(
"StabbingLineComputerGreedySegmentationTest.eps"
,
Board2D::BoundingBox
, 5000 );
223
224
trace
.
info
() << r.size() <<
";"
<< n <<
";"
<< suml << endl;
225
//comparison with the results gave by another program
226
nbok += ((r.size()==85)&&(n==10)&&(suml==94)) ? 1 : 0;
227
nb++;
228
}
229
trace
.
endBlock
();
230
231
trace
.
beginBlock
(
"Saturated segmentation"
);
232
{
233
typedef
SaturatedSegmentation<SegmentComputer>
Segmentation
;
234
Segmentation
theSegmentation( r.
begin
(), r.
end
(),
SegmentComputer
() );
235
236
Board2D
board;
237
board << r;
238
239
typename
Segmentation::SegmentComputerIterator it = theSegmentation.
begin
();
240
typename
Segmentation::SegmentComputerIterator itEnd = theSegmentation.
end
();
241
unsigned
int
n = 0;
242
unsigned
int
suml = 0;
243
for
( ; it != itEnd; ++it, ++n) {
244
board << (*it);
245
for
(
ConstIterator
i = it->begin(); i != it->end(); ++i)
246
suml += 1;
247
}
248
249
board.
saveEPS
(
"StabbingLineComputerSaturatedSegmentationTest.eps"
,
Board2D::BoundingBox
, 5000 );
250
251
trace
.
info
() << r.size() <<
";"
<< n <<
";"
<< suml << endl;
252
//comparison with the results gave by another program
253
nbok += ((r.size()==85)&&(n==25)&&(suml==255)) ? 1 : 0;
254
nb++;
255
}
256
trace
.
endBlock
();
257
258
259
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
260
return
(nbok == nb);
261
}
262
263
// Standard services - public :
264
265
int
main
(
int
argc,
char
** argv )
266
{
267
trace
.
beginBlock
(
"Testing class StabbingLineComputer"
);
268
trace
.
info
() <<
"Args:"
;
269
for
(
int
i = 0; i < argc; ++i )
270
trace
.
info
() <<
" "
<< argv[ i ];
271
trace
.
info
() << endl;
272
273
bool
res;
274
275
{
//concept checking
276
testStabbingLineComputerConceptChecking
();
277
}
278
279
{
//basic operations
280
std::string filename = testPath +
"samples/DSS.dat"
;
281
ifstream instream;
// input stream
282
instream.open (filename.c_str(), ifstream::in);
283
284
typedef
KhalimskySpaceND<2,int>
KSpace
;
285
GridCurve<KSpace>
c;
//grid curve
286
c.
initFromVectorStream
(instream);
287
288
res =
testStabbingLineComputer
(c)
289
&&
drawingTestStabbingLineComputer
(c);
290
}
291
292
{
//segmentations
293
std::string filename = testPath +
"samples/sinus2D4.dat"
;
294
ifstream instream;
// input stream
295
instream.open (filename.c_str(), ifstream::in);
296
297
typedef
KhalimskySpaceND<2,int>
KSpace
;
298
GridCurve<KSpace>
c;
//grid curve
299
c.
initFromVectorStream
(instream);
300
301
res = res &&
testSegmentation
(c);
302
}
303
304
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
305
trace
.
endBlock
();
306
return
res ? 0 : 1;
307
}
308
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::GreedySegmentation
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Definition
GreedySegmentation.h:150
DGtal::GridCurve
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition
GridCurve.h:173
DGtal::GridCurve::initFromVectorStream
bool initFromVectorStream(std::istream &in)
DGtal::ConstIterator
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition
KhalimskySpaceND.h:394
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition
PointVector.h:593
DGtal::SaturatedSegmentation
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
Definition
SaturatedSegmentation.h:154
DGtal::SaturatedSegmentation::end
SaturatedSegmentation::SegmentComputerIterator end() const
DGtal::SaturatedSegmentation::begin
SaturatedSegmentation::SegmentComputerIterator begin() const
DGtal::SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctorFromPoint< Self > >::ConstReverseIterator
boost::reverse_iterator< ConstIterator > ConstReverseIterator
Definition
SimpleRandomAccessRangeFromPoint.h:91
DGtal::SimpleRandomAccessRangeFromPoint::begin
Iterator begin()
Definition
SimpleRandomAccessRangeFromPoint.h:204
DGtal::SimpleRandomAccessRangeFromPoint::rend
ReverseIterator rend()
Definition
SimpleRandomAccessRangeFromPoint.h:320
DGtal::SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctorFromPoint< Self > >::ConstIterator
ConstIterator ConstIterator
Definition
SimpleRandomAccessRangeFromPoint.h:88
DGtal::SimpleRandomAccessRangeFromPoint::end
Iterator end()
Definition
SimpleRandomAccessRangeFromPoint.h:244
DGtal::StabbingLineComputer
Aim: On-line recognition of a digital straight segment (DSS) defined as a sequence of connected grid ...
Definition
StabbingLineComputer.h:93
DGtal::StabbingLineComputer::extendFront
bool extendFront()
DGtal::StabbingLineComputer::isExtendableFront
bool isExtendableFront()
DGtal::StabbingLineComputer::getReverse
Reverse getReverse() const
DGtal::StabbingLineComputer::Ul
Point Ul() const
DGtal::StabbingLineComputer::end
ConstIterator end() const
DGtal::StabbingLineComputer::begin
ConstIterator begin() const
DGtal::StabbingLineComputer::Ll
Point Ll() const
DGtal::StabbingLineComputer::Reverse
StabbingLineComputer< ReverseIterator< ConstIterator > > Reverse
Definition
StabbingLineComputer.h:100
DGtal::StabbingLineComputer::Lf
Point Lf() const
DGtal::StabbingLineComputer::init
void init(const ConstIterator &anIt)
DGtal::StabbingLineComputer::isValid
bool isValid() const
DGtal::StabbingLineComputer::extendBack
bool extendBack()
DGtal::StabbingLineComputer::Uf
Point Uf() const
DGtal::StabbingLineComputer::getParameters
void getParameters(double &alpha, double &beta, double &gamma) const
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::BoundingBox
@ BoundingBox
Definition
Board.h:42
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:804
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::concepts::CBidirectionalSegmentComputer
Aim: Defines the concept describing a bidirectional segment computer, ie. a model of concepts::CSegme...
Definition
CBidirectionalSegmentComputer.h:91
DGtal::concepts::CDrawableWithBoard2D
Aim: The concept CDrawableWithBoard2D specifies what are the classes that admit an export with Board2...
Definition
CDrawableWithBoard2D.h:105
testSegmentation
bool testSegmentation()
Definition
testArithDSS3d.cpp:114
SegmentComputer
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
Definition
testArithmeticalDSSComputerOnSurfels.cpp:55
Segmentation
SaturatedSegmentation< SegmentComputer > Segmentation
Definition
testArithmeticalDSSComputerOnSurfels.cpp:56
KSpace
Z3i::KSpace KSpace
Definition
testArithmeticalDSSComputerOnSurfels.cpp:48
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
Range
Image::Range Range
Definition
testSimpleRandomAccessRangeFromPoint.cpp:46
testStabbingLineComputerConceptChecking
void testStabbingLineComputerConceptChecking()
Definition
testStabbingLineComputer.cpp:181
drawingTestStabbingLineComputer
bool drawingTestStabbingLineComputer(const TCurve &curve)
Definition
testStabbingLineComputer.cpp:159
testStabbingLineComputer
bool testStabbingLineComputer(const TCurve &curve)
Definition
testStabbingLineComputer.cpp:61
tests
geometry
curves
testStabbingLineComputer.cpp
Generated on
for DGtal by
1.18.0