MatrixFieldMappingIO Class Reference
Classes and functions used to implement this library » Field IO classes under-the-hood

`#include <FieldMappingIO.h>`

Inheritance diagram for MatrixFieldMappingIO:

## Public Types

typedef MatrixFieldMappingIO | class_type
typedef boost::intrusive_ptr< MatrixFieldMappingIO > | Ptr
Public Types inherited from FieldMappingIO
typedef FieldMappingIO | class_type
typedef boost::intrusive_ptr< FieldMappingIO > | Ptr
Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBase > | Ptr
typedef boost::weak_ptr< RefBase > | WeakPtr

## Public Member Functions

virtual std::string | className () const
| Returns the class name.
| MatrixFieldMappingIO ()
| Ctor.
virtual FieldMapping::Ptr | read (const OgIGroup &mappingGroup)
| Reads the field mapping and tries to create a MatrixFieldMapping object from it.
virtual FieldMapping::Ptr | read (hid_t mappingGroup)
| Reads the field mapping and tries to create a MatrixFieldMapping object from it.
virtual bool | write (hid_t mappingGroup, FieldMapping::Ptr mapping)
| Writes the given field mapping to disk.
virtual bool | write (OgOGroup &mappingGroup, FieldMapping::Ptr mapping)
| Writes the given field mapping to disk.
Public Member Functions inherited from FieldMappingIO
| FieldMappingIO ()
| Ctor.
virtual | ~FieldMappingIO ()
| Dtor.
Public Member Functions inherited from RefBase
void | ref () const
| Used by boost::intrusive_pointer.
size_t | refcnt ()
| Used by boost::intrusive_pointer.
void | unref () const
| Used by boost::intrusive_pointer.
WeakPtr | weakPtr () const
| RefBase ()
| RefBase (const RefBase &)
| Copy constructor.
RefBase & | operator= (const RefBase &)
| Assignment operator.
virtual | ~RefBase ()
| Destructor.
virtual bool | checkRTTI (const char *typenameStr)=0
| This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();.
bool | matchRTTI (const char *typenameStr)
| Performs a check to see if the given typename string matches this class' This needs to be implemented in -all- subclasses, even abstract ones.

## Static Public Member Functions

static FieldMappingIO::Ptr | create ()
static const char * | staticClassType ()
Static Public Member Functions inherited from FieldMappingIO
static const char * | staticClassType ()
| RTTI replacement.
static const char * | staticClassType ()

## Public Attributes

| DEFINE_FIELD_RTTI_CONCRETE_CLASS
Public Attributes inherited from FieldMappingIO
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS

## Private Types

typedef FieldMappingIO | base
| Convenience typedef for referring to base class.

## Detailed Description

Handles IO for a MatrixFieldMapping object

Definition at line 210 of file FieldMappingIO.h.

## Member Typedef Documentation

## Ptr

typedef boost::intrusive_ptr<MatrixFieldMappingIO> MatrixFieldMappingIO::Ptr

Definition at line 217 of file FieldMappingIO.h.

## class_type

typedef MatrixFieldMappingIO MatrixFieldMappingIO::class_type

Definition at line 221 of file FieldMappingIO.h.

## base

typedef FieldMappingIO MatrixFieldMappingIO::base

private

Convenience typedef for referring to base class.

Definition at line 267 of file FieldMappingIO.h.

## Constructor & Destructor Documentation

## MatrixFieldMappingIO()

MatrixFieldMappingIO::MatrixFieldMappingIO | ( |  | ) |

inline

Ctor.

Definition at line 232 of file FieldMappingIO.h.

: FieldMappingIO()
{ }
FieldMappingIO::FieldMappingIO
FieldMappingIO()
Ctor.
Definition FieldMappingIO.h:87

References FieldMappingIO::FieldMappingIO().

Referenced by create().

## Member Function Documentation

## staticClassType()

const char * MatrixFieldMappingIO::staticClassType | ( |  | ) |

inline static

Definition at line 224 of file FieldMappingIO.h.

{
return "MatrixFieldMappingIO";
}

## create()

FieldMappingIO::Ptr MatrixFieldMappingIO::create | ( |  | ) |

inline static

