IMP Reference Guide  2.7.0 The Integrative Modeling Platform
ReferenceFrame3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/ReferenceFrame3D.h
3  * \brief A reference frame in 3D.
4  *
6  *
7  */
8
9 #ifndef IMPALGEBRA_REFERENCE_FRAME_3D_H
10 #define IMPALGEBRA_REFERENCE_FRAME_3D_H
11
12 #include <IMP/algebra/algebra_config.h>
13 #include "Transformation3D.h"
14
15 IMPALGEBRA_BEGIN_NAMESPACE
16
17 //! A reference frame in 3D.
18 /**
19  \geometry
20 */
21 class IMPALGEBRAEXPORT ReferenceFrame3D {
22  Transformation3D tr_;
23  mutable bool has_inverse_;
24  mutable Transformation3D tri_;
25  const Transformation3D &get_inverse() const {
26  if (!has_inverse_) {
27  tri_ = tr_.get_inverse();
28  has_inverse_ = true;
29  }
30  return tri_;
31  }
32
33  public:
34  IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(ReferenceFrame3D);
35  //! Create the default reference frame
36  /** That is, the origin with x,y,z axis as the principal axes. */
38  : tr_(get_identity_transformation_3d()), has_inverse_(true), tri_(tr_) {}
39
40  //! A reference frame specified by a transformation matrix
41  /** Constructs a reference frame using transformation tr
42
43  @param tr a transformation from local coordinates in this
44  constructed reference frame to the global coordinates
45  (equiv., tr brings the origin of the global frame
46  to the origin of this frame, in global coordinates),
47  */
48  explicit ReferenceFrame3D(const Transformation3D &tr)
49  : tr_(tr), has_inverse_(false) {}
51  //! Get the transformation that brings the origin of the global reference
52  //! frame to the origin of this frame (both in global coordinates).
53  const Transformation3D &get_transformation_to() const { return tr_; }
54  //! Get the transformation from the origin of this reference frame
55  //! to the origin of the global frame (both in global coordinates).
57  return get_inverse();
58  }
59  //! Assume the input vector is in local coordinates and transform
60  //! it to global ones.
62  return tr_.get_transformed(v);
63  }
64  //! Assume the input vector is in global coordinates and get the local
65  //! coordinates.
67  return get_inverse().get_transformed(v);
68  }
69  //! Assume the input vector is in local coordinates and transform
70  //! it to global ones.
72  return ReferenceFrame3D(tr_ * v.tr_);
73  }
74  //! Assume the input vector is in global coordinates and get the local
75  //! coordinates.
77  return ReferenceFrame3D(get_inverse() * v.tr_);
78  }
79  IMP_SHOWABLE_INLINE(ReferenceFrame3D, { out << tr_; });
80 };
81
83
85  const Transformation3D &tr) {
86  return ReferenceFrame3D(tr * rf.get_transformation_to());
87 }
88
89 inline Transformation3D get_transformation_from_first_to_second(
90  const ReferenceFrame3D &a, const ReferenceFrame3D &b) {
91  return b.get_transformation_to() * a.get_transformation_from();
92 }
93
94 IMPALGEBRA_END_NAMESPACE
95 #endif /* IMPALGEBRA_REFERENCE_FRAME_3D_H */
Simple 3D transformation class.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
const Transformation3D & get_transformation_from() const
ReferenceFrame3D get_local_reference_frame(const ReferenceFrame3D &v) const
A reference frame in 3D.
ReferenceFrame3D get_global_reference_frame(const ReferenceFrame3D &v) const
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
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
DensityMap * get_transformed(const DensityMap *input, const algebra::Transformation3D &tr, double threshold)
Return a new density map containing a rotated version of the old one.
ReferenceFrame3D(const Transformation3D &tr)
A reference frame specified by a transformation matrix.