48 using namespace boost;
60 using namespace Hdf5Util;
85 throw BadHdf5IdException(
"Bad layer group in DenseFieldIO::read");
88 if (!
readAttribute(layerGroup, k_versionAttrName, 1, version))
89 throw MissingAttributeException(
"Couldn't find attribute " +
92 if (version != k_versionNumber)
93 throw UnsupportedVersionException(
"DenseField version not supported: " +
94 lexical_cast<std::string>(version));
96 if (!
readAttribute(layerGroup, k_extentsStr, 6, extents.min.x))
97 throw MissingAttributeException(
"Couldn't find attribute " +
100 if (!
readAttribute(layerGroup, k_dataWindowStr, 6, dataW.min.x))
101 throw MissingAttributeException(
"Couldn't find attribute " +
104 if (!
readAttribute(layerGroup, k_componentsStr, 1, components))
105 throw MissingAttributeException(
"Couldn't find attribute " +
110 if (dataSet.
id() < 0)
111 throw OpenDataSetException(
"Couldn't open data set: " + k_dataStr);
115 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
117 if (dataSpace.id() < 0)
118 throw GetDataSpaceException(
"Couldn't get data space");
120 if (dataType.id() < 0)
121 throw GetDataTypeException(
"Couldn't get data type");
125 V3i size(dataW.size() +
V3i(1));
126 int calculatedTotal = size.x * size.y * size.z;
127 int reportedSize = dims[0] / components;
129 if (calculatedTotal != reportedSize)
130 throw FileIntegrityException(
"Data size doesn't match number of voxels");
137 bool isHalf, isFloat, isDouble;
138 isHalf = H5Tequal(dataType, H5T_NATIVE_SHORT);
139 isFloat = H5Tequal(dataType, H5T_NATIVE_FLOAT);
140 isDouble = H5Tequal(dataType, H5T_NATIVE_DOUBLE);
142 if (isHalf && components == 1 && typeEnum ==
DataTypeHalf)
143 result = readData<half>(dataSet.
id(), extents, dataW);
145 result = readData<float>(dataSet.
id(), extents, dataW);
147 result = readData<double>(dataSet.
id(), extents, dataW);
149 result = readData<V3h>(dataSet.
id(), extents, dataW);
151 result = readData<V3f>(dataSet.
id(), extents, dataW);
153 result = readData<V3d>(dataSet.
id(), extents, dataW);
163 if (layerGroup == -1)
164 throw BadHdf5IdException(
"Bad layer group in DenseFieldIO::write");
169 throw WriteAttributeException(
"Couldn't write attribute " +
188 success = writeInternal<float>(layerGroup, floatField);
190 else if (halfField) {
191 success = writeInternal<half>(layerGroup, halfField);
193 else if (doubleField) {
194 success = writeInternal<double>(layerGroup, doubleField);
196 else if (vecFloatField) {
197 success = writeInternal<V3f>(layerGroup, vecFloatField);
199 else if (vecHalfField) {
200 success = writeInternal<V3h>(layerGroup, vecHalfField);
202 else if (vecDoubleField) {
203 success = writeInternal<V3d>(layerGroup, vecDoubleField);
206 throw WriteLayerException(
"DenseFieldIO does not support the given "
207 "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...
Scoped object - opens a dataset on creation and closes it on destruction.
static const std::string k_versionAttrName
#define FIELD3D_NAMESPACE_SOURCE_CLOSE
static const std::string k_dataWindowStr
Scoped object - opens a dataset on creation and closes it on destruction.
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_dataStr
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
static const std::string k_componentsStr
bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
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.
#define FIELD3D_NAMESPACE_OPEN