DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testTiledImage.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
35
#include "DGtal/images/ImageContainerBySTLVector.h"
36
#include "DGtal/images/ImageFactoryFromImage.h"
37
#include "DGtal/images/TiledImage.h"
38
39
#include "ConfigTest.h"
41
42
using namespace
std
;
43
using namespace
DGtal
;
44
46
// Functions for testing class TiledImage.
48
bool
testSimple
()
49
{
50
unsigned
int
nbok = 0;
51
unsigned
int
nb = 0;
52
53
trace
.
beginBlock
(
"Testing simple TiledImage"
);
54
55
typedef
ImageContainerBySTLVector<Z2i::Domain, int>
VImage;
56
VImage
image
(
Z2i::Domain
(
Z2i::Point
(1,1),
Z2i::Point
(16,16)));
57
58
int
i = 1;
59
for
(VImage::Iterator it =
image
.begin(); it !=
image
.end(); ++it)
60
*it = i++;
61
62
trace
.
info
() <<
"ORIGINAL image: "
<<
image
<< endl;
63
64
typedef
ImageFactoryFromImage<VImage>
MyImageFactoryFromImage;
65
typedef
MyImageFactoryFromImage::OutputImage OutputImage;
66
MyImageFactoryFromImage imageFactoryFromImage(
image
);
67
68
typedef
ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromImage>
MyImageCacheReadPolicyFIFO;
69
typedef
ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage>
MyImageCacheWritePolicyWT;
70
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
71
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
72
73
typedef
TiledImage<VImage, MyImageFactoryFromImage, MyImageCacheReadPolicyFIFO, MyImageCacheWritePolicyWT>
MyTiledImage;
74
BOOST_CONCEPT_ASSERT((
concepts::CImage< MyTiledImage >
));
75
MyTiledImage tiledImage(imageFactoryFromImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWT, 4);
76
77
typedef
MyTiledImage::OutputImage OutputImage;
78
OutputImage::Value aValue;
79
80
trace
.
info
() <<
"Read value for Point 4,2: "
<< tiledImage(
Z2i::Point
(4,2)) << endl;
81
nbok += (tiledImage(
Z2i::Point
(4,2)) == 20) ? 1 : 0;
82
nb++;
83
84
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
85
86
trace
.
info
() <<
"Read value for Point 10,6: "
<< tiledImage(
Z2i::Point
(10,6)) << endl;
87
nbok += (tiledImage(
Z2i::Point
(10,6)) == 90) ? 1 : 0;
88
nb++;
89
90
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
91
92
aValue = 1; tiledImage.setValue(
Z2i::Point
(11,7), aValue);
93
trace
.
info
() <<
"Write value for Point 11,7: "
<< aValue << endl;
94
nbok += (tiledImage(
Z2i::Point
(11,7)) == 1) ? 1 : 0;
95
nb++;
96
97
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
98
99
trace
.
info
() <<
"Read value for Point 2,3: "
<< tiledImage(
Z2i::Point
(2,3)) << endl;
100
nbok += (tiledImage(
Z2i::Point
(2,3)) == 34) ? 1 : 0;
101
nb++;
102
103
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
104
105
trace
.
info
() <<
"Read value for Point 16,1: "
<< tiledImage(
Z2i::Point
(16,1)) << endl;
106
nbok += (tiledImage(
Z2i::Point
(16,1)) == 16) ? 1 : 0;
107
nb++;
108
109
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
110
111
aValue = 128; tiledImage.setValue(
Z2i::Point
(16,1), aValue);
112
trace
.
info
() <<
"Write value for Point 16,1: "
<< aValue << endl;
113
nbok += (tiledImage(
Z2i::Point
(16,1)) == 128) ? 1 : 0;
114
nb++;
115
116
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
117
118
trace
.
info
() <<
" Point 16,1 on ORIGINAL image, value: "
<<
image
(
Z2i::Point
(16,1)) << endl;
119
nbok += (
image
(
Z2i::Point
(16,1)) == 128) ? 1 : 0;
120
nb++;
121
122
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
123
124
trace
.
endBlock
();
125
126
return
nbok == nb;
127
}
128
129
bool
test3d
()
130
{
131
unsigned
int
nbok = 0;
132
unsigned
int
nb = 0;
133
134
trace
.
beginBlock
(
"Testing 3d TiledImage"
);
135
136
typedef
ImageContainerBySTLVector<Z3i::Domain, int>
VImage;
137
VImage
image
(
Z3i::Domain
(
Z3i::Point
(1,1,1),
Z3i::Point
(4,4,4)));
138
139
int
i = 1;
140
for
(VImage::Iterator it =
image
.begin(); it !=
image
.end(); ++it)
141
*it = i++;
142
143
trace
.
info
() <<
"ORIGINAL image: "
<<
image
<< endl;
144
145
typedef
ImageFactoryFromImage<VImage>
MyImageFactoryFromImage;
146
typedef
MyImageFactoryFromImage::OutputImage OutputImage;
147
MyImageFactoryFromImage imageFactoryFromImage(
image
);
148
149
typedef
ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromImage>
MyImageCacheReadPolicyFIFO;
150
typedef
ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage>
MyImageCacheWritePolicyWT;
151
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
152
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
153
154
typedef
TiledImage<VImage, MyImageFactoryFromImage, MyImageCacheReadPolicyFIFO, MyImageCacheWritePolicyWT>
MyTiledImage;
155
BOOST_CONCEPT_ASSERT((
concepts::CImage< MyTiledImage >
));
156
MyTiledImage tiledImage(imageFactoryFromImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWT, 4);
157
158
typedef
MyTiledImage::OutputImage OutputImage;
159
160
trace
.
info
() <<
"Read value for Point 1,1,1: "
<< tiledImage(
Z3i::Point
(1,1,1)) << endl;
161
nbok += (tiledImage(
Z3i::Point
(1,1,1)) == 1) ? 1 : 0;
162
nb++;
163
164
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
165
166
trace
.
info
() <<
"Read value for Point 4,4,4: "
<< tiledImage(
Z3i::Point
(4,4,4)) << endl;
167
nbok += (tiledImage(
Z3i::Point
(4,4,4)) == 64) ? 1 : 0;
168
nb++;
169
170
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
171
172
trace
.
info
() <<
"Read value for Point 4,3,2: "
<< tiledImage(
Z3i::Point
(4,3,2)) << endl;
173
nbok += (tiledImage(
Z3i::Point
(4,3,2)) == 28) ? 1 : 0;
174
nb++;
175
176
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
177
178
trace
.
endBlock
();
179
180
return
nbok == nb;
181
}
182
183
bool
testIterators
()
184
{
185
unsigned
int
nbok = 0;
186
unsigned
int
nb = 0;
187
188
trace
.
beginBlock
(
"Testing iterators with TiledImage"
);
189
190
typedef
ImageContainerBySTLVector<Z2i::Domain, int>
VImage;
191
VImage
image
(
Z2i::Domain
(
Z2i::Point
(1,1),
Z2i::Point
(10,10)));
192
for
(VImage::Iterator it =
image
.begin(); it !=
image
.end(); ++it)
193
*it = 10;
194
trace
.
info
() <<
"ORIGINAL image: "
<<
image
<< endl;
195
typedef
ImageFactoryFromImage<VImage>
MyImageFactoryFromImage;
196
typedef
MyImageFactoryFromImage::OutputImage OutputImage;
197
MyImageFactoryFromImage imageFactoryFromImage(
image
);
198
199
typedef
ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromImage>
MyImageCacheReadPolicyFIFO;
200
typedef
ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage>
MyImageCacheWritePolicyWT;
201
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
202
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
203
204
typedef
TiledImage<VImage, MyImageFactoryFromImage, MyImageCacheReadPolicyFIFO, MyImageCacheWritePolicyWT>
MyTiledImage;
205
BOOST_CONCEPT_ASSERT((
concepts::CImage< MyTiledImage >
));
206
MyTiledImage tiledImage(imageFactoryFromImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWT, 4);
207
208
tiledImage.setValue(
Z2i::Point
(5,5), 42 );
209
tiledImage.setValue(
Z2i::Point
(1,1), 1 );
210
211
// typedefs
212
typedef
MyTiledImage::ConstIterator
ConstIterator
;
213
typedef
MyTiledImage::OutputIterator OutputIterator;
214
215
ConstIterator
itbegin = tiledImage.constRange().begin();
216
trace
.
info
() <<
"Value at range begin (1) = "
<< *itbegin << std::endl;
217
nbok += (*itbegin == 1) ? 1 : 0; nb++;
218
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
219
220
ConstIterator
itbegin2 = tiledImage.constRange().begin(
Z2i::Point
(5,5));
221
trace
.
info
() <<
"Value at range begin from point (42) = "
<< *itbegin2 << std::endl;
222
nbok += (*itbegin2 == 42) ? 1 : 0; nb++;
223
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
224
225
OutputIterator itbegino = tiledImage.range().begin();
226
trace
.
info
() <<
"Value at range begin (1) = "
<< *itbegino << std::endl;
227
nbok += (*itbegino == 1) ? 1 : 0; nb++;
228
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
229
230
*itbegino = 5;
231
trace
.
info
() <<
"Value at range begin after writing (5) = "
<< *itbegino << std::endl;
232
nbok += (*itbegino == 5) ? 1 : 0; nb++;
233
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
234
235
trace
.
endBlock
();
236
237
return
nbok == nb;
238
}
239
240
bool
test_range_constRange
()
241
{
242
unsigned
int
nbok = 0;
243
unsigned
int
nb = 0;
244
245
trace
.
beginBlock
(
"Testing range/constRange with TiledImage"
);
246
247
typedef
ImageContainerBySTLVector<Z2i::Domain, int>
VImage;
248
249
VImage
image
(
Z2i::Domain
(
Z2i::Point
(1,1),
Z2i::Point
(10,10)));
250
for
(VImage::Iterator it =
image
.begin(); it !=
image
.end(); ++it)
251
*it = 10;
252
253
trace
.
info
() <<
"ORIGINAL image: "
<<
image
<< endl;
254
255
typedef
ImageFactoryFromImage<VImage>
MyImageFactoryFromImage;
256
typedef
MyImageFactoryFromImage::OutputImage OutputImage;
257
MyImageFactoryFromImage imageFactoryFromImage(
image
);
258
259
typedef
ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromImage>
MyImageCacheReadPolicyFIFO;
260
//typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage> MyImageCacheWritePolicyWT;
261
typedef
ImageCacheWritePolicyWB<OutputImage, MyImageFactoryFromImage>
MyImageCacheWritePolicyWB;
262
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
263
//MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
264
MyImageCacheWritePolicyWB imageCacheWritePolicyWB(imageFactoryFromImage);
265
266
typedef
TiledImage<VImage, MyImageFactoryFromImage, MyImageCacheReadPolicyFIFO, MyImageCacheWritePolicyWB>
MyTiledImage;
267
BOOST_CONCEPT_ASSERT((
concepts::CImage< MyTiledImage >
));
268
MyTiledImage tiledImage(imageFactoryFromImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWB, 4);
269
270
// writing values
271
const
auto
maximalValue = tiledImage.domain().size();
272
MyTiledImage::Range::OutputIterator it = tiledImage.range().outputIterator();
273
for
(
size_t
i = 0; i < maximalValue; ++i)
274
{
275
*it++ = i;
276
}
277
278
// reading values
279
MyTiledImage::ConstRange r = tiledImage.constRange();
280
std::copy( r.begin(), r.end(), std::ostream_iterator<int>(cout,
", "
) );
281
cout << endl;
282
283
std::vector<int> to_vector(100);
284
std::copy(r.begin(), r.end(), to_vector.begin());
285
for
(
int
i = 0; i < 100; i++)
286
{
287
if
(to_vector[i]==i)
288
{
289
cout <<
"ok, "
;
290
nbok += 1;
291
nb++;
292
}
293
else
294
{
295
cout <<
"!ok -> "
<< to_vector[i] <<
", "
;
296
nb++;
297
}
298
}
299
cout << endl;
300
301
cout << endl;
302
303
// reading values
304
std::copy( r.begin(
Z2i::Point
(7,7)), r.end(), std::ostream_iterator<int>(cout,
", "
) );
305
cout << endl;
306
307
std::vector<int> to_vector2(28);
308
std::copy(r.begin(
Z2i::Point
(7,7)), r.end(), to_vector2.begin());
309
for
(
int
i = 0; i < 28; i++)
310
{
311
if
(to_vector2[i]==i+72)
312
{
313
cout <<
"ok, "
;
314
nbok += 1 ;
315
nb++;
316
}
317
else
318
{
319
cout <<
"!ok -> "
<< to_vector2[i] <<
", "
;
320
nb++;
321
}
322
}
323
cout << endl;
324
325
trace
.
endBlock
();
326
327
return
nbok == nb;
328
}
329
331
// Standard services - public :
332
333
int
main
(
int
argc,
char
** argv )
334
{
335
trace
.
beginBlock
(
"Testing class TiledImage"
);
336
trace
.
info
() <<
"Args:"
;
337
for
(
int
i = 0; i < argc; ++i )
338
trace
.
info
() <<
" "
<< argv[ i ];
339
trace
.
info
() << endl;
340
341
bool
res =
testSimple
() &&
test3d
() &&
testIterators
() &&
test_range_constRange
();
// && ... other tests
342
343
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
344
trace
.
endBlock
();
345
return
res ? 0 : 1;
346
}
347
// //
DGtal::ImageCacheReadPolicyFIFO
Aim: implements a 'FIFO' read policy cache.
Definition
ImageCachePolicies.h:183
DGtal::ImageCacheWritePolicyWB
Aim: implements a 'WB (Write-back or Write-behind)' write policy cache.
Definition
ImageCachePolicies.h:363
DGtal::ImageCacheWritePolicyWT
Aim: implements a 'WT (Write-through)' write policy cache.
Definition
ImageCachePolicies.h:287
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::ImageFactoryFromImage
Aim: implements a factory to produce images from a "bigger/original" one according to a given domain.
Definition
ImageFactoryFromImage.h:67
DGtal::ConstIterator
DGtal::TiledImage
Aim: implements a tiled image from a "bigger/original" one from an ImageFactory.
Definition
TiledImage.h:79
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::Z2i::Point
Space::Point Point
Definition
StdDefs.h:95
DGtal::Z2i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:99
DGtal::Z3i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:172
DGtal::Z3i::Point
Space::Point Point
Definition
StdDefs.h:168
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::CImage
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition
CImage.h:103
test_range_constRange
bool test_range_constRange()
Definition
testImageAdapter.cpp:228
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
image
Image image(domain)
test3d
bool test3d()
Definition
testTiledImage.cpp:129
testIterators
bool testIterators()
Definition
testTiledImage.cpp:183
testSimple
void testSimple()
Definition
testTrace.cpp:47
tests
images
testTiledImage.cpp
Generated on
for DGtal by
1.18.0