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");