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>
170 template <
class Data_T>
185 hsize_t totalSize[1];
186 totalSize[0] = size[0] * size[1] * size[2] * components;
189 hsize_t preferredChunkSize = 4096 * 16;
190 const hsize_t chunkSize = std::min(preferredChunkSize, totalSize[0] / 2);
197 { ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
200 throw WriteAttributeException(
"Couldn't write attribute " +
k_extentsStr);
206 { dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
209 throw WriteAttributeException(
"Couldn't write attribute " +
k_dataWindowStr);
215 throw WriteAttributeException(
"Couldn't write attribute " +
k_componentsStr);
230 if (dataSpace.
id() < 0) {
231 throw CreateDataSpaceException(
"Couldn't create data space in " 232 "DenseFieldIO::writeInternal");
237 H5Sset_extent_simple(dataSpace.
id(), 1, totalSize, NULL);
241 hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
243 herr_t status = H5Pset_deflate(dcpl, 9);
247 status = H5Pset_chunk(dcpl, 1, &chunkSize);
256 H5P_DEFAULT, dcpl, H5P_DEFAULT);
258 if (dataSet.id() < 0) {
259 throw CreateDataSetException(
"Couldn't create data set in " 260 "DenseFieldIO::writeInternal");
265 if (!writeData<Data_T>(dataSet.id(), field, Data_T(0.0f))) {
266 throw WriteLayerException(
"Error writing layer");
274 template <
class Data_T>
281 hid_t err = H5Dwrite(dataSet,
284 H5P_DEFAULT, &(*field->
begin()));
287 throw Exc::WriteLayerException(
"Error writing layer in " 288 "DenseFieldIO::writeData");
296 template <
class Data_T>
301 field->
setSize(extents, dataW);
304 H5S_ALL, H5S_ALL, H5P_DEFAULT, &(*field->
begin())) < 0)
306 std::string typeName =
"DenseField<" +
308 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
320 #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
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
DenseField< Data_T >::Ptr readData(hid_t dataSet, const Box3i &extents, const Box3i &dataW)
This call performs the actual reading of data from disk.
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
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
iterator begin()
Iterator to first element.
static const int k_versionNumber
boost::intrusive_ptr< FieldBase > Ptr
static std::string name()
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Contains various utility functions for Hdf5.
static const std::string k_extentsStr
static FieldIO::Ptr create()
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.
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.
static const std::string k_bitsPerComponentStr
static const std::string k_dataStr
static const char * staticClassType()
FIELD3D_API bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
boost::intrusive_ptr< DenseFieldIO > Ptr
static const std::string k_componentsStr
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.
virtual std::string className() const
Returns the class name.
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
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
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.
hid_t id() const
Query the hid_t value.