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 (const OgIGroup &mappingGroup)
 Reads the field mapping and tries to create a MatrixFieldMapping object from it. 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...
 
virtual bool write (OgOGroup &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 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

◆ base

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.

233  : FieldMappingIO()
234  { }

Member Function Documentation

◆ staticClassType()

static const char* MatrixFieldMappingIO::staticClassType ( )
inlinestatic

Definition at line 224 of file FieldMappingIO.h.

225  {
226  return "MatrixFieldMappingIO";
227  }

◆ create()

static FieldMappingIO::Ptr MatrixFieldMappingIO::create ( )
inlinestatic

Definition at line 236 of file FieldMappingIO.h.

237  { return Ptr(new 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.

149 {
150  M44d mtx;
151  int numSamples=0;
152 
154 
155  // For backward compatibility, we first try to read the non-time-varying
156  // mapping.
157 
158  try {
159  readAttribute(mappingGroup, k_matrixMappingDataName, 16, mtx.x[0][0]);
160  mm->setLocalToWorld(mtx);
161  return mm;
162  }
163  catch (...) {
164  // Do nothing
165  }
166 
167  // If we didn't find the non-time-varying matrix data then we attempt
168  // to read time samples
169 
170  try {
171  if (!readAttribute(mappingGroup, k_matrixMappingNumSamples, 1, numSamples)) {
172  Msg::print(Msg::SevWarning, "Couldn't read attribute " +
173  k_matrixMappingNumSamples);
174  return FieldMapping::Ptr();
175  }
176  } catch (...) {
177  //do nothing
178  }
179 
180  for (int i = 0; i < numSamples; ++i) {
181  float time;
182  string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
183  string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
184  if (!readAttribute(mappingGroup, timeAttr, 1, time)) {
185  Msg::print(Msg::SevWarning, "Couldn't read attribute " + timeAttr);
186  return FieldMapping::Ptr();
187  }
188  std::vector<unsigned int> attrSize;
189  attrSize.assign(2,4);
190 
191  if (!readAttribute(mappingGroup, matrixAttr, attrSize, mtx.x[0][0])) {
192  Msg::print(Msg::SevWarning, "Couldn't read attribute " + matrixAttr);
193  return FieldMapping::Ptr();
194  }
195  mm->setLocalToWorld(time, mtx);
196  }
197 
198  return mm;
199 }

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.

205 {
206  M44d mtx;
207  int numSamples = 0;
208 
210 
211  try {
212  OgIAttribute<int> numSamplesAttr =
213  mappingGroup.findAttribute<int>(k_matrixMappingNumSamples);
214  if (!numSamplesAttr.isValid()) {
215  Msg::print(Msg::SevWarning, "Couldn't read attribute " +
216  k_matrixMappingNumSamples);
217  return FieldMapping::Ptr();
218  }
219  numSamples = numSamplesAttr.value();
220  } catch (...) {
221  //do nothing
222  }
223 
224  for (int i = 0; i < numSamples; ++i) {
225  string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
226  string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
227  // Read time
229  mappingGroup.findAttribute<float32_t>(timeAttr);
230  if (!time.isValid()) {
231  Msg::print(Msg::SevWarning, "Couldn't read attribute " + timeAttr);
232  return FieldMapping::Ptr();
233  }
234  // Read matrix
235  OgIAttribute<mtx64_t> mtx =
236  mappingGroup.findAttribute<mtx64_t>(matrixAttr);
237  if (!mtx.isValid()) {
238  Msg::print(Msg::SevWarning, "Couldn't read attribute " + matrixAttr);
239  return FieldMapping::Ptr();
240  }
241  mm->setLocalToWorld(time.value(), mtx.value());
242  }
243 
244  return mm;
245 }

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.

251 {
253 
255  FIELD_DYNAMIC_CAST<MatrixFieldMapping>(mapping);
256 
257  if (!mm) {
258  Msg::print(Msg::SevWarning, "Couldn't get MatrixFieldMapping from pointer");
259  return false;
260  }
261 
262  // First write number of time samples
263 
264  const SampleVec &samples = mm->localToWorldSamples();
265  int numSamples = static_cast<int>(samples.size());
266 
267  if (!writeAttribute(mappingGroup, k_matrixMappingNumSamples, 1, numSamples)) {
268  Msg::print(Msg::SevWarning, "Couldn't add attribute " +
269  k_matrixMappingNumSamples);
270  return false;
271  }
272 
273  // Then write each sample
274 
275  for (int i = 0; i < numSamples; ++i) {
276  string timeAttr = k_matrixMappingTime + boost::lexical_cast<string>(i);
277  string matrixAttr = k_matrixMappingMatrix + boost::lexical_cast<string>(i);
278  if (!writeAttribute(mappingGroup, timeAttr, 1, samples[i].first)) {
279  Msg::print(Msg::SevWarning, "Couldn't add attribute " + timeAttr);
280  return false;
281  }
282  std::vector<unsigned int> attrSize;
283  attrSize.assign(2,4);
284  if (!writeAttribute(mappingGroup, matrixAttr, attrSize,
285  samples[i].second.x[0][0])) {
286  Msg::print(Msg::SevWarning, "Couldn't add attribute " + matrixAttr);
287  return false;
288  }
289  }
290 
291  return true;
292 }

References 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.

298 {
300 
302  FIELD_DYNAMIC_CAST<MatrixFieldMapping>(mapping);
303 
304  if (!mm) {
305  Msg::print(Msg::SevWarning, "Couldn't get MatrixFieldMapping from pointer");
306  return false;
307  }
308 
309  // First write number of time samples
310 
311  const SampleVec &samples = mm->localToWorldSamples();
312  const int numSamples = static_cast<int>(samples.size());
313 
314  OgOAttribute<int> numSamplesAttr(mappingGroup, k_matrixMappingNumSamples,
315  numSamples);
316 
317  // Then write each sample
318 
319  for (int i = 0; i < numSamples; ++i) {
320  // Attribute names
321  const string timeAttr =
322  k_matrixMappingTime + boost::lexical_cast<string>(i);
323  const string matrixAttr =
324  k_matrixMappingMatrix + boost::lexical_cast<string>(i);
325  OgOAttribute<float32_t> time(mappingGroup, timeAttr, samples[i].first);
326  OgOAttribute<mtx64_t> mtx (mappingGroup, matrixAttr, samples[i].second);
327  }
328 
329  return true;
330 }

References 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.

335 {
336  return k_matrixMappingName;
337 }

References FIELD3D_NAMESPACE_OPEN::k_matrixMappingName().

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:
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
Msg::SevWarning
@ SevWarning
Definition: Log.h:68
FIELD3D_NAMESPACE_OPEN::k_matrixMappingName
const string k_matrixMappingName("MatrixFieldMapping")
OgIAttribute
Definition: OgawaFwd.h:62
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
MatrixFieldMappingIO::Ptr
boost::intrusive_ptr< MatrixFieldMappingIO > Ptr
Definition: FieldMappingIO.h:217
OgOAttribute
Definition: OgawaFwd.h:64
mtx64_t
Field3D::M44d mtx64_t
Definition: Traits.h:95
FieldMappingIO::FieldMappingIO
FieldMappingIO()
Ctor.
Definition: FieldMappingIO.h:87
float32_t
float float32_t
Definition: Traits.h:87
MatrixFieldMappingIO
Definition: FieldMappingIO.h:211
MatrixFieldMapping
Represents the mapping of a field by a matrix transform.
Definition: FieldMapping.h:335
M44d
Imath::M44d M44d
Definition: SpiMathLib.h:82
Hdf5Util::readAttribute
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
Curve< Imath::M44d >::SampleVec
std::vector< Sample > SampleVec
Definition: Curve.h:85
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
MatrixFieldMapping::Ptr
boost::intrusive_ptr< MatrixFieldMapping > Ptr
Convenience typedef.
Definition: FieldMapping.h:341