51{
52 unsigned int nbok = 0;
53 unsigned int nb = 0;
54
56
58
60 int i = 1;
61 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
62 *it = i++;
63
64 trace.
info() <<
"ORIGINAL image: " << image << endl;
65
66
68 MyImageFactoryFromImage factImage(image);
69
70 typedef MyImageFactoryFromImage::OutputImage OutputImage;
71
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;
76
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;
81
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;
86
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;
91
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;
96
97
98 trace.
info() << endl <<
"ImageCache with DGtal::CACHE_READ_POLICY_LAST, DGtal::CACHE_WRITE_POLICY_WT" << endl;
99
102 MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
103 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
104
106 MyImageCache imageCache(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT);
107 OutputImage::Value aValue;
108
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;
112 else
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;
115 nb++;
116
117 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
118
119 imageCache.update(domain1);
120
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;
124 else
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;
127 nb++;
128
129 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
130
131 imageCache.update(domain4);
132
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;
136 else
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;
139 nb++;
140
141 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
142
143 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache << endl;
144 aValue = 22;
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;
147 else
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;
150 nb++;
151
152 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
153
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;
156 nb++;
157
158 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
159
160 imageCache.update(domain3);
161
162 trace.
info() <<
"WRITING from cache (not empty but wrong domain): " << imageCache << endl;
163 aValue = 22;
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;
166 else
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;
169 nb++;
170
171 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
172
173 imageCache.update(domain1);
174
175 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache << endl;
176 aValue = 7;
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;
179 else
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;
182 nb++;
183
184 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
185
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;
188 nb++;
189
190 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
191
192
193 i = 1;
194 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
195 *it = i++;
196
197 trace.
info() << endl <<
"ImageCache with DGtal::CACHE_READ_POLICY_LAST, DGtal::CACHE_WRITE_POLICY_WB" << endl;
198
200 MyImageCacheWritePolicyWB imageCacheWritePolicyWB(factImage);
201
203 MyImageCache2 imageCache2(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWB);
204
205 imageCache2.update(domain4);
206
207 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache2 << endl;
208 aValue = 22;
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;
211 else
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;
214 nb++;
215
216 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
217
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;
220 nb++;
221
222 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
223
224 imageCache2.update(domain3);
225
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;
228 nb++;
229
230 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
231
232
233 i = 1;
234 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
235 *it = i++;
236
237 trace.
info() << endl <<
"ImageCache with DGtal::CACHE_READ_POLICY_FIFO, DGtal::CACHE_WRITE_POLICY_WB" << endl;
238
240 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(factImage, 3);
241
243 MyImageCache3 imageCache3(factImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWB);
244
245 imageCache3.update(domain4);
246
247 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache3 << endl;
248 aValue = 22;
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;
251 else
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;
254 nb++;
255
256 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
257
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;
260 nb++;
261
262 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
263
264 imageCache3.update(domain3);
265
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;
268 nb++;
269
270 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
271
272 imageCache3.update(domain2);
273
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;
276 nb++;
277
278 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
279
280 imageCache3.update(domain1);
281
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;
284 nb++;
285
286 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
287
289
290 return nbok == nb;
291}
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.