44 #ifndef _INCLUDED_Field3D_DenseFieldIO_H_
45 #define _INCLUDED_Field3D_DenseFieldIO_H_
51 #include <boost/intrusive_ptr.hpp>
85 typedef boost::intrusive_ptr<DenseFieldIO>
Ptr;
94 return "DenseFieldIO";
117 const std::string &layerPath,
127 {
return "DenseField"; }
134 template <
class Data_T>
139 template <
class Data_T>
144 template <
class Data_T>
169 template <
class Data_T>
174 using namespace Hdf5Util;
184 hsize_t totalSize[1];
185 totalSize[0] = size[0] * size[1] * size[2] * components;
188 hsize_t preferredChunkSize = 4096 * 16;
189 const hsize_t chunkSize = std::min(preferredChunkSize, totalSize[0] / 2);
196 { ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
199 throw WriteAttributeException(
"Couldn't write attribute " +
k_extentsStr);
205 { dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
208 throw WriteAttributeException(
"Couldn't write attribute " +
k_dataWindowStr);
214 throw WriteAttributeException(
"Couldn't write attribute " +
k_componentsStr);
221 if (dataSpace.
id() < 0) {
222 throw CreateDataSpaceException(
"Couldn't create data space in "
223 "DenseFieldIO::writeInternal");
228 H5Sset_extent_simple(dataSpace.
id(), 1, totalSize, NULL);
232 hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
234 herr_t status = H5Pset_deflate(dcpl, 9);
238 status = H5Pset_chunk(dcpl, 1, &chunkSize);
247 H5P_DEFAULT, dcpl, H5P_DEFAULT);
249 if (dataSet.id() < 0) {
250 throw CreateDataSetException(
"Couldn't create data set in "
251 "DenseFieldIO::writeInternal");
256 if (!writeData<Data_T>(dataSet.id(), field, Data_T(0.0f))) {
257 throw WriteLayerException(
"Error writing layer");
265 template <
class Data_T>
270 using namespace Hdf5Util;
272 hid_t err = H5Dwrite(dataSet,
275 H5P_DEFAULT, &(*field->
begin()));
278 throw Exc::WriteLayerException(
"Error writing layer in "
279 "DenseFieldIO::writeData");
287 template <
class Data_T>
292 field->
setSize(extents, dataW);
295 H5S_ALL, H5S_ALL, H5P_DEFAULT, &(*field->
begin())) < 0)
297 std::string typeName =
"DenseField<" +
299 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
311 #endif // Include guard