48 using namespace boost;
83 const std::string &layerPath,
90 throw BadHdf5IdException(
"Bad layer group in MIPFieldIO::read");
93 if (!
readAttribute(layerGroup, k_versionAttrName, 1, version))
94 throw MissingAttributeException(
"Couldn't find attribute " +
97 if (version != k_versionNumber)
98 throw UnsupportedVersionException(
"MIPField version not supported: " +
99 lexical_cast<std::string>(version));
101 if (!
readAttribute(layerGroup, k_componentsStr, 1, components))
102 throw MissingAttributeException(
"Couldn't find attribute " +
108 if (!
readAttribute(layerGroup, k_bitsPerComponentStr, 1, bits))
109 throw MissingAttributeException(
"Couldn't find attribute: " +
110 k_bitsPerComponentStr);
112 std::string baseType;
114 throw MissingAttributeException(
"Couldn't find attribute: " +
119 bool isFloat =
false;
120 bool isDouble =
false;
134 bool isSparse =
false;
135 bool isDense =
false;
137 if (baseType ==
"SparseField") {
139 }
else if (baseType ==
"DenseField") {
147 if (isDense && isHalf && components == 1 && typeEnum ==
DataTypeHalf)
148 result = readInternal<DenseField, half>(layerGroup, filename,
149 layerPath, typeEnum);
150 if (isDense && isFloat && components == 1 && typeEnum ==
DataTypeFloat)
151 result = readInternal<DenseField, float>(layerGroup, filename,
152 layerPath, typeEnum);
153 if (isDense && isDouble && components == 1 && typeEnum ==
DataTypeDouble)
154 result = readInternal<DenseField, double>(layerGroup, filename,
155 layerPath, typeEnum);
156 if (isDense && isHalf && components == 3 && typeEnum ==
DataTypeVecHalf)
157 result = readInternal<DenseField, V3h>(layerGroup, filename,
158 layerPath, typeEnum);
160 result = readInternal<DenseField, V3f>(layerGroup, filename,
161 layerPath, typeEnum);
163 result = readInternal<DenseField, V3d>(layerGroup, filename,
164 layerPath, typeEnum);
165 if (isSparse && isHalf && components == 1 && typeEnum ==
DataTypeHalf)
166 result = readInternal<SparseField, half>(layerGroup, filename,
167 layerPath, typeEnum);
168 if (isSparse && isFloat && components == 1 && typeEnum ==
DataTypeFloat)
169 result = readInternal<SparseField, float>(layerGroup, filename,
170 layerPath, typeEnum);
171 if (isSparse && isDouble && components == 1 && typeEnum ==
DataTypeDouble)
172 result = readInternal<SparseField, double>(layerGroup, filename,
173 layerPath, typeEnum);
174 if (isSparse && isHalf && components == 3 && typeEnum ==
DataTypeVecHalf)
175 result = readInternal<SparseField, V3h>(layerGroup, filename,
176 layerPath, typeEnum);
178 result = readInternal<SparseField, V3f>(layerGroup, filename,
179 layerPath, typeEnum);
181 result = readInternal<SparseField, V3d>(layerGroup, filename,
182 layerPath, typeEnum);
192 if (layerGroup == -1) {
193 throw BadHdf5IdException(
"Bad layer group in MIPFieldIO::write");
198 1, k_versionNumber)) {
199 throw WriteAttributeException(
"Couldn't write attribute " +
230 if (floatDenseField) {
231 success = writeInternal<DenseField, float>(layerGroup, floatDenseField);
233 else if (halfDenseField) {
234 success = writeInternal<DenseField, half>(layerGroup, halfDenseField);
236 else if (doubleDenseField) {
237 success = writeInternal<DenseField, double>(layerGroup, doubleDenseField);
239 else if (vecFloatDenseField) {
240 success = writeInternal<DenseField, V3f>(layerGroup, vecFloatDenseField);
242 else if (vecHalfDenseField) {
243 success = writeInternal<DenseField, V3h>(layerGroup, vecHalfDenseField);
245 else if (vecDoubleDenseField) {
246 success = writeInternal<DenseField, V3d>(layerGroup, vecDoubleDenseField);
248 else if (floatSparseField) {
249 success = writeInternal<SparseField, float>(layerGroup, floatSparseField);
251 else if (halfSparseField) {
252 success = writeInternal<SparseField, half>(layerGroup, halfSparseField);
254 else if (doubleSparseField) {
255 success = writeInternal<SparseField, double>(layerGroup, doubleSparseField);
257 else if (vecFloatSparseField) {
258 success = writeInternal<SparseField, V3f>(layerGroup, vecFloatSparseField);
260 else if (vecHalfSparseField) {
261 success = writeInternal<SparseField, V3h>(layerGroup, vecHalfSparseField);
263 else if (vecDoubleSparseField) {
264 success = writeInternal<SparseField, V3d>(layerGroup, vecDoubleSparseField);
267 throw WriteLayerException(
"MIPFieldIO does not support the given " 268 "MIPField template parameter");
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.
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.
Contains the MIPFieldIO class.
static const std::string k_dataWindowStr
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
boost::intrusive_ptr< FieldBase > Ptr
static const std::string k_levelsStr
static const std::string k_baseTypeStr
This subclass stores a MIP representation of a Field_T field.
static const std::string k_levelGroupStr
static const std::string k_mipGroupStr
static const std::string k_extentsStr
static const std::string k_versionAttrName
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 MIPField object from it. Calls out to readData() for template-specific work.
static const std::string k_componentsStr
boost::intrusive_ptr< FieldIO > Ptr
static const std::string k_bitsPerComponentStr
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...
static const int k_versionNumber