IMP logo
IMP Reference Guide  2.18.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-2022 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 <boost/serialization/access.hpp>
14 #include <boost/serialization/split_member.hpp>
15 #include "Transformation3D.h"
16 
17 IMPALGEBRA_BEGIN_NAMESPACE
18 
19 //! A reference frame in 3D.
20 /**
21  \geometry
22 */
23 class IMPALGEBRAEXPORT ReferenceFrame3D {
24  Transformation3D tr_;
25  mutable bool has_inverse_;
26  mutable Transformation3D tri_;
27 
28 #ifndef SWIG
29  friend class boost::serialization::access;
30 
31  template<class Archive> void save(Archive &ar, const unsigned int) const {
32  ar << tr_;
33  }
34 
35  template<class Archive> void load(Archive &ar, const unsigned int) {
36  ar >> tr_;
37  has_inverse_ = false;
38  }
39 
40  BOOST_SERIALIZATION_SPLIT_MEMBER()
41 #endif
42 
43  const Transformation3D &get_inverse() const {
44  if (!has_inverse_) {
45  tri_ = tr_.get_inverse();
46  has_inverse_ = true;
47  }
48  return tri_;
49  }
50 
51  public:
52  IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(ReferenceFrame3D);
53  //! Create the default reference frame
54  /** That is, the origin with x,y,z axis as the principal axes. */
56  : tr_(get_identity_transformation_3d()), has_inverse_(true), tri_(tr_) {}
57 
58  //! A reference frame specified by a transformation matrix
59  /** Constructs a reference frame using transformation tr
60 
61  @param tr a transformation from local coordinates in this
62  constructed reference frame to the global coordinates
63  (equiv., tr brings the origin of the global frame
64  to the origin of this frame, in global coordinates),
65  */
66  explicit ReferenceFrame3D(const Transformation3D &tr)
67  : tr_(tr), has_inverse_(false) {}
69  //! Return transformation from local to global coordinates
70 
71  /**
72  Get the transformation that brings the origin of the global reference
73  frame to the origin of this frame (both in global coordinates).
74  */
75  const Transformation3D &get_transformation_to() const { return tr_; }
76 
77  //! Return the transformation from global to local coordinates
78  /**
79  Get the transformation from the origin of this reference frame
80  to the origin of the global frame (both in global coordinates).
81  */
83  return get_inverse();
84  }
85 
86  //! Convert the vector v from local to global coordinates
87  //! (i.e., v is specified in this reference frame)
89  return tr_.get_transformed(v);
90  }
91 
92  //! Convert the vector v from global to local coordinates
93  //! (i.e., the returned vector is specified in this reference frame)
95  return get_inverse().get_transformed(v);
96  }
97 
98  //! Convert reference frame v from local to global
99  //! (i.e., v is specified in this reference frame)
101  return ReferenceFrame3D(tr_ * v.tr_);
102  }
103 
104  //! Convert reference frame v from global to local
105  //! (i.e. the returned reference frame is speficied in this reference frame)
107  return ReferenceFrame3D(get_inverse() * v.tr_);
108  }
109 
110  IMP_SHOWABLE_INLINE(ReferenceFrame3D, { out << tr_; });
111 };
112 
114 
116  const Transformation3D &tr) {
117  return ReferenceFrame3D(tr * rf.get_transformation_to());
118 }
119 
120 inline Transformation3D get_transformation_from_first_to_second(
121  const ReferenceFrame3D &a, const ReferenceFrame3D &b) {
122  return b.get_transformation_to() * a.get_transformation_from();
123 }
124 
125 IMPALGEBRA_END_NAMESPACE
126 #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:421
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.