Definition at line 236 of file FieldMappingIO.h.

{ return Ptr(new MatrixFieldMappingIO); }
MatrixFieldMappingIO::MatrixFieldMappingIO
MatrixFieldMappingIO()
Ctor.
Definition FieldMappingIO.h:232
MatrixFieldMappingIO::Ptr
boost::intrusive_ptr< MatrixFieldMappingIO > Ptr
Definition FieldMappingIO.h:217

References MatrixFieldMappingIO().

Referenced by initIO().

## read() [1/2]

FieldMapping::Ptr MatrixFieldMappingIO::read | ( | hid_t | mappingGroup | ) |

virtual

Reads the field mapping and tries to create a MatrixFieldMapping object from it.

Returns
  Matrix if no object was read

Implements FieldMappingIO.

Definition at line 148 of file FieldMappingIO.cpp.

{
M44d mtx;
int numSamples=0;
MatrixFieldMapping::Ptr mm(new MatrixFieldMapping);
// For backward compatibility, we first try to read the non-time-varying
// mapping.
try {
readAttribute(mappingGroup, k_matrixMappingDataName, 16, mtx.x[0][0]);
mm->setLocalToWorld(mtx);
return mm;
}
catch (...) {
// Do nothing
}
// If we didn't find the non-time-varying matrix data then we attempt
// to read time samples
try {
if (!readAttribute(mappingGroup, k_matrixMappingNumSamples, 1, numSamples)) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " +
k_matrixMappingNumSamples);
return FieldMapping::Ptr();
}
} catch (...) {
//do nothing
}
for (int i = 0; i < numSamples; ++i) {
float time;
string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
if (!readAttribute(mappingGroup, timeAttr, 1, time)) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + timeAttr);
return FieldMapping::Ptr();
}
std::vector<unsigned int> attrSize;
attrSize.assign(2,4);
if (!readAttribute(mappingGroup, matrixAttr, attrSize, mtx.x[0][0])) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + matrixAttr);
return FieldMapping::Ptr();
}
mm->setLocalToWorld(time, mtx);
}
return mm;
}
M44d
Imath::M44d M44d
Definition SpiMathLib.h:82
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92
MatrixFieldMapping::Ptr
boost::intrusive_ptr< MatrixFieldMapping > Ptr
Convenience typedef.
Definition FieldMapping.h:341
Hdf5Util::readAttribute
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
Msg::SevWarning
@ SevWarning
Definition Log.h:68
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70

References Msg::print(), Hdf5Util::readAttribute(), and Msg::SevWarning.

## read() [2/2]

FieldMapping::Ptr MatrixFieldMappingIO::read | ( | const OgIGroup & | mappingGroup | ) |

virtual

Reads the field mapping and tries to create a MatrixFieldMapping object from it.

Returns
  Matrix if no object was read

Implements FieldMappingIO.

Definition at line 204 of file FieldMappingIO.cpp.

{
M44d mtx;
int numSamples = 0;
MatrixFieldMapping::Ptr mm(new MatrixFieldMapping);
try {
OgIAttribute<int> numSamplesAttr =
mappingGroup.findAttribute<int>(k_matrixMappingNumSamples);
if (!numSamplesAttr.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " +
k_matrixMappingNumSamples);
return FieldMapping::Ptr();
}
numSamples = numSamplesAttr.value();
} catch (...) {
//do nothing
}
for (int i = 0; i < numSamples; ++i) {
string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
// Read time
OgIAttribute<float32_t> time =
mappingGroup.findAttribute<float32_t>(timeAttr);
if (!time.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + timeAttr);
return FieldMapping::Ptr();
}
// Read matrix
OgIAttribute<mtx64_t> mtx =
mappingGroup.findAttribute<mtx64_t>(matrixAttr);
if (!mtx.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + matrixAttr);
return FieldMapping::Ptr();
}
mm->setLocalToWorld(time.value(), mtx.value());
}
return mm;
}
mtx64_t
Field3D::M44d mtx64_t
Definition Traits.h:95
float32_t
float float32_t
Definition Traits.h:87

References Msg::print(), and Msg::SevWarning.

## write() [1/2]

