39 #include "DGtal/base/Common.h"
40 #include "DGtal/helpers/StdDefs.h"
44 #include "DGtal/images/ImageSelector.h"
45 #include "DGtal/images/ImageFactoryFromHDF5.h"
46 #include "DGtal/io/writers/VolWriter.h"
48 #include "ConfigExamples.h"
52 using namespace DGtal;
56 #define DATASETNAME_3D "UInt8Array3D"
59 bool raw2HDF5_3D(
char *rawFilename,
int sizeX,
int sizeY,
int sizeZ,
int sizeChunk,
char *HDF5Filename)
66 hid_t datatype, dataspace;
78 fd = fopen(rawFilename,
"rb");
84 trace.
info() <<
" open raw_file: " << rawFilename <<
" size_X: " << sizeX <<
" size_Y: " << sizeY <<
" size_Z: " << sizeZ <<
" size_CHUNK: " << sizeChunk << endl;
95 if (fread(data, 1, sizeZ*sizeY*sizeX, fd) != (
unsigned)sizeZ*sizeY*sizeX)
110 file = H5Fcreate(HDF5Filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
116 dataspace = H5Screate_simple(
RANK_3D, dimsf, NULL);
119 plist_id = H5Pcreate(H5P_DATASET_CREATE);
122 cdims[0] = sizeChunk;
123 cdims[1] = sizeChunk;
124 cdims[2] = sizeChunk;
125 status = H5Pset_chunk(plist_id,
RANK_3D, cdims);
128 trace.
error() <<
" H5Dchunck error" << std::endl;
140 status = H5Pset_deflate(plist_id, 6);
143 trace.
error() <<
" H5Ddeflate error" << std::endl;
152 datatype = H5Tcopy(H5T_NATIVE_UINT8);
153 status = H5Tset_order(datatype, H5T_ORDER_LE);
156 trace.
error() <<
" H5Dset_order error" << std::endl;
166 H5P_DEFAULT, plist_id, H5P_DEFAULT);
169 trace.
info() <<
" begin write hdf5_file: " << HDF5Filename << endl;
170 status = H5Dwrite(dataset, H5T_NATIVE_UINT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
173 trace.
error() <<
" H5Dwrite error" << std::endl;
178 trace.
info() <<
" end write hdf5_file" << endl;
208 typedef MyImageFactoryFromHDF5::OutputImage OutputImage;
210 OutputImage *volImage = factImage.requestImage( factImage.domain() );
212 factImage.detachImage(volImage);
222 int main(
int argc,
char** argv )
224 if (argc==7 || argc==8)
226 raw2HDF5_3D(argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), argv[6]);
233 trace.
info() <<
"A raw to HDF5 converter (first version, restriction: only 3D UInt8 data input file, HDF5 output file with ZLIB compression activated)" << endl;
234 trace.
info() <<
"Usage: raw2HDF5 <raw_file> <size_X> <size_Y> <size_Z> <size_CHUNK> <hdf5_file>" << endl;
Aim: implements a factory from an HDF5 file.
void beginBlock(const std::string &keyword="")
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 HDF5_3D2vol(char *HDF5Filename, char *volFileName)
bool raw2HDF5_3D(char *rawFilename, int sizeX, int sizeY, int sizeZ, int sizeChunk, char *HDF5Filename)
Aim: Export a 3D Image using the Vol formats.
ImageContainerBySTLVector< Domain, Value > Image