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);
74 OutputImage::ConstRange r1 = image1->constRange();
75 cout <<
"image1: "; std::copy( r1.begin(), r1.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
78 OutputImage *image1b = factImage.requestImage(domain1b);
79 OutputImage::ConstRange r1b = image1b->constRange();
80 cout <<
"image1b: "; std::copy( r1b.begin(), r1b.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
83 OutputImage *image2 = factImage.requestImage(domain2);
84 OutputImage::ConstRange r2 = image2->constRange();
85 cout <<
"image2: "; std::copy( r2.begin(), r2.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
88 OutputImage *image3 = factImage.requestImage(domain3);
89 OutputImage::ConstRange r3 = image3->constRange();
90 cout <<
"image3: "; std::copy( r3.begin(), r3.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
93 OutputImage *image4 = factImage.requestImage(domain4);
94 OutputImage::ConstRange r4 = image4->constRange();
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);
107 OutputImage::Value aValue;
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;
154 trace.
info() <<
" AFTER WRITING: Point 2,2 on ORIGINAL image, value: " << image(
Z2i::Point(2,2)) << endl;
155 nbok += (image(
Z2i::Point(2,2)) == 22) ? 1 : 0;
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;
186 trace.
info() <<
" AFTER WRITING: Point 0,0 on ORIGINAL image, value: " << image(
Z2i::Point(0,0)) << endl;
187 nbok += (image(
Z2i::Point(0,0)) == 7) ? 1 : 0;
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;
218 trace.
info() <<
" AFTER WRITING: Point 2,2 on ORIGINAL image, value: " << image(
Z2i::Point(2,2)) << endl;
219 nbok += (image(
Z2i::Point(2,2)) == 11) ? 1 : 0;
222 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
224 imageCache2.update(domain3);
226 trace.
info() <<
" AFTER FLUSHING: Point 2,2 on ORIGINAL image, value: " << image(
Z2i::Point(2,2)) << endl;
227 nbok += (image(
Z2i::Point(2,2)) == 22) ? 1 : 0;
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;
258 trace.
info() <<
" AFTER WRITING: Point 2,2 on ORIGINAL image, value: " << image(
Z2i::Point(2,2)) << endl;
259 nbok += (image(
Z2i::Point(2,2)) == 11) ? 1 : 0;
262 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
264 imageCache3.update(domain3);
266 trace.
info() <<
" AFTER FLUSHING: Point 2,2 on ORIGINAL image, value: " << image(
Z2i::Point(2,2)) << endl;
267 nbok += (image(
Z2i::Point(2,2)) == 11) ? 1 : 0;
270 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
272 imageCache3.update(domain2);
274 trace.
info() <<
" AFTER FLUSHING: Point 2,2 on ORIGINAL image, value: " << image(
Z2i::Point(2,2)) << endl;
275 nbok += (image(
Z2i::Point(2,2)) == 11) ? 1 : 0;
278 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
280 imageCache3.update(domain1);
282 trace.
info() <<
" AFTER FLUSHING: Point 2,2 on ORIGINAL image, value: " << image(
Z2i::Point(2,2)) << endl;
283 nbok += (image(
Z2i::Point(2,2)) == 22) ? 1 : 0;
286 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;