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>
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>
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 This subclass of Field stores data in a contiguous std::vector.
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Contains utility functions and classes for Hdf5 files.
static const std::string k_versionAttrName
DenseField< Data_T >::Ptr readData(hid_t dataSet, const Box3i &extents, const Box3i &dataW)
This call performs the actual reading of data from disk.
const FIELD3D_VEC3_T< size_t > & internalMemSize() const
Returns the internal memory size in each dimension. This is used for example in LinearInterpolator, where it optimizes random access to voxels.
Contains the Field3DFile classesOSS sanitized.
Contains the DenseField class.
DEFINE_FIELD_RTTI_CONCRETE_CLASS
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
static const std::string k_dataWindowStr
static const char * classType()
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
iterator begin()
Iterator to first element.
static const int k_versionNumber
boost::intrusive_ptr< FieldBase > Ptr
static std::string name()
Contains various utility functions for Hdf5.
static const std::string k_extentsStr
static FieldIO::Ptr create()
void setSize(const V3i &size)
Resizes the object.
bool writeData(hid_t dataSet, typename DenseField< Data_T >::Ptr field, Data_T dummy)
This call performs the actual writing of data to disk.
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
static const std::string k_dataStr
bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
boost::intrusive_ptr< DenseFieldIO > Ptr
static const std::string k_componentsStr
bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
virtual std::string className() const
Returns the class name.
virtual FieldBase::Ptr read(hid_t layerGroup, const std::string &filename, const std::string &layerPath, DataTypeEnum typeEnum)
Reads the field at the given location and tries to create a DenseField object from it...
FieldIO base
Convenience typedef for referring to base class.
Scoped object - creates a dataspace on creation and closes it on destruction.
boost::intrusive_ptr< DenseField > Ptr
bool writeInternal(hid_t layerGroup, typename DenseField< Data_T >::Ptr field)
This call writes all the attributes and sets up the data space.
Scoped object - creates a dataset on creation and closes it on destruction.
boost::intrusive_ptr< FieldIO > Ptr
hid_t id() const
Query the hid_t value.
virtual bool write(hid_t layerGroup, FieldBase::Ptr field)
Writes the given field to disk. This function calls out to writeInternal once the template type has b...
virtual ~DenseFieldIO()
Dtor.
Contains Exception base class.