IMP  2.0.1
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-2013 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 
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  const Transformation3D& get_inverse() const {
27  if (!has_inverse_) {
28  tri_= tr_.get_inverse();
29  has_inverse_=true;
30  }
31  return tri_;
32  }
33 public:
34  //! Create the default reference frame
35  /** That is, the origin with x,y,z axis as the principal axes.*/
37  has_inverse_(true),
38  tri_(tr_){}
39  //! a reference frame specified by a transformation matrix
40  /** Constructs a reference frame using transformation tr
41 
42  @param tr a transformation from local coordinates in this
43  constructed reference frame to the global coordinates
44  (equiv., tr brings the origin of the global frame
45  to the origin of this frame, in global coordinates),
46  */
47  explicit ReferenceFrame3D(const Transformation3D &tr): tr_(tr),
48  has_inverse_(false){}
50  //! Get the transformation that brings the origin of the global reference
51  //! frame to the origin of this frame (both in global coordinates).
53  return tr_;
54  }
55  //! Get the transformation from the origin of this reference frame
56  //! to the origin of the global frame (both in global coordinates).
58  return get_inverse();
59  }
60  //! Assume the input vector is in local coordinates and transform
61  //! it to global ones.
63  return tr_.get_transformed(v);
64  }
65  //! Assume the input vector is in global coordinates and get the local
66  //! coordinates.
68  return get_inverse().get_transformed(v);
69  }
70  //! Assume the input vector is in local coordinates and transform
71  //! it to global ones.
73  return ReferenceFrame3D(tr_*v.tr_);
74  }
75  //! Assume the input vector is in global coordinates and get the local
76  //! coordinates.
78  return ReferenceFrame3D(get_inverse() *v.tr_);
79  }
80  IMP_SHOWABLE_INLINE(ReferenceFrame3D, {out << tr_;});
81 };
82 
83 
85 
86 inline ReferenceFrame3D
89 }
90 
91 inline Transformation3D
92 get_transformation_from_first_to_second(const ReferenceFrame3D &a,
93  const ReferenceFrame3D &b) {
94  return b.get_transformation_to()*a.get_transformation_from();
95 }
96 
97 IMPALGEBRA_END_NAMESPACE
98 #endif /* IMPALGEBRA_REFERENCE_FRAME_3D_H */