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