Example of HDF5 ImageFactory.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/ImageFactoryFromImage.h"
#include "DGtal/images/ImageFactoryFromHDF5.h"
#include "DGtal/images/ImageCache.h"
#include "DGtal/images/TiledImage.h"
#include "ConfigExamples.h"
#define H5FILE_NAME_3D_TILED "exampleImageFactoryFromHDF5_TILED_3D.h5"
#define DATASETNAME_3D "UInt8Array3D"
#define NX_3D_TILED 300
#define NY_3D_TILED 300
#define NZ_3D_TILED 300
#define CHUNK_X_3D_TILED 50
#define CHUNK_Y_3D_TILED 50
#define CHUNK_Z_3D_TILED 50
#define RANK_3D_TILED 3
{
trace.
info() <<
"begin" << endl;
hid_t file, dataset;
hid_t datatype, dataspace;
herr_t status;
int i, j, k;
hid_t plist_id;
if (data == NULL)
{
trace.
error() <<
" malloc error" << endl;
return false;
}
if (i>=15 && j>=15 && k>=15 && i<35 && j<35 && k<35)
else
plist_id = H5Pcreate (H5P_DATASET_CREATE);
if (status)
{
trace.
error() <<
" H5Dchunck error" << std::endl;
free(data);
return false;
}
status = H5Pset_deflate (plist_id, 6);
if (status)
{
trace.
error() <<
" H5Ddeflate error" << std::endl;
free(data);
return false;
}
datatype = H5Tcopy(H5T_NATIVE_UINT8);
status = H5Tset_order(datatype, H5T_ORDER_LE);
if (status)
{
trace.
error() <<
" H5Dsetorder error" << std::endl;
free(data);
return false;
}
H5P_DEFAULT, plist_id, H5P_DEFAULT);
status = H5Dwrite(dataset, H5T_NATIVE_UINT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
if (status)
{
trace.
error() <<
" H5Dwrite error" << std::endl;
free(data);
return false;
}
H5Sclose(dataspace);
H5Tclose(datatype);
H5Dclose(dataset);
H5Pclose(plist_id);
H5Fclose(file);
free(data);
trace.
info() <<
"end" << endl;
return true;
}
{
int i, j, k;
typedef ImageV::Domain DomainV;
typedef ImageV::Point PointV;
ImageV imageV(domainV);
if (i>=15 && j>=15 && k>=15 && i<35 && j<35 && k<35)
imageV.setValue(PointV(i,j,k), 1);
else
imageV.setValue(PointV(i,j,k), 0);
int cpt=0;
trace.
beginBlock(
"Counting ones in the original image (domain)");
for(ImageV::Domain::ConstIterator it = imageV.domain().begin(), itend = imageV.domain().end();
it != itend; ++it)
if (imageV( *it ) == 1)
cpt++;
trace.
info() <<
"imageV cpt: " << cpt << endl;
cpt=0;
trace.
beginBlock(
"Counting ones in the original image (range)");
for(ImageV::Range::ConstIterator it = imageV.range().begin(), itend = imageV.range().end();
it != itend; ++it)
if (( *it ) == 1)
cpt++;
trace.
info() <<
"imageV cpt: " << cpt << endl;
return true;
}
{
int i, j, k;
trace.
beginBlock(
"Example : TiledImage with ImageFactoryFromImage - 1 block (3D)");
typedef ImageV::Domain DomainV;
typedef ImageV::Point PointV;
ImageV imageV(domainV);
if (i>=15 && j>=15 && k>=15 && i<35 && j<35 && k<35)
imageV.setValue(PointV(i,j,k), 1);
else
imageV.setValue(PointV(i,j,k), 0);
MyImageFactoryFromImage factImage(imageV);
typedef MyImageFactoryFromImage::OutputImage OutputImage;
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
MyTiledImage tiledImage1block(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT, 1);
typedef MyTiledImage::OutputImage OutputImage;
trace.
info() << tiledImage1block << std::endl;
int cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 1x1x1 blocks - LAST/WT - TiledIterator");
for(MyTiledImage::TiledIterator it = tiledImage1block.begin(), itend = tiledImage1block.end();
it != itend; ++it)
if ((*it) == 1)
cpt++;
trace.
info() <<
"Cpt: " << cpt <<
" - cacheMissRead:" << tiledImage1block.getCacheMissRead() <<
" - cacheMissWrite:" << tiledImage1block.getCacheMissWrite() << endl;
cpt=0; tiledImage1block.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 1x1x1 blocks - LAST/WT");
for(ImageV::Domain::ConstIterator it = tiledImage1block.domain().begin(), itend = tiledImage1block.domain().end();
it != itend; ++it)
if (tiledImage1block(*it) == 1)
cpt++;
trace.
info() <<
"Cpt: " << cpt <<
" - cacheMissRead:" << tiledImage1block.getCacheMissRead() <<
" - cacheMissWrite:" << tiledImage1block.getCacheMissWrite() << endl;
return true;
}
{
trace.
beginBlock(
"Example : TiledImage with ImageFactoryFromHDF5 - 1 block (3D)");
typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
MyTiledImage tiledImage1block(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT, 1);
typedef MyTiledImage::OutputImage OutputImage;
trace.
info() << tiledImage1block << std::endl;
int cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 1x1x1 blocks - LAST/WT - TiledIterator");
for(MyTiledImage::TiledIterator it = tiledImage1block.begin(), itend = tiledImage1block.end();
it != itend; ++it)
if ((*it) == 1)
cpt++;
trace.
info() <<
"Cpt: " << cpt <<
" - cacheMissRead:" << tiledImage1block.getCacheMissRead() <<
" - cacheMissWrite:" << tiledImage1block.getCacheMissWrite() << endl;
cpt=0; tiledImage1block.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 1x1x1 blocks - LAST/WT");
for(Image::Domain::ConstIterator it = tiledImage1block.domain().begin(), itend = tiledImage1block.domain().end();
it != itend; ++it)
if (tiledImage1block(*it) == 1)
cpt++;
trace.
info() <<
"Cpt: " << cpt <<
" - cacheMissRead:" << tiledImage1block.getCacheMissRead() <<
" - cacheMissWrite:" << tiledImage1block.getCacheMissWrite() << endl;
return true;
}
{
int i, j, k;
trace.
beginBlock(
"Example : TiledImage with ImageFactoryFromImage - 10 blocks (3D)");
typedef ImageV::Domain DomainV;
typedef ImageV::Point PointV;
ImageV imageV(domainV);
if (i>=15 && j>=15 && k>=15 && i<35 && j<35 && k<35)
imageV.setValue(PointV(i,j,k), 1);
else
imageV.setValue(PointV(i,j,k), 0);
MyImageFactoryFromImage factImage(imageV);
typedef MyImageFactoryFromImage::OutputImage OutputImage;
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_A(factImage, 10);
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_B(factImage, 5);
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
MyTiledImage tiledImage(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT, 10);
MyTiledImageFIFO tiledImageFIFO_A(factImage, imageCacheReadPolicyFIFO_A, imageCacheWritePolicyWT, 10);
MyTiledImageFIFO tiledImageFIFO_B(factImage, imageCacheReadPolicyFIFO_B, imageCacheWritePolicyWT, 10);
typedef MyTiledImage::OutputImage OutputImage;
int cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(10)/WT - TiledIterator");
for(MyTiledImageFIFO::TiledIterator it = tiledImageFIFO_A.begin(), itend = tiledImageFIFO_A.end();
it != itend; ++it)
{
if ((*it) == 1)
cpt++;
}
cpt=0; tiledImageFIFO_A.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(10)/WT");
for(ImageV::Domain::ConstIterator it = tiledImageFIFO_A.domain().begin(), itend = tiledImageFIFO_A.domain().end();
it != itend; ++it)
{
if (tiledImageFIFO_A(*it) == 1)
cpt++;
}
cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(5)/WT - TiledIterator");
for(MyTiledImageFIFO::TiledIterator it = tiledImageFIFO_B.begin(), itend = tiledImageFIFO_B.end();
it != itend; ++it)
{
if ((*it) == 1)
cpt++;
}
cpt=0; tiledImageFIFO_B.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(5)/WT");
for(ImageV::Domain::ConstIterator it = tiledImageFIFO_B.domain().begin(), itend = tiledImageFIFO_B.domain().end();
it != itend; ++it)
{
if (tiledImageFIFO_B(*it) == 1)
cpt++;
}
cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - LAST/WT - TiledIterator");
for(MyTiledImage::TiledIterator it = tiledImage.begin(), itend = tiledImage.end();
it != itend; ++it)
{
if ((*it) == 1)
cpt++;
}
cpt=0; tiledImage.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - LAST/WT");
for(ImageV::Domain::ConstIterator it = tiledImage.domain().begin(), itend = tiledImage.domain().end();
it != itend; ++it)
{
if (tiledImage(*it) == 1)
cpt++;
}
return true;
}
{
trace.
beginBlock(
"Example : TiledImage with ImageFactoryFromHDF5 - 10 blocks (3D)");
typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_A(factImage, 10);
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_B(factImage, 5);
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
MyTiledImage tiledImage(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT, 10);
MyTiledImageFIFO tiledImageFIFO_A(factImage, imageCacheReadPolicyFIFO_A, imageCacheWritePolicyWT, 10);
MyTiledImageFIFO tiledImageFIFO_B(factImage, imageCacheReadPolicyFIFO_B, imageCacheWritePolicyWT, 10);
typedef MyTiledImage::OutputImage OutputImage;
int cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(10)/WT - TiledIterator");
for(MyTiledImageFIFO::TiledIterator it = tiledImageFIFO_A.begin(), itend = tiledImageFIFO_A.end();
it != itend; ++it)
{
if ((*it) == 1)
cpt++;
}
cpt=0; tiledImageFIFO_A.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(10)/WT");
for(Image::Domain::ConstIterator it = tiledImageFIFO_A.domain().begin(), itend = tiledImageFIFO_A.domain().end();
it != itend; ++it)
{
if (tiledImageFIFO_A(*it) == 1)
cpt++;
}
cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(5)/WT - TiledIterator");
for(MyTiledImageFIFO::TiledIterator it = tiledImageFIFO_B.begin(), itend = tiledImageFIFO_B.end();
it != itend; ++it)
{
if ((*it) == 1)
cpt++;
}
cpt=0; tiledImageFIFO_B.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - FIFO(5)/WT");
for(Image::Domain::ConstIterator it = tiledImageFIFO_B.domain().begin(), itend = tiledImageFIFO_B.domain().end();
it != itend; ++it)
{
if (tiledImageFIFO_B(*it) == 1)
cpt++;
}
cpt=0;
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - LAST/WT - TiledIterator");
for(MyTiledImage::TiledIterator it = tiledImage.begin(), itend = tiledImage.end();
it != itend; ++it)
{
if ((*it) == 1)
cpt++;
}
cpt=0; tiledImage.clearCacheAndResetCacheMisses();
trace.
beginBlock(
"Counting ones in the tiled image - 10x10x10 blocks - LAST/WT");
for(Image::Domain::ConstIterator it = tiledImage.domain().begin(), itend = tiledImage.domain().end();
it != itend; ++it)
{
if (tiledImage(*it) == 1)
cpt++;
}
return true;
}
{
return 0;
}
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 a factory from an HDF5 file.
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.
void beginBlock(const std::string &keyword="")
bool exampleTiledImageFromHDF5_1block3D()
bool exampleTiledImageFromImage_10blocks3D()
bool exampleTiledImageFromImage_1block3D()
bool exampleTiledImageFromHDF5_10blocks3D()
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::uint8_t uint8_t
unsigned 8-bit integer.
Aim: Defines the concept describing a read/write image, having an output iterator.
bool writeHDF5_3D_TILED()
#define H5FILE_NAME_3D_TILED
ImageContainerBySTLVector< Domain, Value > Image