IMP  2.1.1
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  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
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  const Rotation3D &get_rotation() const { return rot_; }
72  const Vector3D &get_translation() const { return trans_; }
73 
74  IMP_SHOWABLE_INLINE(Transformation3D, {
75  rot_.show(out);
76  out << " || " << trans_;
77  });
78  Transformation3D get_inverse() const;
79 
80  private:
81  Vector3D trans_; // translation
82  Rotation3D rot_; // rotation
83 };
84 
86 
87 //! Return a transformation that does not do anything
88 /** See Transformation3D */
90  return Transformation3D(get_identity_rotation_3d(), Vector3D(0.0, 0.0, 0.0));
91 }
92 
93 //! Generate a Transformation3D object from a rotation around a point
94 /** Rotate about a point rather than the origin.
95  \param[in] point Center to rotate about
96  \param[in] rotation The rotation to perform
97 
98  See Transformation3D
99 */
101  const Rotation3D &rotation) {
102  return Transformation3D(rotation, (rotation * (-point) + point));
103 }
104 
105 //! compose two transformations
106 /** For any vector v (a*b)*v = a*(b*v).
107  See Transformation3D
108  */
110  const Transformation3D &b) {
111  return Transformation3D(compose(a.get_rotation(), b.get_rotation()),
112  a.get_transformed(b.get_translation()));
113 }
114 
115 class Transformation2D;
116 
117 //! Builds a 3D transformation from a 2D one.
118 /**
119  \note The 3D transformation is built with the 2D rotation becoming a rotation
120  around the z axis.
121  **/
122 IMPALGEBRAEXPORT Transformation3D
123  get_transformation_3d(const Transformation2D &t2d);
124 
125 //! Get a local transformation
126 /**
127  \note randomly select an axis that passes to the input point
128  and rotate around it
129  \param[in] origin the origin of the rotation
130  \param[in] max_translation detault value is 5
131  \param[in] max_angle_in_rad default value is 15 degree in radians
132  **/
133 IMPALGEBRAEXPORT Transformation3D
135  double max_translation = 5.,
136  double max_angle_in_rad = 0.26);
137 
138 //! Return a bounding box containing the transformed box
139 inline BoundingBoxD<3> get_transformed(const BoundingBoxD<3> &bb,
140  const Transformation3D &tr) {
141  BoundingBoxD<3> nbb;
142  for (unsigned int i = 0; i < 2; ++i) {
143  for (unsigned int j = 0; j < 2; ++j) {
144  for (unsigned int k = 0; k < 2; ++k) {
145  algebra::Vector3D v(bb.get_corner(i)[0], bb.get_corner(j)[1],
146  bb.get_corner(k)[2]);
147  nbb += tr.get_transformed(v);
148  }
149  }
150  }
151  return nbb;
152 }
153 
154 IMPALGEBRA_END_NAMESPACE
155 
156 #endif /* IMPALGEBRA_TRANSFORMATION_3D_H */
Basic types used by IMP.
Simple 3D transformation class.
const VectorD< D > & get_corner(unsigned int i) const
For 0 return lower corner and 1 upper corner.
Definition: BoundingBoxD.h:123
Rotation2D compose(const Rotation2D &a, const Rotation2D &b)
compose two rotations a and b
Definition: Rotation2D.h:105
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Transformation3D()
construct an invalid transformation
Transformation2D get_rotation_about_point(const Vector2D &point, const Rotation2D &rotation)
Generates a Transformation2D object from a rotation around a point.
A bounding box in D dimensions.
Transformation3D operator/(const Transformation3D &b) const
Vector3D get_transformed(const Vector3D &o) const
transform
Simple 3D rotation class.
3D rotation class.
Definition: Rotation3D.h:45
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:587
Rotation3D get_identity_rotation_3d()
Return a rotation that does not do anything.
Definition: Rotation3D.h:220
Simple 3D vector class.
Transformation3D get_random_local_transformation(Vector3D origin, double max_translation=5., double max_angle_in_rad=0.26)
Get a local transformation.