bool MatrixFieldMappingIO::write | ( | hid_t | mappingGroup,
|  | FieldMapping::Ptr | mapping )

virtual

Writes the given field mapping to disk.

Returns
  true if successful, otherwise false

Implements FieldMappingIO.

Definition at line 250 of file FieldMappingIO.cpp.

{
typedef MatrixFieldMapping::MatrixCurve::SampleVec SampleVec;
MatrixFieldMapping::Ptr mm =
FIELD_DYNAMIC_CAST<MatrixFieldMapping>(mapping);
if (!mm) {
Msg::print(Msg::SevWarning, "Couldn't get MatrixFieldMapping from pointer");
return false;
}
// First write number of time samples
const SampleVec &samples = mm->localToWorldSamples();
int numSamples = static_cast<int>(samples.size());
if (!writeAttribute(mappingGroup, k_matrixMappingNumSamples, 1, numSamples)) {
Msg::print(Msg::SevWarning, "Couldn't add attribute " +
k_matrixMappingNumSamples);
return false;
}
// Then write each sample
for (int i = 0; i < numSamples; ++i) {
string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
if (!writeAttribute(mappingGroup, timeAttr, 1, samples[i].first)) {
Msg::print(Msg::SevWarning, "Couldn't add attribute " + timeAttr);
return false;
}
std::vector<unsigned int> attrSize;
attrSize.assign(2,4);
if (!writeAttribute(mappingGroup, matrixAttr, attrSize,
samples[i].second.x[0][0])) {
Msg::print(Msg::SevWarning, "Couldn't add attribute " + matrixAttr);
return false;
}
}
return true;
}
FIELD_DYNAMIC_CAST
#define FIELD_DYNAMIC_CAST
Definition RefCount.h:271
Curve< Imath::M44d >::SampleVec
std::vector< Sample > SampleVec
Definition Curve.h:102
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.

References FIELD_DYNAMIC_CAST, Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

## write() [2/2]

bool MatrixFieldMappingIO::write | ( | OgOGroup & | mappingGroup,
|  | FieldMapping::Ptr | mapping )

virtual

Writes the given field mapping to disk.

Returns
  true if successful, otherwise false

Implements FieldMappingIO.

Definition at line 297 of file FieldMappingIO.cpp.

{
typedef MatrixFieldMapping::MatrixCurve::SampleVec SampleVec;
MatrixFieldMapping::Ptr mm =
FIELD_DYNAMIC_CAST<MatrixFieldMapping>(mapping);
if (!mm) {
Msg::print(Msg::SevWarning, "Couldn't get MatrixFieldMapping from pointer");
return false;
}
// First write number of time samples
const SampleVec &samples = mm->localToWorldSamples();
const int numSamples = static_cast<int>(samples.size());
OgOAttribute<int> numSamplesAttr(mappingGroup, k_matrixMappingNumSamples,
numSamples);
// Then write each sample
for (int i = 0; i < numSamples; ++i) {
// Attribute names
const string timeAttr =
k_matrixMappingTime + boost::lexical_cast<string>(i);
const string matrixAttr =
k_matrixMappingMatrix + boost::lexical_cast<string>(i);
OgOAttribute<float32_t> time(mappingGroup, timeAttr, samples[i].first);
OgOAttribute<mtx64_t> mtx (mappingGroup, matrixAttr, samples[i].second);
}
return true;
}

References FIELD_DYNAMIC_CAST, Msg::print(), and Msg::SevWarning.

## className()

std::string MatrixFieldMappingIO::className | ( |  | ) | const

virtual

Returns the class name.

Implements FieldMappingIO.

Definition at line 334 of file FieldMappingIO.cpp.

{
return k_matrixMappingName;
}
FIELD3D_NAMESPACE_OPEN::k_matrixMappingName
const string k_matrixMappingName("MatrixFieldMapping")

## Member Data Documentation

## DEFINE_FIELD_RTTI_CONCRETE_CLASS

MatrixFieldMappingIO::DEFINE_FIELD_RTTI_CONCRETE_CLASS

Definition at line 222 of file FieldMappingIO.h.

The documentation for this class was generated from the following files:

- export/FieldMappingIO.h
- src/FieldMappingIO.cpp