32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/images/ImageSelector.h"
35#include "DGtal/images/ImageFactoryFromHDF5.h"
36#include "DGtal/images/ImageCache.h"
37#include "DGtal/images/TiledImage.h"
39#include "ConfigTest.h"
49#define H5FILE_NAME "testImageFactoryFromHDF5.h5"
51#define DATASETNAME_2D "Int32Array2D"
59 hid_t datatype, dataspace;
66 for(j = 0; j <
NY_2D; j++)
67 for(i = 0; i <
NX_2D; i++)
82 file = H5Fcreate(
H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
87 dataspace = H5Screate_simple(
RANK_2D, dimsf, NULL);
92 datatype = H5Tcopy(H5T_NATIVE_INT32);
93 status = H5Tset_order(datatype, H5T_ORDER_LE);
100 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
103 status = H5Dwrite(dataset, H5T_NATIVE_INT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
106 trace.
error() <<
" H5Dwrite error" << std::endl;
119#define DATASETNAME_2D_TILED "Int64Array2D"
120#define RANK_2D_TILED 2
121#define _NX_2D_TILED 16
122#define _NY_2D_TILED 16
127 hid_t datatype, dataspace;
144 file = H5Fcreate(_H5FILE_NAME_2D_TILED.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
154 datatype = H5Tcopy(H5T_NATIVE_INT64);
155 status = H5Tset_order(datatype, H5T_ORDER_LE);
162 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
165 status = H5Dwrite(dataset, H5T_NATIVE_INT64, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
168 trace.
error() <<
" H5Dwrite error" << std::endl;
181#define H5FILE_NAME_3D_TILED_EASY_READING "testImageFactoryFromHDF5_TILED_3D_for_easy_reading.h5"
182#define H5FILE_NAME_3D_TILED "testImageFactoryFromHDF5_TILED_3D.h5"
184#define DATASETNAME_3D_TILED "DoubleArray3D"
185#define NX_3D_TILED 10
188#define RANK_3D_TILED 3
193 hid_t datatype, dataspace;
204 data[j][i][k] = ii++;
222 datatype = H5Tcopy(H5T_NATIVE_DOUBLE);
223 status = H5Tset_order(datatype, H5T_ORDER_LE);
230 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
233 status = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
236 trace.
error() <<
" H5Dwrite error" << std::endl;
252 hid_t datatype, dataspace;
263 data[k][j][i] = ii++;
281 datatype = H5Tcopy(H5T_NATIVE_DOUBLE);
282 status = H5Tset_order(datatype, H5T_ORDER_LE);
289 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
292 status = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
295 trace.
error() <<
" H5Dwrite error" << std::endl;
310 unsigned int nbok = 0;
321 typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
324 OutputImage *image1 = factImage.requestImage(domain1);
325 OutputImage::ConstRange r1 = image1->constRange();
326 cout <<
"image1: "; std::copy( r1.begin(), r1.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
329 OutputImage *image1b = factImage.requestImage(domain1b);
330 OutputImage::ConstRange r1b = image1b->constRange();
331 cout <<
"image1b: "; std::copy( r1b.begin(), r1b.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
334 OutputImage *image2 = factImage.requestImage(domain2);
335 OutputImage::ConstRange r2 = image2->constRange();
336 cout <<
"image2: "; std::copy( r2.begin(), r2.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
339 OutputImage *image3 = factImage.requestImage(domain3);
340 OutputImage::ConstRange r3 = image3->constRange();
341 cout <<
"image3: "; std::copy( r3.begin(), r3.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
344 OutputImage *image4 = factImage.requestImage(domain4);
345 OutputImage::ConstRange r4 = image4->constRange();
346 cout <<
"image4: "; std::copy( r4.begin(), r4.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
349 OutputImage *image5 = factImage.requestImage(domain5);
350 OutputImage::ConstRange r5 = image5->constRange();
351 cout <<
"image5: "; std::copy( r5.begin(), r5.end(), std::ostream_iterator<int>(cout,
", ") ); cout << endl;
354 trace.
info() << endl <<
"ImageCache with DGtal::CACHE_READ_POLICY_LAST, DGtal::CACHE_WRITE_POLICY_WT" << endl;
358 MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
359 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
362 MyImageCache imageCache(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT);
363 OutputImage::Value aValue;
365 trace.
info() <<
"READING from cache (empty cache): " << imageCache << endl;
367 trace.
info() <<
"READ: Point 2,2 is in an image from cache, value: " << aValue << endl;
369 trace.
info() <<
"READ: Point 2,2 is not in an image from cache." << endl;
370 nbok += (imageCache.read(
Z2i::Point(2,2), aValue) ==
false) ? 1 : 0;
373 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
375 imageCache.update(domain1);
377 trace.
info() <<
"READING from cache (not empty but wrong domain): " << imageCache << endl;
379 trace.
info() <<
"READ: Point 2,2 is in an image from cache, value: " << aValue << endl;
381 trace.
info() <<
"READ: Point 2,2 is not in an image from cache." << endl;
382 nbok += (imageCache.read(
Z2i::Point(2,2), aValue) ==
false) ? 1 : 0;
385 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
387 imageCache.update(domain4);
389 trace.
info() <<
"READING from cache (not empty but good domain): " << imageCache << endl;
391 trace.
info() <<
"READ: Point 2,2 is in an image from cache, value: " << aValue << endl;
393 trace.
info() <<
"READ: Point 2,2 is not in an image from cache." << endl;
394 nbok += ( (imageCache.read(
Z2i::Point(2,2), aValue) && (aValue == 4)) ==
true ) ? 1 : 0;
397 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
399 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache << endl;
401 if (imageCache.write(
Z2i::Point(2,2), aValue))
402 trace.
info() <<
"WRITE: Point 2,2 is in an image from cache, value: " << aValue << endl;
404 trace.
info() <<
"WRITE: Point 2,2 is not in an image from cache." << endl;
405 nbok += ( (imageCache.read(
Z2i::Point(2,2), aValue) && (aValue == 22)) ==
true ) ? 1 : 0;
408 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
410 imageCache.update(domain3);
412 trace.
info() <<
"WRITING from cache (not empty but wrong domain): " << imageCache << endl;
414 if (imageCache.write(
Z2i::Point(2,2), aValue))
415 trace.
info() <<
"WRITE: Point 2,2 is in an image from cache, value: " << aValue << endl;
417 trace.
info() <<
"WRITE: Point 2,2 is not in an image from cache." << endl;
418 nbok += (imageCache.read(
Z2i::Point(2,2), aValue) ==
false) ? 1 : 0;
421 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
423 imageCache.update(domain1);
425 trace.
info() <<
"WRITING from cache (not empty but good domain): " << imageCache << endl;
427 if (imageCache.write(
Z2i::Point(0,0), aValue))
428 trace.
info() <<
"WRITE: Point 0,0 is in an image from cache, value: " << aValue << endl;
430 trace.
info() <<
"WRITE: Point 0,0 is not in an image from cache." << endl;
431 nbok += ( (imageCache.read(
Z2i::Point(0,0), aValue) && (aValue == 7)) ==
true ) ? 1 : 0;
434 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
443 unsigned int nbok = 0;
453 typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
457 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(factImage, 2);
458 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
462 MyTiledImage tiledImage(factImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWT, 4);
464 typedef MyTiledImage::OutputImage OutputImage;
465 OutputImage::Value aValue;
468 nbok += (tiledImage(
Z2i::Point(3,1)) == 20) ? 1 : 0;
471 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
474 nbok += (tiledImage(
Z2i::Point(9,5)) == 90) ? 1 : 0;
477 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
479 aValue = 1; tiledImage.setValue(
Z2i::Point(10,6), aValue);
480 trace.
info() <<
"Write value for Point 10,6: " << aValue << endl;
481 nbok += (tiledImage(
Z2i::Point(10,6)) == 1) ? 1 : 0;
484 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
487 nbok += (tiledImage(
Z2i::Point(1,2)) == 34) ? 1 : 0;
490 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
493 nbok += (tiledImage(
Z2i::Point(15,0)) == 16) ? 1 : 0;
496 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
498 aValue = 128; tiledImage.setValue(
Z2i::Point(15,0), aValue);
499 trace.
info() <<
"Write value for Point 15,0: " << aValue << endl;
500 nbok += (tiledImage(
Z2i::Point(15,0)) == 128) ? 1 : 0;
503 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
512 unsigned int nbok = 0;
522 typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
526 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(factImage, 2);
527 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
531 MyTiledImage tiledImage(factImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWT, 2);
533 typedef MyTiledImage::OutputImage OutputImage;
534 OutputImage::Value aValue;
537 nbok += (tiledImage(
Z3i::Point(0,0,0)) == 1) ? 1 : 0;
540 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
543 nbok += (tiledImage(
Z3i::Point(3,1,0)) == 14) ? 1 : 0;
546 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
549 nbok += (tiledImage(
Z3i::Point(9,5,2)) == 220) ? 1 : 0;
552 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
554 aValue = 1.1; tiledImage.setValue(
Z3i::Point(3,6,5), aValue);
555 trace.
info() <<
"Write value for Point 3,6,5: " << aValue << endl;
556 nbok += (tiledImage(
Z3i::Point(3,6,5)) == 1.1) ? 1 : 0;
559 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
562 nbok += (tiledImage(
Z3i::Point(1,2,4)) == 342) ? 1 : 0;
565 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
568 nbok += (tiledImage(
Z3i::Point(8,6,3)) == 309) ? 1 : 0;
571 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
573 aValue = 125.5; tiledImage.setValue(
Z3i::Point(8,6,3), aValue);
574 trace.
info() <<
"Write value for Point 8,6,3: " << aValue << endl;
575 nbok += (tiledImage(
Z3i::Point(8,6,3)) == 125.5) ? 1 : 0;
578 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
588int main(
int argc,
char** argv )
592 for (
int i = 0; i < argc; ++i )
605 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: implements a 'FIFO' read policy cache.
Aim: implements a 'LAST' read 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 from an HDF5 file.
Aim: implements association bewteen points lying in a digital domain and values.
Aim: implements a tiled image from a "bigger/original" one from an ImageFactory.
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
boost::int32_t int32_t
signed 32-bit integer.
Aim: Defines the concept describing a read/write image, having an output iterator.
bool writeHDF5_3D_TILED_for_easy_reading()
bool writeHDF5_2D_TILED(const std::string &_H5FILE_NAME_2D_TILED)
#define DATASETNAME_3D_TILED
bool writeHDF5_3D_TILED()
bool testTiledImage2D_int64()
bool testTiledImage3D_double()
#define H5FILE_NAME_3D_TILED_EASY_READING
#define H5FILE_NAME_3D_TILED
#define DATASETNAME_2D_TILED