44 #ifndef _INCLUDED_Field3D_MIPFieldIO_H_ 45 #define _INCLUDED_Field3D_MIPFieldIO_H_ 51 #include <boost/intrusive_ptr.hpp> 52 #include <boost/thread/mutex.hpp> 85 typedef boost::intrusive_ptr<MIPFieldIO>
Ptr;
117 const std::string &filename,
118 const std::string &layerPath,
128 {
return "MIPField"; }
135 template <
template <
typename X>
class Field_T,
class Data_T>
137 typename MIPField<Field_T<Data_T> >::Ptr field);
139 template <
template <
typename X>
class Field_T,
class Data_T>
141 readInternal(hid_t layerGroup,
const std::string &filename,
172 template <
typename Field_T>
176 template <
typename Data_T>
183 template <
typename Data_T>
195 template <
class Field_T>
203 typedef boost::shared_ptr<GenericLazyLoadAction<Field_T> >
Ptr;
204 typedef std::vector<Ptr>
Vec;
209 const std::string &path,
212 m_filename(filename), m_path(path), m_typeEnum(typeEnum)
222 virtual typename Field_T::Ptr
load()
const 227 boost::shared_ptr<H5ScopedGopen> levelGroup;
234 file = H5Fopen(m_filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
236 throw Exc::NoSuchFileException(m_filename);
252 if (H5Fclose(file) < 0) {
253 Msg::print(
"Error closing file: " + m_filename);
280 template <
template <
typename X>
class Field_T,
class Data_T>
287 Box3i ext(field->extents()), dw(field->dataWindow());
292 { ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
295 throw WriteAttributeException(
"Couldn't write attribute " +
k_extentsStr);
301 { dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
304 throw WriteAttributeException(
"Couldn't write attribute " +
k_dataWindowStr);
312 throw WriteAttributeException(
"Couldn't write attribute " +
k_componentsStr);
325 std::string baseType = Field_T<Data_T>::staticClassName();
327 throw WriteAttributeException(
"Couldn't write attribute " +
k_baseTypeStr);
335 int numLevels = field->numLevels();
337 throw WriteAttributeException(
"Couldn't write attribute " +
k_levelsStr);
342 for (
size_t i = 0; i < field->numLevels(); i++) {
346 boost::lexical_cast<std::string>(i));
349 std::string
className = Field_T<Data_T>::staticClassName();
352 io->write(levelGroup, field->mipLevel(i));
361 template <
template <
typename X>
class Field_T,
class Data_T>
364 const std::string &filename,
365 const std::string &layerPath,
378 throw MissingAttributeException(
"Couldn't find attribute " +
384 throw MissingAttributeException(
"Couldn't find attribute " +
390 throw MissingAttributeException(
"Couldn't find attribute " +
394 typename MIPType::Ptr result(
new typename MIPInstance<Field_T<Data_T> >::type);
402 throw MissingAttributeException(
"Couldn't find attribute " +
k_levelsStr);
406 std::vector<typename EmptyField<Data_T>::Ptr> proxies;
409 for (
int i = 0; i < numLevels; i++) {
411 std::string levelGroupStr =
418 throw MissingAttributeException(
"Couldn't find attribute " +
422 throw MissingAttributeException(
"Couldn't find attribute " +
425 proxy->
setSize(extents, dataW);
426 proxies.push_back(proxy);
428 std::string fullPath =
430 typename Action::Ptr action(
new Action(filename, fullPath, typeEnum));
431 actions.push_back(action);
434 result->setupLazyLoad(proxies, actions);
443 template <
typename Field_T>
452 #endif // Include guard This subclass of Field stores data in a contiguous std::vector.
virtual std::string className() const
Returns the class name.
const std::string m_path
Path in file.
#define FIELD3D_NAMESPACE_HEADER_CLOSE
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.
Contains the Field3DFile classesOSS sanitized.
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
MIPSparseField< Data_T > type
static const std::string k_dataWindowStr
static boost::mutex ms_hdf5Mutex
HDF5 access mutex.
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
boost::intrusive_ptr< FieldBase > Ptr
virtual Field_T::Ptr load() const
Performs the loading of the pre-determined field and returns a pointer to it.
static ClassFactory & singleton()
}
static const std::string k_levelsStr
boost::recursive_mutex::scoped_lock GlobalLock
static const std::string k_baseTypeStr
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
This subclass stores a MIP representation of a Field_T field.
boost::intrusive_ptr< MIPFieldIO > Ptr
Contains various utility functions for Hdf5.
Scoped object - creates a group on creation and closes it on destruction.
GenericLazyLoadAction(const std::string &filename, const std::string &path, const DataTypeEnum &typeEnum)
boost::shared_ptr< GenericLazyLoadAction< Field_T > > Ptr
static const std::string k_levelGroupStr
static const std::string k_mipGroupStr
void setSize(const V3i &size)
Resizes the object.
static const std::string k_extentsStr
static const std::string k_versionAttrName
static FieldIO::Ptr create()
static const char * staticClassType()
virtual ~MIPFieldIO()
Dtor.
This subclass of Field does not store any data.
We need to instantiate MIPSparseField rather than MIPField<SparseField>. This traits class does that...
MIPField< Field_T< Data_T > >::Ptr readInternal(hid_t layerGroup, const std::string &filename, const std::string &layerPath, DataTypeEnum typeEnum)
boost::intrusive_ptr< EmptyField > Ptr
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.
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
const std::string m_filename
Filename.
static const std::string k_componentsStr
const DataTypeEnum m_typeEnum
Data type enum.
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
MIPDenseField< Data_T > type
bool writeInternal(hid_t layerGroup, typename MIPField< Field_T< Data_T > >::Ptr field)
This call writes all the attributes and sets up the data space.
boost::intrusive_ptr< FieldIO > Ptr
static const std::string k_bitsPerComponentStr
This Field subclass stores voxel data in block-allocated arrays.
Scoped object - opens a group on creation and closes it on destruction.
Contains Exception base class.
DEFINE_FIELD_RTTI_CONCRETE_CLASS
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...
Contains the MIPField class.
static const int k_versionNumber
FieldIO base
Convenience typedef for referring to base class.