IMP  2.4.0 The Integrative Modeling Platform
Transformation3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/Transformation3D.h
3  * \brief Simple 3D transformation class.
4  *
6  *
7  */
8
9 #ifndef IMPALGEBRA_TRANSFORMATION_3D_H
10 #define IMPALGEBRA_TRANSFORMATION_3D_H
11
12 #include <IMP/algebra/algebra_config.h>
13 #include "Vector3D.h"
14 #include "Rotation3D.h"
15 #include "BoundingBoxD.h"
16 #include "GeometricPrimitiveD.h"
17
18 IMPALGEBRA_BEGIN_NAMESPACE
19
20 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
21 class Transformation3D;
22 Transformation3D compose(const Transformation3D &a, const Transformation3D &b);
23 #endif
24
25 //! Simple 3D transformation class
26 /** The rotation is applied first, and then the point is translated.
27  \see IMP::core::Transform
28  \geometry
29 */
30 class IMPALGEBRAEXPORT Transformation3D : public GeometricPrimitiveD<3> {
31  public:
32  IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(Transformation3D);
33  //! construct an invalid transformation
35  /** basic constructor*/
36  Transformation3D(const Rotation3D &r, const Vector3D &t = Vector3D(0, 0, 0))
37  : trans_(t), rot_(r) {}
38  /** Construct a transformation with an identity rotation.*/
40  : trans_(t), rot_(get_identity_rotation_3d()) {}
42  //! transform
43  Vector3D get_transformed(const Vector3D &o) const {
44  return rot_.get_rotated(o) + trans_;
45  }
46  //! apply transformation (rotate and then translate)
47  Vector3D operator*(const Vector3D &v) const { return get_transformed(v); }
48  /** compose two rigid transformation such that for any vector v
49  (rt1*rt2)*v = rt1*(rt2*v) */
51  return compose(*this, tr);
52  }
53  const Transformation3D &operator*=(const Transformation3D &o) {
54  *this = compose(*this, o);
55  return *this;
56  }
57  /** Compute the transformation which, when composed with b, gives *this.
58  That is a(x)== d(b(x)) for all x.
59
60  For consistency, this should probably have a nice name, but
61  I don't know what name to give it.
62  */
64  Transformation3D ret = compose(*this, b.get_inverse());
65  return ret;
66  }
67  const Transformation3D &operator/=(const Transformation3D &o) {
68  *this = *this / o;
69  return *this;
70  }
71
72  //! returns the rotation associated with this transformation
73  const Rotation3D &get_rotation() const { return rot_; }
74
75  //! returns the translation vector associated with this transformation
76  const Vector3D &get_translation() const { return trans_; }
77
79  rot_.show(out);
80  out << " || " << trans_;
81  });
82  Transformation3D get_inverse() const;
83
84  /** @return true if the 3D transformation is valid; false if the
85  transformation was initialized only with the empty constructor,
86  or it was initialized with an invalid rotation.
87  */
88  bool get_is_valid() const {
89  return rot_.get_is_valid();
90  }
91
92  private:
93  Vector3D trans_; // translation
94  Rotation3D rot_; // rotation
95 };
96
98
99 //! Return a transformation that does not do anything
100 /** \see Transformation3D */
102  return Transformation3D(get_identity_rotation_3d(), Vector3D(0.0, 0.0, 0.0));
103 }
104
105 //! Generate a Transformation3D object from a rotation around a point
106 /** Rotate about a point rather than the origin.
107  \param[in] point Center to rotate about
108  \param[in] rotation The rotation to perform
109
110  \see Transformation3D
111 */
113  const Rotation3D &rotation) {
114  return Transformation3D(rotation, (rotation * (-point) + point));
115 }
116
117 //! Compose two transformations
118 /** For any vector v (a*b)*v = a*(b*v).
119  \see Transformation3D
120  */
122  const Transformation3D &b) {
124  "composing an invalid transformation");
127 }
128
129 class Transformation2D;
130
131 //! Builds a 3D transformation from a 2D one.
132 /**
133  \note The 3D transformation is built with the 2D rotation becoming a rotation
134  around the z axis.
135  **/
136 IMPALGEBRAEXPORT Transformation3D
137  get_transformation_3d(const Transformation2D &t2d);
138
139 //! Get a local transformation
140 /**
141  \note randomly select an axis that passes to the input point
142  and rotate around it
143  \param[in] origin the origin of the rotation
144  \param[in] max_translation default value is 5
146  **/
147 IMPALGEBRAEXPORT Transformation3D
149  double max_translation = 5.,
151
152 //! Return a bounding box containing the transformed box
154  const Transformation3D &tr) {
155  BoundingBoxD<3> nbb;
156  for (unsigned int i = 0; i < 2; ++i) {
157  for (unsigned int j = 0; j < 2; ++j) {
158  for (unsigned int k = 0; k < 2; ++k) {
159  algebra::Vector3D v(bb.get_corner(i)[0], bb.get_corner(j)[1],
160  bb.get_corner(k)[2]);
161  nbb += tr.get_transformed(v);
162  }
163  }
164  }
165  return nbb;
166 }
167
168 IMPALGEBRA_END_NAMESPACE
169
170 #endif /* IMPALGEBRA_TRANSFORMATION_3D_H */
Basic types used by IMP.
Simple 3D transformation class.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
const VectorD< D > & get_corner(unsigned int i) const
For 0 return lower corner and 1 upper corner.
Definition: BoundingBoxD.h:139
Rotation2D compose(const Rotation2D &a, const Rotation2D &b)
compose two rotations a and b
Definition: Rotation2D.h:108
BoundingBoxD< 3 > get_transformed(const BoundingBoxD< 3 > &bb, const Transformation3D &tr)
Return a bounding box containing the transformed box.
Transformation3D get_rotation_about_point(const Vector3D &point, const Rotation3D &rotation)
Generate a Transformation3D object from a rotation around a point.
Transformation3D()
construct an invalid transformation
const Rotation3D & get_rotation() const
returns the rotation associated with this transformation
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
Base class for geometric types.
A bounding box in D dimensions.
Transformation3D operator/(const Transformation3D &b) const
Vector3D get_transformed(const Vector3D &o) const
transform
Transformation3D compose(const Transformation3D &a, const Transformation3D &b)
Compose two transformations.
Simple 3D rotation class.
3D rotation class.
Definition: Rotation3D.h:46
Transformation3D get_identity_transformation_3d()
Return a transformation that does not do anything.
Transformation3D operator*(const Transformation3D &tr) const
Transformation3D get_transformation_3d(const Transformation2D &t2d)
Builds a 3D transformation from a 2D one.
Vector3D operator*(const Vector3D &v) const
apply transformation (rotate and then translate)
Transformation3D(const Vector3D &t)
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Rotation3D get_identity_rotation_3d()
Return a rotation that does not do anything.
Definition: Rotation3D.h:236
Simple 3D vector class.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:170
Transformation3D(const Rotation3D &r, const Vector3D &t=Vector3D(0, 0, 0))
const Vector3D & get_translation() const
returns the translation vector associated with this transformation
Transformation3D get_random_local_transformation(Vector3D origin, double max_translation=5., double max_angle_in_rad=0.26)
Get a local transformation.