31#if defined(ImageFactoryFromHDF5_RECURSES)
32#error Recursive header files inclusion detected in ImageFactoryFromHDF5.h
35#define ImageFactoryFromHDF5_RECURSES
37#if !defined ImageFactoryFromHDF5_h
39#define ImageFactoryFromHDF5_h
44#include "DGtal/base/Common.h"
45#include "DGtal/base/ConceptUtils.h"
46#include "DGtal/images/CImage.h"
47#include "DGtal/base/Alias.h"
48#include "DGtal/kernel/CBoundedNumber.h"
65 template <
typename TImageFactory,
typename T>
71 typedef typename ImageFactory::OutputImage::Value
Value;
84 template <
typename TImageFactory>
90 typedef typename ImageFactory::OutputImage::Value
Value;
94 return H5Dread(anImageFactory.dataset, H5T_NATIVE_UINT8, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_out);
99 return H5Dwrite(anImageFactory.dataset, H5T_NATIVE_UINT8, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_in);
110 template <
typename TImageFactory>
116 typedef typename ImageFactory::OutputImage::Value
Value;
120 return H5Dread(anImageFactory.dataset, H5T_NATIVE_INT32, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_out);
125 return H5Dwrite(anImageFactory.dataset, H5T_NATIVE_INT32, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_in);
136 template <
typename TImageFactory>
142 typedef typename ImageFactory::OutputImage::Value
Value;
146 return H5Dread(anImageFactory.dataset, H5T_NATIVE_INT64, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_out);
151 return H5Dwrite(anImageFactory.dataset, H5T_NATIVE_INT64, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_in);
162 template <
typename TImageFactory>
168 typedef typename ImageFactory::OutputImage::Value
Value;
172 return H5Dread(anImageFactory.dataset, H5T_NATIVE_DOUBLE, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_out);
177 return H5Dwrite(anImageFactory.dataset, H5T_NATIVE_DOUBLE, memspace, anImageFactory.dataspace, H5P_DEFAULT, data_in);
195 template <
typename TImageContainer>
229 const int ddim = Domain::dimension;
231 hsize_t dims_out[ddim];
242 H5Sget_simple_extent_dims(
dataspace, dims_out, NULL);
247 typename TSpace::Point low, up;
250 for(d=0; d<ddim; d++)
253 up[d]=dims_out[ddim-d-1]-1;
327 const int ddim = Domain::dimension;
331 hsize_t offset[ddim];
338 hsize_t offset_out[ddim];
339 hsize_t count_out[ddim];
345 for(d=0; d<ddim; d++)
347 N_SUB[d] = (aDomain.upperBound()[ddim-d-1]-aDomain.lowerBound()[ddim-d-1])+1;
348 malloc_size = malloc_size*N_SUB[d];
352 if (data_out == NULL)
354 trace.
error() <<
"data_out malloc error in requestImage: " << (malloc_size *
sizeof(
Value)) << std::endl;
359 for(d=0; d<ddim; d++)
360 offset[d] = aDomain.lowerBound()[ddim-d-1]-
myDomain->lowerBound()[ddim-d-1];
361 for(d=0; d<ddim; d++)
363 status = H5Sselect_hyperslab(
dataspace, H5S_SELECT_SET, offset, NULL, count, NULL);
366 trace.
error() <<
" H5Sselect_hyperslab from dataspace error" << std::endl;
371 for(d=0; d<ddim; d++)
373 memspace = H5Screate_simple(ddim,dimsm,NULL);
376 for(d=0; d<ddim; d++)
378 for(d=0; d<ddim; d++)
379 count_out[d] = N_SUB[d];
380 status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL, count_out, NULL);
383 trace.
error() <<
" H5Sselect_hyperslab from memspace error" << std::endl;
392 trace.
error() <<
" H5DSpecializations/H5DreadS error" << std::endl;
397 if (outputImage == NULL)
399 trace.
error() <<
"outputImage new error in requestImage: " << std::endl;
404 typename TSpace::Point a, b;
405 for(d=0; d<ddim; d++)
407 a[d]=offset[ddim-d-1]+
myDomain->lowerBound()[d];
408 b[d]=a[d]+N_SUB[ddim-d-1]-1;
414 it = hrdomain.
begin(), itend = hrdomain.
end();
418 outputImage->
setValue((*it), data_out[ p++ ]);
439 const int ddim = Domain::dimension;
443 hsize_t offset[ddim];
450 hsize_t offset_in[ddim];
451 hsize_t count_in[ddim];
458 for(d=0; d<ddim; d++)
460 N_SUB[d] = (outputImage->
domain().upperBound()[ddim-d-1]-outputImage->
domain().lowerBound()[ddim-d-1])+1;
461 malloc_size = malloc_size*N_SUB[d];
467 trace.
error() <<
"data_in malloc error in flushImage: " << (malloc_size *
sizeof(
Value)) << std::endl;
472 for(d=0; d<ddim; d++)
473 offset[d] = outputImage->
domain().lowerBound()[ddim-d-1]-
myDomain->lowerBound()[ddim-d-1];
474 for(d=0; d<ddim; d++)
476 status = H5Sselect_hyperslab(
dataspace, H5S_SELECT_SET, offset, NULL, count, NULL);
479 trace.
error() <<
" H5Sselect_hyperslab from dataspace error" << std::endl;
484 for(d=0; d<ddim; d++)
486 memspace = H5Screate_simple(ddim,dimsm,NULL);
489 for(d=0; d<ddim; d++)
491 for(d=0; d<ddim; d++)
492 count_in[d] = N_SUB[d];
493 status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_in, NULL, count_in, NULL);
496 trace.
error() <<
" H5Sselect_hyperslab from memspace error" << std::endl;
501 typename TSpace::Point a, b;
502 for(d=0; d<ddim; d++)
504 a[d]=offset[ddim-d-1]+
myDomain->lowerBound()[d];
505 b[d]=a[d]+N_SUB[ddim-d-1]-1;
509 std::vector<typename TSpace::Dimension> v(ddim);
510 for(d=0; d<ddim; d++)
519 data_in[ p++ ] = outputImage->operator()((*it));
527 trace.
error() <<
" H5DSpecializations/H5DwriteS error" << std::endl;
583 template <
typename TImageContainer>
592#include "DGtal/images/ImageFactoryFromHDF5.ih"
599#undef ImageFactoryFromHDF5_RECURSES
Iterator for HyperRectDomain.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & begin() const
ConstSubRange subRange(const std::vector< Dimension > &permutation) const
const ConstIterator & end() const
void setValue(const Point &aPoint, const Value &aValue)
const Domain & domain() const
Aim: implements a factory from an HDF5 file.
TImageContainer ImageContainer
Types copied from the container.
ImageFactoryFromHDF5 & operator=(const ImageFactoryFromHDF5 &other)
ImageFactoryFromHDF5(const ImageFactoryFromHDF5 &other)
OutputImage * requestImage(const Domain &aDomain)
Domain * myDomain
Alias on the image domain.
void flushImage(OutputImage *outputImage)
BOOST_CONCEPT_ASSERT((concepts::CBoundedNumber< Value >))
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
const std::string myFilename
HDF5 filename and datasetname.
const std::string myDataset
void detachImage(OutputImage *outputImage)
ImageContainer OutputImage
New types.
ImageContainer::Domain Domain
ImageFactoryFromHDF5< TImageContainer > Self
void selfDisplay(std::ostream &out) const
ImageFactoryFromHDF5(const std::string &aFilename, const std::string &aDataset)
const Domain & domain() const
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
boost::uint8_t uint8_t
unsigned 8-bit integer.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
boost::int32_t int32_t
signed 32-bit integer.
TImageFactory ImageFactory
static int H5DwriteS(ImageFactory &anImageFactory, hid_t memspace, Value *data_in)
static int H5DreadS(ImageFactory &anImageFactory, hid_t memspace, Value *data_out)
ImageFactory::OutputImage::Value Value
TImageFactory ImageFactory
ImageFactory::OutputImage::Value Value
static int H5DreadS(ImageFactory &anImageFactory, hid_t memspace, Value *data_out)
static int H5DwriteS(ImageFactory &anImageFactory, hid_t memspace, Value *data_in)
TImageFactory ImageFactory
ImageFactory::OutputImage::Value Value
static int H5DreadS(ImageFactory &anImageFactory, hid_t memspace, Value *data_out)
static int H5DwriteS(ImageFactory &anImageFactory, hid_t memspace, Value *data_in)
static int H5DreadS(ImageFactory &anImageFactory, hid_t memspace, Value *data_out)
static int H5DwriteS(ImageFactory &anImageFactory, hid_t memspace, Value *data_in)
ImageFactory::OutputImage::Value Value
TImageFactory ImageFactory
Aim: implements HDF5 reading and writing for specialized type T.
ImageFactory::OutputImage::Value Value
static int H5DwriteS(ImageFactory &anImageFactory, hid_t memspace, Value *data_in)
static int H5DreadS(ImageFactory &anImageFactory, hid_t memspace, Value *data_out)
TImageFactory ImageFactory
ConstIterator end() const
ConstIterator begin() const
Aim: The concept CBoundedNumber specifies what are the bounded numbers. Models of this concept should...
Aim: Defines the concept describing a read/write image, having an output iterator.
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer