32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/images/ImageContainerBySTLVector.h"
38 #include "DGtal/images/ImageFactoryFromImage.h"
39 #include "DGtal/images/ImageCache.h"
41 #include "ConfigTest.h"
45 using namespace DGtal;
52 unsigned int nbok = 0;
61 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
64 trace.
info() <<
"ORIGINAL image: " << image << endl;
68 MyImageFactoryFromImage factImage(image);
70 typedef MyImageFactoryFromImage::OutputImage OutputImage;
73 OutputImage *image1 = factImage.requestImage(domain1);
75 cout <<
"image1: "; std::copy( r1.begin(), r1.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
78 OutputImage *image1b = factImage.requestImage(domain1b);
80 cout <<
"image1b: "; std::copy( r1b.begin(), r1b.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
83 OutputImage *image2 = factImage.requestImage(domain2);
85 cout <<
"image2: "; std::copy( r2.begin(), r2.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
88 OutputImage *image3 = factImage.requestImage(domain3);
90 cout <<
"image3: "; std::copy( r3.begin(), r3.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
93 OutputImage *image4 = factImage.requestImage(domain4);
95 cout <<
"image4: "; std::copy( r4.begin(), r4.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
98 trace.
info() << endl <<
"ImageCache with DGtal::CACHE_READ_POLICY_LAST, DGtal::CACHE_WRITE_POLICY_WT" << endl;
102 MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
103 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
106 MyImageCache imageCache(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT);
109 trace.
info() <<
"READING from cache (empty cache): " << imageCache << endl;
111 trace.
info() <<
"READ: Point 2,2 is in an image from cache, value: " << aValue << endl;
113 trace.
info() <<
"READ: Point 2,2 is not in an image from cache." << endl;
114 nbok += (imageCache.read(
Z2i::Point(2,2), aValue) ==
false) ? 1 : 0;
117 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
119 imageCache.update(domain1);
121 trace.
info() <<
"READING from cache (not empty but wrong domain): " << imageCache << endl;
123 trace.
info() <<
"READ: Point 2,2 is in an image from cache, value: " << aValue << endl;
125 trace.
info() <<
"READ: Point 2,2 is not in an image from cache." << endl;
126 nbok += (imageCache.read(
Z2i::Point(2,2), aValue) ==
false) ? 1 : 0;
129 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
131 imageCache.update(domain4);
133 trace.
info() <<
"READING from cache (not empty but good domain): " << imageCache << endl;
135 trace.
info() <<
"READ: Point 2,2 is in an image from cache, value: " << aValue << endl;
137 trace.
info() <<
"READ: Point 2,2 is not in an image from cache." << endl;
138 nbok += ( (imageCache.read(
Z2i::Point(2,2), aValue) && (aValue == 11)) ==
true ) ? 1 : 0;
141 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
143 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache << endl;
145 if (imageCache.write(
Z2i::Point(2,2), aValue))
146 trace.
info() <<
"WRITE: Point 2,2 is in an image from cache, value: " << aValue << endl;
148 trace.
info() <<
"WRITE: Point 2,2 is not in an image from cache." << endl;
149 nbok += ( (imageCache.read(
Z2i::Point(2,2), aValue) && (aValue == 22)) ==
true ) ? 1 : 0;
152 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
158 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
160 imageCache.update(domain3);
162 trace.
info() <<
"WRITING from cache (not empty but wrong domain): " << imageCache << endl;
164 if (imageCache.write(
Z2i::Point(2,2), aValue))
165 trace.
info() <<
"WRITE: Point 2,2 is in an image from cache, value: " << aValue << endl;
167 trace.
info() <<
"WRITE: Point 2,2 is not in an image from cache." << endl;
168 nbok += (imageCache.read(
Z2i::Point(2,2), aValue) ==
false) ? 1 : 0;
171 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
173 imageCache.update(domain1);
175 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache << endl;
177 if (imageCache.write(
Z2i::Point(0,0), aValue))
178 trace.
info() <<
"WRITE: Point 0,0 is in an image from cache, value: " << aValue << endl;
180 trace.
info() <<
"WRITE: Point 0,0 is not in an image from cache." << endl;
181 nbok += ( (imageCache.read(
Z2i::Point(0,0), aValue) && (aValue == 7)) ==
true ) ? 1 : 0;
184 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
190 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
194 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
197 trace.
info() << endl <<
"ImageCache with DGtal::CACHE_READ_POLICY_LAST, DGtal::CACHE_WRITE_POLICY_WB" << endl;
200 MyImageCacheWritePolicyWB imageCacheWritePolicyWB(factImage);
203 MyImageCache2 imageCache2(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWB);
205 imageCache2.update(domain4);
207 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache2 << endl;
209 if (imageCache2.write(
Z2i::Point(2,2), aValue))
210 trace.
info() <<
"WRITE: Point 2,2 is in an image from cache, value: " << aValue << endl;
212 trace.
info() <<
"WRITE: Point 2,2 is not in an image from cache." << endl;
213 nbok += ( (imageCache2.read(
Z2i::Point(2,2), aValue) && (aValue == 22)) == true ) ? 1 : 0;
216 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
222 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
224 imageCache2.update(domain3);
230 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
234 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
237 trace.
info() << endl <<
"ImageCache with DGtal::CACHE_READ_POLICY_FIFO, DGtal::CACHE_WRITE_POLICY_WB" << endl;
240 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(factImage, 3);
243 MyImageCache3 imageCache3(factImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWB);
245 imageCache3.update(domain4);
247 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache3 << endl;
249 if (imageCache3.write(
Z2i::Point(2,2), aValue))
250 trace.
info() <<
"WRITE: Point 2,2 is in an image from cache, value: " << aValue << endl;
252 trace.
info() <<
"WRITE: Point 2,2 is not in an image from cache." << endl;
253 nbok += ( (imageCache3.read(
Z2i::Point(2,2), aValue) && (aValue == 22)) == true ) ? 1 : 0;
256 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
262 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
264 imageCache3.update(domain3);
270 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
272 imageCache3.update(domain2);
278 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
280 imageCache3.update(domain1);
286 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
296 int main(
int argc,
char** argv )
300 for (
int i = 0; i < argc; ++i )
306 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: implements a 'FIFO' read policy cache.
Aim: implements a 'LAST' read policy cache.
Aim: implements a 'WB (Write-back or Write-behind)' write policy cache.
Aim: implements a 'WT (Write-through)' write policy cache.
Aim: implements an images cache with 'read and write' policies.
Aim: implements a factory to produce images from a "bigger/original" one according to a given domain.
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
Image::ConstRange ConstRange