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

`#include <FieldMappingIO.h>`

Inheritance diagram for FrustumFieldMappingIO:

## Public Types

typedef FrustumFieldMappingIO | class_type
typedef boost::intrusive_ptr< FrustumFieldMappingIO > | 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.
| FrustumFieldMappingIO ()
| Ctor.
virtual FieldMapping::Ptr | read (const OgIGroup &mappingGroup)
| Reads the field mapping and tries to create a FrustumFieldMapping object from it.
virtual FieldMapping::Ptr | read (hid_t mappingGroup)
| Reads the field mapping and tries to create a FrustumFieldMapping 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 FrustumFieldMapping object

Definition at line 282 of file FieldMappingIO.h.

## Member Typedef Documentation

## Ptr

typedef boost::intrusive_ptr<FrustumFieldMappingIO> FrustumFieldMappingIO::Ptr

Definition at line 289 of file FieldMappingIO.h.

## class_type

typedef FrustumFieldMappingIO FrustumFieldMappingIO::class_type

Definition at line 293 of file FieldMappingIO.h.

## base

typedef FieldMappingIO FrustumFieldMappingIO::base

private

Convenience typedef for referring to base class.

Definition at line 339 of file FieldMappingIO.h.

## Constructor & Destructor Documentation

## FrustumFieldMappingIO()

FrustumFieldMappingIO::FrustumFieldMappingIO | ( |  | ) |

inline

Ctor.

Definition at line 304 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 * FrustumFieldMappingIO::staticClassType | ( |  | ) |

inline static

Definition at line 296 of file FieldMappingIO.h.

{
return "FrustumFieldMappingIO";
}

## create()

FieldMappingIO::Ptr FrustumFieldMappingIO::create | ( |  | ) |

inline static

Definition at line 308 of file FieldMappingIO.h.

{ return Ptr(new FrustumFieldMappingIO); }
FrustumFieldMappingIO::FrustumFieldMappingIO
FrustumFieldMappingIO()
Ctor.
Definition FieldMappingIO.h:304
FrustumFieldMappingIO::Ptr
boost::intrusive_ptr< FrustumFieldMappingIO > Ptr
Definition FieldMappingIO.h:289

References FrustumFieldMappingIO().

Referenced by initIO().

## read() [1/2]

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

virtual

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

Returns
  Null pointer if no object was read

Implements FieldMappingIO.

Definition at line 344 of file FieldMappingIO.cpp.

{
float time;
M44d ssMtx, csMtx;
int numSamples=0;
FrustumFieldMapping::Ptr fm(new FrustumFieldMapping);
// Read number of time samples
try {
if (!readAttribute(mappingGroup, k_frustumMappingNumSamples, 1, numSamples)) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " +
k_frustumMappingNumSamples);
return FieldMapping::Ptr();
}
} catch (...) {
//do nothing
}
// Read each time sample
for (int i = 0; i < numSamples; ++i) {
string timeAttr = k_frustumMappingTime + boost::lexical_cast<string>(i);
string ssAttr = k_frustumMappingScreenMatrix + boost::lexical_cast<string>(i);
string csAttr = k_frustumMappingCameraMatrix + 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, ssAttr, attrSize, ssMtx.x[0][0])) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + ssAttr);
return FieldMapping::Ptr();
}
if (!readAttribute(mappingGroup, csAttr, attrSize, csMtx.x[0][0])) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + csAttr);
return FieldMapping::Ptr();
}
fm->setTransforms(time, ssMtx, csMtx);
}
// Read Z distribution
int distInt;
FrustumFieldMapping::ZDistribution dist;
try {
if (!readAttribute(mappingGroup, k_frustumMappingZDistribution, 1, distInt)) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " +
k_frustumMappingZDistribution);
return FieldMapping::Ptr();
}
dist = static_cast<FrustumFieldMapping::ZDistribution>(distInt);
} catch (...) {
dist = FrustumFieldMapping::PerspectiveDistribution;
}
fm->setZDistribution(dist);
return fm;
}
M44d
Imath::M44d M44d
Definition SpiMathLib.h:82
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92
FrustumFieldMapping::ZDistribution
ZDistribution
Enumerates the Z slice distribution. .f3d files will store values as an int, so be very careful not t...
Definition FieldMapping.h:585
FrustumFieldMapping::PerspectiveDistribution
@ PerspectiveDistribution
Definition FieldMapping.h:586
FrustumFieldMapping::Ptr
boost::intrusive_ptr< FrustumFieldMapping > Ptr
Convenience typedef.
Definition FieldMapping.h:571
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 FrustumFieldMapping::PerspectiveDistribution, Msg::print(), Hdf5Util::readAttribute(), and Msg::SevWarning.

## read() [2/2]

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

virtual

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

Returns
  Null pointer if no object was read

Implements FieldMappingIO.

Definition at line 414 of file FieldMappingIO.cpp.

