48 using namespace boost;
86 throw BadHdf5IdException(
"Bad layer group in DenseFieldIO::read");
89 if (!
readAttribute(layerGroup, k_versionAttrName, 1, version))
90 throw MissingAttributeException(
"Couldn't find attribute " +
93 if (version != k_versionNumber)
94 throw UnsupportedVersionException(
"DenseField version not supported: " +
95 lexical_cast<std::string>(version));
97 if (!
readAttribute(layerGroup, k_extentsStr, 6, extents.min.x))
98 throw MissingAttributeException(
"Couldn't find attribute " +
101 if (!
readAttribute(layerGroup, k_dataWindowStr, 6, dataW.min.x))
102 throw MissingAttributeException(
"Couldn't find attribute " +
105 if (!
readAttribute(layerGroup, k_componentsStr, 1, components))
106 throw MissingAttributeException(
"Couldn't find attribute " +
111 if (dataSet.
id() < 0)
112 throw OpenDataSetException(
"Couldn't open data set: " + k_dataStr);
116 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
118 if (dataSpace.id() < 0)
119 throw GetDataSpaceException(
"Couldn't get data space");
121 if (dataType.id() < 0)
122 throw GetDataTypeException(
"Couldn't get data type");
126 V3i size(dataW.size() +
V3i(1));
127 int calculatedTotal = size.x * size.y * size.z;
128 int reportedSize = dims[0] / components;
130 if (calculatedTotal != reportedSize)
131 throw FileIntegrityException(
"Data size doesn't match number of voxels");
138 bool isHalf, isFloat, isDouble;
139 isHalf = H5Tequal(dataType, H5T_NATIVE_SHORT);
140 isFloat = H5Tequal(dataType, H5T_NATIVE_FLOAT);
141 isDouble = H5Tequal(dataType, H5T_NATIVE_DOUBLE);
143 if (isHalf && components == 1 && typeEnum ==
DataTypeHalf)
144 result = readData<half>(dataSet.
id(), extents, dataW);
146 result = readData<float>(dataSet.
id(), extents, dataW);
148 result = readData<double>(dataSet.
id(), extents, dataW);
150 result = readData<V3h>(dataSet.
id(), extents, dataW);
152 result = readData<V3f>(dataSet.
id(), extents, dataW);
154 result = readData<V3d>(dataSet.
id(), extents, dataW);
164 if (layerGroup == -1)
165 throw BadHdf5IdException(
"Bad layer group in DenseFieldIO::write");
170 throw WriteAttributeException(
"Couldn't write attribute " +
189 success = writeInternal<float>(layerGroup, floatField);
191 else if (halfField) {
192 success = writeInternal<half>(layerGroup, halfField);
194 else if (doubleField) {
195 success = writeInternal<double>(layerGroup, doubleField);
197 else if (vecFloatField) {
198 success = writeInternal<V3f>(layerGroup, vecFloatField);
200 else if (vecHalfField) {
201 success = writeInternal<V3h>(layerGroup, vecHalfField);
203 else if (vecDoubleField) {
204 success = writeInternal<V3d>(layerGroup, vecDoubleField);
207 throw WriteLayerException(
"DenseFieldIO does not support the given " 208 "DenseField template parameter");
This subclass of Field stores data in a contiguous std::vector.
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Contains utility functions and classes for Hdf5 files.
Scoped object - opens a dataset on creation and closes it on destruction.
static const std::string k_versionAttrName
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
#define FIELD3D_NAMESPACE_SOURCE_CLOSE
Namespace for Exception objects.
static const std::string k_dataWindowStr
Scoped object - opens a dataset on creation and closes it on destruction.
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
static const int k_versionNumber
boost::intrusive_ptr< FieldBase > Ptr
static const std::string k_extentsStr
Contains the DenseFieldIO class.
static const std::string k_bitsPerComponentStr
static const std::string k_dataStr
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...
boost::intrusive_ptr< DenseField > Ptr
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...
Scoped object - opens a dataset on creation and closes it on destruction.
hid_t id() const
Query the hid_t value.