Field3D

#include <FieldMappingIO.h>

Inheritance diagram for MatrixFieldMappingIO:
FieldMappingIO RefBase

Public Types

typedef MatrixFieldMappingIO class_type
 
typedef boost::intrusive_ptr< MatrixFieldMappingIOPtr
 
- Public Types inherited from FieldMappingIO
typedef FieldMappingIO class_type
 
typedef boost::intrusive_ptr< FieldMappingIOPtr
 
- Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBasePtr
 
typedef boost::weak_ptr< RefBaseWeakPtr
 

Public Member Functions

virtual std::string className () const
 Returns the class name. More...
 
 MatrixFieldMappingIO ()
 Ctor. More...
 
virtual FieldMapping::Ptr read (hid_t mappingGroup)
 Reads the field mapping and tries to create a MatrixFieldMapping object from it. More...
 
virtual bool write (hid_t mappingGroup, FieldMapping::Ptr mapping)
 Writes the given field mapping to disk. More...
 
- Public Member Functions inherited from FieldMappingIO
 FieldMappingIO ()
 Ctor. More...
 
virtual ~FieldMappingIO ()
 Dtor. More...
 
- Public Member Functions inherited from RefBase
void ref () const
 Used by boost::intrusive_pointer. More...
 
size_t refcnt ()
 Used by boost::intrusive_pointer. More...
 
void unref () const
 Used by boost::intrusive_pointer. More...
 
WeakPtr weakPtr () const
 
 RefBase ()
 
 RefBase (const RefBase &)
 Copy constructor. More...
 
RefBaseoperator= (const RefBase &)
 Assignment operator. More...
 
virtual ~RefBase ()
 Destructor. More...
 
virtual bool checkRTTI (const char *typenameStr)=0
 This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();. More...
 
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. More...
 

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. More...
 
- Static Public Member Functions inherited from RefBase
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. More...
 

Detailed Description

Handles IO for a MatrixFieldMapping object

Definition at line 191 of file FieldMappingIO.h.

Member Typedef Documentation

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

Definition at line 198 of file FieldMappingIO.h.

Convenience typedef for referring to base class.

Definition at line 239 of file FieldMappingIO.h.

Constructor & Destructor Documentation

MatrixFieldMappingIO::MatrixFieldMappingIO ( )
inline

Ctor.

Definition at line 213 of file FieldMappingIO.h.

214  : FieldMappingIO()
215  { }
FieldMappingIO()
Ctor.

Member Function Documentation

static const char* MatrixFieldMappingIO::staticClassType ( )
inlinestatic

Definition at line 205 of file FieldMappingIO.h.

206  {
207  return "MatrixFieldMappingIO";
208  }
static FieldMappingIO::Ptr MatrixFieldMappingIO::create ( )
inlinestatic

Definition at line 217 of file FieldMappingIO.h.

References FieldMappingIO::className(), FieldMappingIO::read(), and FieldMappingIO::write().

Referenced by initIO().

218  { return Ptr(new MatrixFieldMappingIO); }
boost::intrusive_ptr< MatrixFieldMappingIO > Ptr
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 122 of file FieldMappingIO.cpp.

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

123 {
124  M44d mtx;
125  int numSamples=0;
126 
128 
129  // For backward compatibility, we first try to read the non-time-varying
130  // mapping.
131 
132  try {
133  readAttribute(mappingGroup, k_matrixMappingDataName, 16, mtx.x[0][0]);
134  mm->setLocalToWorld(mtx);
135  return mm;
136  }
137  catch (...) {
138  // Do nothing
139  }
140 
141  // If we didn't find the non-time-varying matrix data then we attempt
142  // to read time samples
143 
144  try {
145  if (!readAttribute(mappingGroup, k_matrixMappingNumSamples, 1, numSamples)) {
146  Msg::print(Msg::SevWarning, "Couldn't read attribute " +
147  k_matrixMappingNumSamples);
148  return FieldMapping::Ptr();
149  }
150  } catch (...) {
151  //do nothing
152  }
153 
154  for (int i = 0; i < numSamples; ++i) {
155  float time;
156  string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
157  string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
158  if (!readAttribute(mappingGroup, timeAttr, 1, time)) {
159  Msg::print(Msg::SevWarning, "Couldn't read attribute " + timeAttr);
160  return FieldMapping::Ptr();
161  }
162  std::vector<unsigned int> attrSize;
163  attrSize.assign(2,4);
164 
165  if (!readAttribute(mappingGroup, matrixAttr, attrSize, mtx.x[0][0])) {
166  Msg::print(Msg::SevWarning, "Couldn't read attribute " + matrixAttr);
167  return FieldMapping::Ptr();
168  }
169  mm->setLocalToWorld(time, mtx);
170  }
171 
172  return mm;
173 }
Imath::M44d M44d
Definition: SpiMathLib.h:82
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
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:66
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
Represents the mapping of a field by a matrix transform.
Definition: FieldMapping.h:327
boost::intrusive_ptr< MatrixFieldMapping > Ptr
Convenience typedef.
Definition: FieldMapping.h:334
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 178 of file FieldMappingIO.cpp.

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

179 {
181 
183  FIELD_DYNAMIC_CAST<MatrixFieldMapping>(mapping);
184 
185  if (!mm) {
186  Msg::print(Msg::SevWarning, "Couldn't get MatrixFieldMapping from pointer");
187  return false;
188  }
189 
190  // First write number of time samples
191 
192  const SampleVec &samples = mm->localToWorldSamples();
193  int numSamples = static_cast<int>(samples.size());
194 
195  if (!writeAttribute(mappingGroup, k_matrixMappingNumSamples, 1, numSamples)) {
196  Msg::print(Msg::SevWarning, "Couldn't add attribute " +
197  k_matrixMappingNumSamples);
198  return false;
199  }
200 
201  // Then write each sample
202 
203  for (int i = 0; i < numSamples; ++i) {
204  string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
205  string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
206  if (!writeAttribute(mappingGroup, timeAttr, 1, samples[i].first)) {
207  Msg::print(Msg::SevWarning, "Couldn't add attribute " + timeAttr);
208  return false;
209  }
210  std::vector<unsigned int> attrSize;
211  attrSize.assign(2,4);
212  if (!writeAttribute(mappingGroup, matrixAttr, attrSize,
213  samples[i].second.x[0][0])) {
214  Msg::print(Msg::SevWarning, "Couldn't add attribute " + matrixAttr);
215  return false;
216  }
217  }
218 
219  return true;
220 }
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
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:66
std::vector< Sample > SampleVec
Definition: Curve.h:85
boost::intrusive_ptr< MatrixFieldMapping > Ptr
Convenience typedef.
Definition: FieldMapping.h:334
std::string MatrixFieldMappingIO::className ( ) const
virtual

Returns the class name.

Implements FieldMappingIO.

Definition at line 224 of file FieldMappingIO.cpp.

References FIELD3D_NAMESPACE_OPEN::k_matrixMappingName().

225 {
226  return k_matrixMappingName;
227 }
const string k_matrixMappingName("MatrixFieldMapping")

Member Data Documentation

MatrixFieldMappingIO::DEFINE_FIELD_RTTI_CONCRETE_CLASS

Definition at line 203 of file FieldMappingIO.h.


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