{
int numSamples = 0;
FrustumFieldMapping::Ptr fm(new FrustumFieldMapping);
// Read number of time samples
try {
OgIAttribute<int> numSamplesAttr =
mappingGroup.findAttribute<int>(k_frustumMappingNumSamples);
if (!numSamplesAttr.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " +
k_frustumMappingNumSamples);
return FieldMapping::Ptr();
}
} catch (...) {
//do nothing
}
// Read each time sample
for (int i = 0; i < numSamples; ++i) {
// Attribute names
string timeAttr = k_frustumMappingTime + boost::lexical_cast<string>(i);
string ssAttr = k_frustumMappingScreenMatrix + boost::lexical_cast<string>(i);
string csAttr = k_frustumMappingCameraMatrix + boost::lexical_cast<string>(i);
// Read time
OgIAttribute<float> time =
mappingGroup.findAttribute<float>(timeAttr);
if (!time.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + timeAttr);
return FieldMapping::Ptr();
}
// Read matrices
OgIAttribute<mtx64_t> ssMtx =
mappingGroup.findAttribute<mtx64_t>(ssAttr);
OgIAttribute<mtx64_t> csMtx =
mappingGroup.findAttribute<mtx64_t>(csAttr);
if (!ssMtx.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + ssAttr);
return FieldMapping::Ptr();
}
if (!csMtx.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " + csAttr);
return FieldMapping::Ptr();
}
fm->setTransforms(time.value(), ssMtx.value(), csMtx.value());
}
// Read Z distribution
FrustumFieldMapping::ZDistribution dist;
try {
OgIAttribute<int> zDist =
mappingGroup.findAttribute<int>(k_frustumMappingZDistribution);
if (!zDist.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't read attribute " +
k_frustumMappingZDistribution);
return FieldMapping::Ptr();
}
dist = static_cast<FrustumFieldMapping::ZDistribution>(zDist.value());
} catch (...) {
dist = FrustumFieldMapping::PerspectiveDistribution;
}
fm->setZDistribution(dist);
return fm;
}
mtx64_t
Field3D::M44d mtx64_t
Definition Traits.h:95

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

## write() [1/2]

bool FrustumFieldMappingIO::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 491 of file FieldMappingIO.cpp.

{
typedef FrustumFieldMapping::MatrixCurve::SampleVec SampleVec;
FrustumFieldMapping::Ptr fm =
FIELD_DYNAMIC_CAST<FrustumFieldMapping>(mapping);
if (!fm) {
Msg::print(Msg::SevWarning, "Couldn't get FrustumFieldMapping from pointer");
return false;
}
// First write number of time samples
const SampleVec &ssSamples = fm->screenToWorldSamples();
const SampleVec &csSamples = fm->cameraToWorldSamples();
int numSamples = static_cast<int>(ssSamples.size());
if (!writeAttribute(mappingGroup, k_frustumMappingNumSamples, 1, numSamples)) {
Msg::print(Msg::SevWarning, "Couldn't add attribute " +
k_frustumMappingNumSamples);
return false;
}
// Then write each sample
for (int i = 0; i < numSamples; ++i) {
string timeAttr = k_frustumMappingTime + boost::lexical_cast<string>(i);
string ssAttr = k_frustumMappingScreenMatrix + boost::lexical_cast<string>(i);
string csAttr = k_frustumMappingCameraMatrix + boost::lexical_cast<string>(i);
if (!writeAttribute(mappingGroup, timeAttr, 1, ssSamples[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, ssAttr,attrSize,
ssSamples[i].second.x[0][0])) {
Msg::print(Msg::SevWarning, "Couldn't add attribute " + ssAttr);
return false;
}
if (!writeAttribute(mappingGroup, csAttr, attrSize,
csSamples[i].second.x[0][0])) {
Msg::print(Msg::SevWarning, "Couldn't add attribute " + csAttr);
return false;
}
}
// Write distribution type
int dist = static_cast<int>(fm->zDistribution());
if (!writeAttribute(mappingGroup, k_frustumMappingZDistribution, 1, dist)) {
Msg::print(Msg::SevWarning, "Couldn't add attribute " +
k_frustumMappingNumSamples);
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 FrustumFieldMappingIO::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 557 of file FieldMappingIO.cpp.

{
typedef FrustumFieldMapping::MatrixCurve::SampleVec SampleVec;
FrustumFieldMapping::Ptr fm =
FIELD_DYNAMIC_CAST<FrustumFieldMapping>(mapping);
if (!fm) {
Msg::print(Msg::SevWarning,
"Couldn't get FrustumFieldMapping from pointer");
return false;
}
// First write number of time samples ---
const SampleVec &ssSamples = fm->screenToWorldSamples();
const SampleVec &csSamples = fm->cameraToWorldSamples();
const int numSamples = static_cast<int>(ssSamples.size());
OgOAttribute<int> numSamplesAttr(mappingGroup, k_frustumMappingNumSamples,
numSamples);
// Then write each sample ---
for (int i = 0; i < numSamples; ++i) {
const string timeAttr = k_frustumMappingTime +
boost::lexical_cast<string>(i);
const string ssAttr = k_frustumMappingScreenMatrix +
boost::lexical_cast<string>(i);
const string csAttr = k_frustumMappingCameraMatrix +
boost::lexical_cast<string>(i);
OgOAttribute<float> time(mappingGroup, timeAttr, ssSamples[i].first);
OgOAttribute<mtx64_t> ss(mappingGroup, ssAttr, ssSamples[i].second);
OgOAttribute<mtx64_t> cs(mappingGroup, csAttr, csSamples[i].second);
}
// Write distribution type ---
int dist = static_cast<int>(fm->zDistribution());
OgOAttribute<int> zDist(mappingGroup, k_frustumMappingZDistribution, dist);
return true;
}

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

## className()

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

virtual

Returns the class name.

Implements FieldMappingIO.

Definition at line 605 of file FieldMappingIO.cpp.

{
return k_frustumMappingName;
}
FIELD3D_NAMESPACE_OPEN::k_frustumMappingName
const string k_frustumMappingName("FrustumFieldMapping")

## Member Data Documentation

## DEFINE_FIELD_RTTI_CONCRETE_CLASS

FrustumFieldMappingIO::DEFINE_FIELD_RTTI_CONCRETE_CLASS

Definition at line 294 of file FieldMappingIO.h.

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

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