IMP logo
IMP Reference Guide  2.11.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  *
5  * Copyright 2007-2019 IMP Inventors. All rights reserved.
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  //! Return transformation from local to global coordinates
52 
53  /**
54  Get the transformation that brings the origin of the global reference
55  frame to the origin of this frame (both in global coordinates).
56  */
57  const Transformation3D &get_transformation_to() const { return tr_; }
58 
59  //! Return the transformation from global to local coordinates
60  /**
61  Get the transformation from the origin of this reference frame
62  to the origin of the global frame (both in global coordinates).
63  */
65  return get_inverse();
66  }
67 
68  //! Convert the vector v from local to global coordinates
69  //! (i.e., v is specified in this reference frame)
71  return tr_.get_transformed(v);
72  }
73 
74  //! Convert the vector v from global to local coordinates
75  //! (i.e., the returned vector is specified in this reference frame)
77  return get_inverse().get_transformed(v);
78  }
79 
80  //! Convert reference frame v from local to global
81  //! (i.e., v is specified in this reference frame)
83  return ReferenceFrame3D(tr_ * v.tr_);
84  }
85 
86  //! Convert reference frame v from global to local
87  //! (i.e. the returned reference frame is speficied in this reference frame)
89  return ReferenceFrame3D(get_inverse() * v.tr_);
90  }
91 
92  IMP_SHOWABLE_INLINE(ReferenceFrame3D, { out << tr_; });
93 };
94 
96 
98  const Transformation3D &tr) {
99  return ReferenceFrame3D(tr * rf.get_transformation_to());
100 }
101 
102 inline Transformation3D get_transformation_from_first_to_second(
103  const ReferenceFrame3D &a, const ReferenceFrame3D &b) {
104  return b.get_transformation_to() * a.get_transformation_from();
105 }
106 
107 IMPALGEBRA_END_NAMESPACE
108 #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
Return the transformation from global to local coordinates.
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
Return transformation from local to global coordinates.
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.