DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testCombinDSS.cpp
Go to the documentation of this file.
1
16
32
34
#include <iostream>
35
#include <fstream>
36
#include <list>
37
#include <vector>
38
39
#include "DGtal/base/Common.h"
40
#include "DGtal/helpers/StdDefs.h"
41
#include "DGtal/io/boards/Board2D.h"
42
#include "DGtal/geometry/curves/OneBalancedWordComputer.h"
43
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
44
#include "ConfigTest.h"
45
#include "DGtal/geometry/curves/CDynamicBidirectionalSegmentComputer.h"
46
#include "DGtal/geometry/curves/GreedySegmentation.h"
47
49
50
using namespace
std
;
51
using namespace
DGtal
;
52
using namespace
Z2i
;
53
55
// Functions for testing class CombinDSS.
57
58
59
typedef
FreemanChain<int>
Contour
;
60
61
62
66
bool
testOneBalancedWordComputer
()
67
{
68
typedef
string::const_iterator
codeIterator;
69
typedef
OneBalancedWordComputer< list<char>::iterator
,
int
> OneBalancedWordComputer_list;
70
typedef
OneBalancedWordComputer<codeIterator, int>
OneBalancedWordComputer_string;
71
72
BOOST_CONCEPT_ASSERT((
concepts::CDynamicBidirectionalSegmentComputer<OneBalancedWordComputer_list>
));
73
BOOST_CONCEPT_ASSERT((
concepts::CDynamicBidirectionalSegmentComputer<OneBalancedWordComputer_string>
));
74
75
trace
.
beginBlock
(
"Test different initialization methods"
);
76
77
std::string filename = testPath +
"samples/france.fc"
;
78
std::fstream fst;
79
fst.open (filename.c_str(), std::ios::in);
80
Contour
theContour(fst);
81
82
list<char> l;
83
for
(
string::const_iterator
it = theContour.
chain
.begin(); it != theContour.
chain
.end(); ++it )
84
{
85
l.push_back( *it );
86
}
87
88
list<char>::iterator it = l.begin();
89
90
OneBalancedWordComputer_list C1;
91
C1.init( it, theContour.
firstPoint
() );
92
93
OneBalancedWordComputer_list C2;
94
C2.init( C1.begin() );
95
96
OneBalancedWordComputer_string C3;
97
C3.init( theContour );
98
99
OneBalancedWordComputer_string C4;
100
C4.init( theContour.
begin
() );
101
102
int
nbRetract = 0;
103
while
( C3.end() != theContour.
chain
.end() )
104
{
105
bool
b1 = C1.extendFront();
106
bool
b2 = C2.extendFront();
107
bool
b3 = C3.extendFront();
108
bool
b4 = C4.extendFront();
109
if
( b1 && b2 && b3 && b4 )
110
{
111
}
112
else
if
( !b1 && !b2 && !b3 && !b4 )
113
{
114
C1.retractBack();
115
C2.retractBack();
116
C3.retractBack();
117
C4.retractBack();
118
++nbRetract;
119
}
120
else
121
{
122
cout << b1 <<
" "
<< b2 <<
" "
<< b3 <<
" "
<< b4 << endl;
123
cout << C1 << endl;
124
cout << C2 << endl;
125
cout << C3 << endl;
126
cout << C4 << endl;
127
return
false
;
128
}
129
}
130
trace
.
endBlock
();
131
return
(nbRetract == 3485) ;
132
}
133
134
139
bool
CompareToArithmetical
()
140
{
141
typedef
string::const_iterator
codeIterator;
142
typedef
OneBalancedWordComputer<codeIterator, int>
TestedType;
143
typedef
ArithmeticalDSSComputer<Contour::ConstIterator,int,4>
ReferenceType;
144
145
trace
.
beginBlock
(
"Comparing to ArithmeticalDSSComputer"
);
146
147
std::string filename = testPath +
"samples/manche.fc"
;
148
std::fstream fst;
149
fst.open (filename.c_str(), std::ios::in);
150
Contour
theContour(fst);
151
Contour::ConstIterator it = theContour.
begin
();
152
TestedType C;
153
C.init( it );
154
ReferenceType
A
(it);
155
A
.extendFront();
156
bool
res =
true
;
157
while
( C.end() != theContour.
chain
.end() )
158
{
159
bool
a =
A
.extendFront();
160
bool
c = C.extendFront();
161
if
( a ^ c )
162
{
163
res =
false
;
164
cout <<
"Extension test error\n"
;
165
break
;
166
}
167
else
if
( ! a )
168
{
169
A
.retractBack();
170
C.retractBack();
171
}
172
// Compare positions
173
if
( ( C.back() !=
A
.back() ) || ( C.front() !=
A
.front() ) )
174
{
175
res =
false
;
176
cout <<
"Equality test error\n"
;
177
break
;
178
}
179
// Compare arithmetic parameters
180
if
( ( C.getA() !=
A
.
a
() ) || ( C.getB() !=
A
.b() ) ||
181
( C.getMu() !=
A
.mu() ) || ( C.getOmega() !=
A
.omega() ) ||
182
( C.Uf() !=
A
.Uf() ) || ( C.Ul() !=
A
.Ul() ) ||
183
( C.Lf() !=
A
.Lf() ) || ( C.Ll() !=
A
.Ll() )
184
)
185
{
186
cout <<
"Arithmetic parameters error\n"
;
187
cout << C << endl;
188
cout <<
A
<< endl;
189
cout <<
"a() "
<< C.getA() <<
" --- "
<<
A
.
a
() <<
"\n"
;
190
cout <<
"b() "
<< C.getB() <<
" --- "
<<
A
.b() <<
"\n"
;
191
cout <<
"mu() "
<< C.getMu() <<
" --- "
<<
A
.mu() <<
"\n"
;
192
cout <<
"omega()"
<< C.getOmega() <<
" --- "
<<
A
.omega() <<
"\n"
;
193
cout <<
"Uf() "
<< C.Uf() <<
" --- "
<<
A
.Uf() <<
"\n"
;
194
cout <<
"Ul() "
<< C.Ul() <<
" --- "
<<
A
.Ul() <<
"\n"
;
195
cout <<
"Lf() "
<< C.Lf() <<
" --- "
<<
A
.Lf() <<
"\n"
;
196
cout <<
"Ll() "
<< C.Ll() <<
" --- "
<<
A
.Ll() << endl;
197
res =
false
;
198
break
;
199
}
200
}
201
trace
.
endBlock
();
202
return
res;
203
}
204
205
206
207
bool
testInGreedySegmentation
( )
208
{
209
210
typedef
OneBalancedWordComputer<string::const_iterator, int>
combinDSS;
211
typedef
GreedySegmentation<combinDSS>
combinSegmentation;
212
213
std::string filename = testPath +
"samples/BigBall.fc"
;
214
std::fstream fst;
215
fst.open (filename.c_str(), std::ios::in);
216
Contour
theContour(fst);
217
218
trace
.
beginBlock
(
"Test OneBalancedWordComputer in greedy segmentation"
);
219
combinSegmentation combin_dec( theContour.
chain
.begin(), theContour.
chain
.end(), combinDSS() );
220
vector<combinDSS> theCombinDSS;
221
for
( combinSegmentation::SegmentComputerIterator i = combin_dec.begin();
222
i != combin_dec.end(); ++i )
223
{
224
combinDSS c( *i );
225
theCombinDSS.push_back( c );
226
}
227
bool
ok = ( theCombinDSS.size() == 1593 );
228
trace
.
endBlock
();
229
230
return
ok;
231
}
232
233
243
bool
showGreedySegmantation
()
244
{
245
trace
.
beginBlock
(
"Example testCombinDSS-greedy"
);
246
247
typedef
OneBalancedWordComputer<string::const_iterator,int>
combinDSS;
248
typedef
GreedySegmentation<combinDSS>
Decomposition;
249
typedef
StandardDSS4<int>
arithDSS;
250
251
std::stringstream ss(stringstream::in | stringstream::out);
252
ss <<
"31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111"
<< endl;
253
Contour
theContour( ss );
254
255
Decomposition theDecomposition( theContour.
chain
.begin(), theContour.
chain
.end(), combinDSS() );
256
Point
p1( 0, 0 );
257
Point
p2( 31, 31 );
258
Domain
domain
( p1, p2 );
259
Board2D
aBoard;
260
aBoard <<
SetMode
(
domain
.className(),
"Grid"
)
261
<<
domain
262
<<
SetMode
(
"PointVector"
,
"Grid"
)
263
<< theContour;
264
//for each segment
265
Point
p;
266
p[0] = 31;
267
p[1] = 16;
268
for
( Decomposition::SegmentComputerIterator i = theDecomposition.begin();
269
i != theDecomposition.end(); ++i )
270
{
271
combinDSS segment(*i);
272
// set the position of the combinatorilDSS
273
segment.setPosition( p );
274
// Since both DSS overlap on one code, the start point of the next one is
275
// the penultimate point of the current one.
276
p = *( --( --( segment.pointEnd() )));
277
278
// Build an ArithmeticDSS from the OneBalancedWordComputer.
279
arithDSS toShow( *segment.pointBegin(), *segment.pointBegin() );
280
for
(combinDSS::ConstPointIterator it = segment.pointBegin(),
281
itEnd = segment.pointEnd(); it != itEnd; ++it )
282
toShow.extendFront( *it );
283
284
aBoard <<
SetMode
( toShow.className(),
"BoundingBox"
)
285
<<
CustomStyle
( toShow.className()+
"/BoundingBox"
,
new
CustomPenColor
(
Color::Blue
) )
286
<< toShow;
// draw each segment
287
}
288
aBoard.
saveSVG
(
"testCombinDSS-greedy.svg"
);
289
trace
.
endBlock
();
290
return
1;
291
}
292
293
295
// Standard services - public :
296
int
main
(
int
argc,
char
** argv )
297
{
298
trace
.
beginBlock
(
"Testing class CombinDSS"
);
299
trace
.
info
() <<
"Args:"
;
300
for
(
int
i = 0; i < argc; ++i )
301
trace
.
info
() <<
" "
<< argv[ i ];
302
trace
.
info
() << endl;
303
304
bool
res =
testOneBalancedWordComputer
()
305
&&
CompareToArithmetical
()
306
&&
testInGreedySegmentation
()
307
&&
showGreedySegmantation
();
308
309
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
310
trace
.
endBlock
();
311
312
return
res ? 0 : 1;
313
}
314
// //
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition
ArithmeticalDSSComputer.h:87
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::Color::Blue
static const Color Blue
Definition
Color.h:428
DGtal::FreemanChain
Definition
FreemanChain.h:116
DGtal::FreemanChain::firstPoint
Point firstPoint() const
Definition
FreemanChain.h:769
DGtal::FreemanChain::begin
ConstIterator begin() const
DGtal::FreemanChain::chain
std::string chain
Definition
FreemanChain.h:1139
DGtal::GreedySegmentation
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Definition
GreedySegmentation.h:150
DGtal::OneBalancedWordComputer
Aim:
Definition
OneBalancedWordComputer.h:92
DGtal::Point
DGtal::StandardDSS4
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 4-co...
Definition
ArithmeticalDSS.h:831
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::Domain
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1011
string::const_iterator
STL iterator class.
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
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.
A
Definition
testCountedConstPtrOrConstPtr.cpp:43
A::a
int a
Definition
testCountedConstPtrOrConstPtr.cpp:67
A::A
A(int _a)
Definition
testCountedConstPtrOrConstPtr.cpp:44
DGtal::CustomPenColor
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Definition
Board2D.h:313
DGtal::CustomStyle::CustomStyle
CustomStyle(std::string classname, DrawableWithBoard2D *style)
Definition
Board2D.h:224
DGtal::SetMode::SetMode
SetMode(std::string classname, std::string mode)
Definition
Board2D.h:254
DGtal::concepts::CDynamicBidirectionalSegmentComputer
Aim: Defines the concept describing a dynamic and bidirectional segment computer, ie....
Definition
CDynamicBidirectionalSegmentComputer.h:85
showGreedySegmantation
bool showGreedySegmantation()
Definition
testCombinDSS.cpp:243
testOneBalancedWordComputer
bool testOneBalancedWordComputer()
Definition
testCombinDSS.cpp:66
testInGreedySegmentation
bool testInGreedySegmentation()
Definition
testCombinDSS.cpp:207
Contour
FreemanChain< int > Contour
Definition
testCombinDSS.cpp:59
CompareToArithmetical
bool CompareToArithmetical()
Definition
testCombinDSS.cpp:139
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
tests
geometry
curves
testCombinDSS.cpp
Generated on
for DGtal by
1.18.0