DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testTiledImage.cpp File Reference

A test file for TiledImage. More...

#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageFactoryFromImage.h"
#include "DGtal/images/TiledImage.h"
#include "ConfigTest.h"

Go to the source code of this file.

Functions

bool testSimple ()
 
bool test3d ()
 
bool testIterators ()
 
bool test_range_constRange ()
 
int main (int argc, char **argv)
 

Detailed Description

A test file for TiledImage.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Martial Tola (marti.nosp@m.al.t.nosp@m.ola@l.nosp@m.iris.nosp@m..cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2013/01/23

This file is part of the DGtal library.

Definition in file testTiledImage.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 333 of file testTiledImage.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool test3d()
bool testSimple()
bool testIterators()
bool test_range_constRange()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), test3d(), test_range_constRange(), testIterators(), testSimple(), and DGtal::trace.

◆ test3d()

bool test3d ( )

Definition at line 129 of file testTiledImage.cpp.

130{
131 unsigned int nbok = 0;
132 unsigned int nb = 0;
133
134 trace.beginBlock("Testing 3d TiledImage");
135
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
151 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
152 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
153
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}
Aim: implements a 'FIFO' read policy cache.
Aim: implements a 'WT (Write-through)' write policy cache.
Aim: implements a factory to produce images from a "bigger/original" one according to a given domain.
Aim: implements a tiled image from a "bigger/original" one from an ImageFactory.
Definition: TiledImage.h:77
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ test_range_constRange()

bool test_range_constRange ( )

Definition at line 240 of file testTiledImage.cpp.

241{
242 unsigned int nbok = 0;
243 unsigned int nb = 0;
244
245 trace.beginBlock("Testing range/constRange with TiledImage");
246
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
260 //typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage> MyImageCacheWritePolicyWT;
262 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
263 //MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
264 MyImageCacheWritePolicyWB imageCacheWritePolicyWB(imageFactoryFromImage);
265
267 BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImage > ));
268 MyTiledImage tiledImage(imageFactoryFromImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWB, 4);
269
270 // writing values
271 const int maximalValue = tiledImage.domain().size();
272 MyTiledImage::Range::OutputIterator it = tiledImage.range().outputIterator();
273 for (int 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}
Aim: implements a 'WB (Write-back or Write-behind)' write policy cache.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testIterators()

bool testIterators ( )

Definition at line 183 of file testTiledImage.cpp.

184{
185 unsigned int nbok = 0;
186 unsigned int nb = 0;
187
188 trace.beginBlock("Testing iterators with TiledImage");
189
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
201 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
202 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
203
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}
MyDigitalSurface::ConstIterator ConstIterator

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testSimple()

bool testSimple ( )

Definition at line 48 of file testTiledImage.cpp.

49{
50 unsigned int nbok = 0;
51 unsigned int nb = 0;
52
53 trace.beginBlock("Testing simple TiledImage");
54
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
70 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
71 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
72
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}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().