IMP  2.2.0
The Integrative Modeling Platform
ReferenceFrame3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/ReferenceFrame3D.h \brief Simple 3D rotation class.
3  *
4  * Copyright 2007-2014 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPALGEBRA_REFERENCE_FRAME_3D_H
9 #define IMPALGEBRA_REFERENCE_FRAME_3D_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 #include "Transformation3D.h"
13 
14 IMPALGEBRA_BEGIN_NAMESPACE
15 
16 //! A reference frame in 3D.
17 /**
18  \geometry
19 */
20 class IMPALGEBRAEXPORT ReferenceFrame3D {
21  Transformation3D tr_;
22  mutable bool has_inverse_;
23  mutable Transformation3D tri_;
24  const Transformation3D &get_inverse() const {
25  if (!has_inverse_) {
26  tri_ = tr_.get_inverse();
27  has_inverse_ = true;
28  }
29  return tri_;
30  }
31 
32  public:
33  IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(ReferenceFrame3D);
34  //! Create the default reference frame
35  /** That is, the origin with x,y,z axis as the principal axes.*/
37  : tr_(get_identity_transformation_3d()), has_inverse_(true), tri_(tr_) {}
38  //! a reference frame specified by a transformation matrix
39  /** Constructs a reference frame using transformation tr
40 
41  @param tr a transformation from local coordinates in this
42  constructed reference frame to the global coordinates
43  (equiv., tr brings the origin of the global frame
44  to the origin of this frame, in global coordinates),
45  */
46  explicit ReferenceFrame3D(const Transformation3D &tr)
47  : tr_(tr), has_inverse_(false) {}
49  //! Get the transformation that brings the origin of the global reference
50  //! frame to the origin of this frame (both in global coordinates).
51  const Transformation3D &get_transformation_to() const { return tr_; }
52  //! Get the transformation from the origin of this reference frame
53  //! to the origin of the global frame (both in global coordinates).
55  return get_inverse();
56  }
57  //! Assume the input vector is in local coordinates and transform
58  //! it to global ones.
60  return tr_.get_transformed(v);
61  }
62  //! Assume the input vector is in global coordinates and get the local
63  //! coordinates.
65  return get_inverse().get_transformed(v);
66  }
67  //! Assume the input vector is in local coordinates and transform
68  //! it to global ones.
70  return ReferenceFrame3D(tr_ * v.tr_);
71  }
72  //! Assume the input vector is in global coordinates and get the local
73  //! coordinates.
75  return ReferenceFrame3D(get_inverse() * v.tr_);
76  }
77  IMP_SHOWABLE_INLINE(ReferenceFrame3D, { out << tr_; });
78 };
79 
81 
82 inline ReferenceFrame3D get_transformed(const ReferenceFrame3D &rf,
83  const Transformation3D &tr) {
84  return ReferenceFrame3D(tr * rf.get_transformation_to());
85 }
86 
87 inline Transformation3D get_transformation_from_first_to_second(
88  const ReferenceFrame3D &a, const ReferenceFrame3D &b) {
89  return b.get_transformation_to() * a.get_transformation_from();
90 }
91 
92 IMPALGEBRA_END_NAMESPACE
93 #endif /* IMPALGEBRA_REFERENCE_FRAME_3D_H */
Simple 3D transformation class.
const Transformation3D & get_transformation_from() const
ReferenceFrame3D get_local_reference_frame(const ReferenceFrame3D &v) const
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
A reference frame in 3D.
ReferenceFrame3D get_global_reference_frame(const ReferenceFrame3D &v) const
Vector3D get_local_coordinates(const Vector3D &v) const
const Transformation3D & get_transformation_to() const
Simple 3D transformation class.
Transformation3D get_identity_transformation_3d()
Return a transformation that does not do anything.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
ReferenceFrame3D()
Create the default reference frame.
Vector3D get_global_coordinates(const Vector3D &v) const
ReferenceFrame3D(const Transformation3D &tr)
a reference frame specified by a transformation matrix