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"
using namespace std;
#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
{
hid_t file, dataset;
hid_t datatype, dataspace;
herr_t status;
int i, j, k;
hid_t plist_id;
if (data == NULL)
{
return false;
}
if (i>=15 && j>=15 && k>=15 && i<35 && j<35 && k<35)
else
plist_id = H5Pcreate (H5P_DATASET_CREATE);
if (status)
{
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)
{
free(data);
return false;
}
H5Sclose(dataspace);
H5Tclose(datatype);
H5Dclose(dataset);
H5Pclose(plist_id);
H5Fclose(file);
free(data);
return true;
}
{
int i, j, k;
typedef ImageContainerBySTLVector<Z3i::Domain, DGtal::uint8_t> ImageV;
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;
it != itend; ++it)
if (imageV( *it ) == 1)
cpt++;
trace.
info() <<
"imageV cpt: " << cpt << endl;
cpt=0;
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 ImageContainerBySTLVector<Z3i::Domain, DGtal::uint8_t> ImageV;
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);
typedef ImageFactoryFromImage<ImageV> MyImageFactoryFromImage;
MyImageFactoryFromImage factImage(imageV);
typedef MyImageFactoryFromImage::OutputImage OutputImage;
typedef ImageCacheReadPolicyLAST<OutputImage, MyImageFactoryFromImage> MyImageCacheReadPolicyLAST;
typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage> MyImageCacheWritePolicyWT;
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
typedef TiledImage<ImageV, MyImageFactoryFromImage, MyImageCacheReadPolicyLAST, MyImageCacheWritePolicyWT> MyTiledImage;
BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImage > ));
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");
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 ImageSelector<Z3i::Domain, DGtal::uint8_t>::Type
Image;
typedef ImageFactoryFromHDF5<Image> MyImageFactoryFromHDF5;
typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
typedef ImageCacheReadPolicyLAST<OutputImage, MyImageFactoryFromHDF5> MyImageCacheReadPolicyLAST;
typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromHDF5> MyImageCacheWritePolicyWT;
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
typedef TiledImage<Image, MyImageFactoryFromHDF5, MyImageCacheReadPolicyLAST, MyImageCacheWritePolicyWT> MyTiledImage;
BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImage > ));
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");
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 ImageContainerBySTLVector<Z3i::Domain, DGtal::uint8_t> ImageV;
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);
typedef ImageFactoryFromImage<ImageV> MyImageFactoryFromImage;
MyImageFactoryFromImage factImage(imageV);
typedef MyImageFactoryFromImage::OutputImage OutputImage;
typedef ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromImage> MyImageCacheReadPolicyFIFO;
typedef ImageCacheReadPolicyLAST<OutputImage, MyImageFactoryFromImage> MyImageCacheReadPolicyLAST;
typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage> MyImageCacheWritePolicyWT;
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_A(factImage, 10);
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_B(factImage, 5);
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
typedef TiledImage<ImageV, MyImageFactoryFromImage, MyImageCacheReadPolicyLAST, MyImageCacheWritePolicyWT> MyTiledImage;
BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImage > ));
MyTiledImage tiledImage(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT, 10);
typedef TiledImage<ImageV, MyImageFactoryFromImage, MyImageCacheReadPolicyFIFO, MyImageCacheWritePolicyWT> MyTiledImageFIFO;
BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImageFIFO > ));
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");
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");
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");
it != itend; ++it)
{
if (tiledImage(*it) == 1)
cpt++;
}
return true;
}
{
trace.
beginBlock(
"Example : TiledImage with ImageFactoryFromHDF5 - 10 blocks (3D)");
typedef ImageSelector<Z3i::Domain, DGtal::uint8_t>::Type
Image;
typedef ImageFactoryFromHDF5<Image> MyImageFactoryFromHDF5;
typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
typedef ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromHDF5> MyImageCacheReadPolicyFIFO;
typedef ImageCacheReadPolicyLAST<OutputImage, MyImageFactoryFromHDF5> MyImageCacheReadPolicyLAST;
typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromHDF5> MyImageCacheWritePolicyWT;
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_A(factImage, 10);
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO_B(factImage, 5);
MyImageCacheReadPolicyLAST imageCacheReadPolicyLAST(factImage);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(factImage);
typedef TiledImage<Image, MyImageFactoryFromHDF5, MyImageCacheReadPolicyLAST, MyImageCacheWritePolicyWT> MyTiledImage;
BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImage > ));
MyTiledImage tiledImage(factImage, imageCacheReadPolicyLAST, imageCacheWritePolicyWT, 10);
typedef TiledImage<Image, MyImageFactoryFromHDF5, MyImageCacheReadPolicyFIFO, MyImageCacheWritePolicyWT> MyTiledImageFIFO;
BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImageFIFO > ));
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");
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");
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");
it != itend; ++it)
{
if (tiledImage(*it) == 1)
cpt++;
}
return true;
}
{
return 0;
}
void beginBlock(const std::string &keyword="")
bool exampleTiledImageFromHDF5_1block3D()
bool exampleTiledImageFromImage_10blocks3D()
bool exampleTiledImageFromImage_1block3D()
bool exampleTiledImageFromHDF5_10blocks3D()
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::uint8_t uint8_t
unsigned 8-bit integer.
int main(int argc, char **argv)
bool writeHDF5_3D_TILED()
#define H5FILE_NAME_3D_TILED
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain