44 #ifndef _INCLUDED_Field3D_MACFieldIO_H_ 45 #define _INCLUDED_Field3D_MACFieldIO_H_ 51 #include <boost/intrusive_ptr.hpp> 85 typedef boost::intrusive_ptr<MACFieldIO>
Ptr;
117 const std::string &layerPath,
126 {
return "MACField"; }
133 template <
class Data_T>
137 template <
class Data_T>
142 template <
class Data_T>
168 template <
class Data_T>
182 { ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
185 throw WriteAttributeException(
"Couldn't write attribute " +
k_extentsStr);
190 { dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
193 throw WriteAttributeException(
"Couldn't write attribute " +
k_dataWindowStr);
198 throw WriteAttributeException(
"Couldn't write attribute " +
k_componentsStr);
209 if (!writeData<Data_T>(layerGroup, field,
MACCompU)) {
210 throw WriteMACFieldDataException(
"Error writing u_data");
213 if (!writeData<Data_T>(layerGroup, field,
MACCompV)) {
214 throw WriteMACFieldDataException(
"Error writing v_data");
217 if (!writeData<Data_T>(layerGroup, field,
MACCompW)) {
218 throw WriteMACFieldDataException(
"Error writing w_data");
227 template <
class Data_T>
237 hsize_t totalSize[1];
242 totalSize[0] = compSize.x;
246 totalSize[0] = compSize.y;
250 totalSize[0] = compSize.z;
258 hsize_t preferredChunkSize = 4096 * 16;
259 const hsize_t chunkSize = std::min(preferredChunkSize, totalSize[0] / 2);
263 if (dataSpace.
id() < 0)
264 throw CreateDataSpaceException(
"Couldn't create data space in " 265 "MACFieldIO::writeData");
269 H5Sset_extent_simple(dataSpace.
id(), 1, totalSize, NULL);
273 hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
275 herr_t status = H5Pset_deflate(dcpl, 9);
279 status = H5Pset_chunk(dcpl, 1, &chunkSize);
288 H5P_DEFAULT, dcpl, H5P_DEFAULT);
290 if (dataSet.id() < 0)
291 throw CreateDataSetException(
"Couldn't create data set in " 292 "MACFieldIO::writeData");
294 hid_t err = H5Dwrite(dataSet,
299 throw Exc::WriteLayerException(
"Error writing layer in " 300 "MACFieldIO::writeData");
308 template <
class Data_T>
322 if (dataSet.
id() < 0)
323 throw OpenDataSetException(
"Couldn't open data set: " +
k_uDataStr);
327 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
329 if (dataSpace.id() < 0)
330 throw GetDataSpaceException(
"Couldn't get data space");
332 if (dataType.id() < 0)
333 throw GetDataTypeException(
"Couldn't get data type");
338 std::string typeName =
"MACField<" +
340 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
349 if (dataSet.
id() < 0)
350 throw OpenDataSetException(
"Couldn't open data set: " +
k_vDataStr);
354 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
356 if (dataSpace.id() < 0)
357 throw GetDataSpaceException(
"Couldn't get data space");
359 if (dataType.id() < 0)
360 throw GetDataTypeException(
"Couldn't get data type");
366 std::string typeName =
"MACField<" +
368 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
377 if (dataSet.
id() < 0)
378 throw OpenDataSetException(
"Couldn't open data set: " +
k_wDataStr);
382 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
384 if (dataSpace.id() < 0)
385 throw GetDataSpaceException(
"Couldn't get data space");
387 if (dataType.id() < 0)
388 throw GetDataTypeException(
"Couldn't get data type");
394 std::string typeName =
"MACField<" +
396 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
410 #endif // Include guard #define FIELD3D_NAMESPACE_HEADER_CLOSE
Contains utility functions and classes for Hdf5 files.
static const std::string k_vDataStr
Scoped object - opens a dataset on creation and closes it on destruction.
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
Contains the Field3DFile classesOSS sanitized.
Contains the MACField class.
virtual ~MACFieldIO()
Dtor.
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
mac_comp_iterator begin_comp(MACComponent comp)
Iterator to first element.
virtual std::string className() const
Returns the class name.
V3i getComponentSize() const
Returns the size of U,V,W components.
Scoped object - opens a dataset on creation and closes it on destruction.
boost::intrusive_ptr< FieldBase > Ptr
boost::intrusive_ptr< MACFieldIO > Ptr
static const std::string k_componentsStr
static std::string name()
static const std::string k_uDataStr
Contains various utility functions for Hdf5.
static const int k_versionNumber
static FieldIO::Ptr create()
boost::intrusive_ptr< MACField > Ptr
static const std::string k_wDataStr
FIELD3D_API bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
static const std::string k_extentsStr
bool writeInternal(hid_t layerGroup, typename MACField< Data_T >::Ptr field)
This call writes all the attributes and sets up the data space.
static const std::string k_versionAttrName
FieldIO base
Convenience typedef for referring to base class.
static const std::string k_dataWindowStr
static const std::string k_bitsPerComponentStr
Scoped object - creates a dataspace on creation and closes it on destruction.
virtual bool write(hid_t layerGroup, FieldBase::Ptr field)
Writes the given field to disk.
bool writeData(hid_t layerGroup, typename MACField< Data_T >::Ptr field, MACComponent comp)
This call writes out the u,v,w data.
DEFINE_FIELD_RTTI_CONCRETE_CLASS
Scoped object - creates a dataset on creation and closes it on destruction.
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 MACField object from it.
boost::intrusive_ptr< FieldIO > Ptr
const_mac_comp_iterator cbegin_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
Contains Exception base class.
static const char * staticClassType()
Scoped object - opens a dataset on creation and closes it on destruction.
hid_t id() const
Query the hid_t value.
bool readData(hid_t location, typename MACField< Data_T >::Ptr result)
Reads the data that is dependent on the data type on disk.