44 #include <boost/intrusive_ptr.hpp> 51 using namespace boost;
85 const std::string &layerPath,
94 if (layerGroup == -1) {
100 if (!
readAttribute(layerGroup, k_versionAttrName, 1, version))
101 throw MissingAttributeException(
"Couldn't find attribute: " +
104 if (version != k_versionNumber)
105 throw UnsupportedVersionException(
"SparseField version not supported: " +
106 lexical_cast<std::string>(version));
108 if (!
readAttribute(layerGroup, k_extentsStr, 6, extents.min.x))
109 throw MissingAttributeException(
"Couldn't find attribute: " +
112 if (!
readAttribute(layerGroup, k_dataWindowStr, 6, dataW.min.x))
113 throw MissingAttributeException(
"Couldn't find attribute: " +
116 if (!
readAttribute(layerGroup, k_componentsStr, 1, components))
117 throw MissingAttributeException(
"Couldn't find attribute: " +
121 if (!
readAttribute(layerGroup, k_blockOrderStr, 1, blockOrder))
122 throw MissingAttributeException(
"Couldn't find attribute: " +
126 if (!
readAttribute(layerGroup, k_numBlocksStr, 1, numBlocks))
127 throw MissingAttributeException(
"Couldn't find attribute: " +
131 if (!
readAttribute(layerGroup, k_blockResStr, 3, blockRes.x))
132 throw MissingAttributeException(
"Couldn't find attribute: " +
137 int numCalculatedBlocks = blockRes.x * blockRes.y * blockRes.z;
138 if (numCalculatedBlocks != numBlocks)
139 throw FileIntegrityException(
"Incorrect block count in SparseFieldIO::read");
146 if (!
readAttribute(layerGroup, k_numOccupiedBlocksStr, 1, occupiedBlocks))
147 throw MissingAttributeException(
"Couldn't find attribute: " +
148 k_numOccupiedBlocksStr);
153 if (!
readAttribute(layerGroup, k_bitsPerComponentStr, 1, bits))
154 throw MissingAttributeException(
"Couldn't find attribute: " +
155 k_bitsPerComponentStr);
158 bool isFloat =
false;
159 bool isDouble =
false;
175 if (components == 1) {
178 field->
setSize(extents, dataW);
180 readData<half>(layerGroup, numBlocks, filename, layerPath, field);
184 field->
setSize(extents, dataW);
186 readData<float>(layerGroup, numBlocks, filename, layerPath, field);
190 field->
setSize(extents, dataW);
192 readData<double>(layerGroup, numBlocks, filename, layerPath, field);
195 }
else if (components == 3) {
198 field->
setSize(extents, dataW);
200 readData<V3h>(layerGroup, numBlocks, filename, layerPath, field);
204 field->
setSize(extents, dataW);
206 readData<V3f>(layerGroup, numBlocks, filename, layerPath, field);
210 field->
setSize(extents, dataW);
212 readData<V3d>(layerGroup, numBlocks, filename, layerPath, field);
225 if (layerGroup == -1) {
232 1, k_versionNumber)) {
252 success = writeInternal<half>(layerGroup, halfField);
253 }
else if (floatField) {
254 success = writeInternal<float>(layerGroup, floatField);
255 }
else if (doubleField) {
256 success = writeInternal<double>(layerGroup, doubleField);
257 }
else if (vecHalfField) {
258 success = writeInternal<V3h>(layerGroup, vecHalfField);
259 }
else if (vecFloatField) {
260 success = writeInternal<V3f>(layerGroup, vecFloatField);
261 }
else if (vecDoubleField) {
262 success = writeInternal<V3d>(layerGroup, vecDoubleField);
264 throw WriteLayerException(
"SparseFieldIO::write does not support the given " 265 "SparseField 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.
Contains typedefs for the commonly used types in Field3D.
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_dataStr
static const std::string k_versionAttrName
virtual bool write(hid_t layerGroup, FieldBase::Ptr field)
Writes the given field to disk.
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_numOccupiedBlocksStr
static const std::string k_extentsStr
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
boost::intrusive_ptr< SparseField > Ptr
static const int k_versionNumber
void setSize(const V3i &size)
Resizes the object.
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 SparseField object from it...
static const std::string k_blockOrderStr
static const std::string k_numBlocksStr
static const std::string k_componentsStr
static const std::string k_blockResStr
void setBlockOrder(int order)
Sets the block order (i.e. the power-of-2 to use as block size.
Contains the SparseFieldIO class.
static const std::string k_bitsPerComponentStr
This Field subclass stores voxel data in block-allocated arrays.