IMP  2.1.1
The Integrative Modeling Platform
Transformation2D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/Transformation2D.h
3  * \brief 2D transformations.
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPALGEBRA_TRANSFORMATION_2D_H
9 #define IMPALGEBRA_TRANSFORMATION_2D_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 
13 #include "Vector2D.h"
14 #include "Rotation2D.h"
15 #include "GeometricPrimitiveD.h"
16 
17 IMPALGEBRA_BEGIN_NAMESPACE
18 
19 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
20 // #ifndef IMP_DOXYGEN
21 class Transformation2D;
22 Transformation2D compose(const Transformation2D &a, const Transformation2D &b);
23 #endif
24 
25 //! Simple 2D transformation class
26 /** \geometry
27 */
28 class IMPALGEBRAEXPORT Transformation2D : public GeometricPrimitiveD<2> {
29  public:
30  IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(Transformation2D);
31 
32  //! constructor. An invalid transformation is built
34 
35  //! basic constructor from a Rotation2D and translation vector
36  Transformation2D(const Rotation2D &r, const Vector2D &t = Vector2D(0.0, 0.0))
37  : trans_(t), rot_(r) {}
38 
39  //! Constructor for a transformation with an identity rotation.
41  : trans_(t), rot_(get_identity_rotation_2d()) {}
42 
44 
45  //! Perform the transformation on an 2D vector
46  /**
47  \param[in] o vector where the transformation is applied
48  \note: The transformation is done firstly applying the rotation and then
49  the translation
50  **/
51  Vector2D get_transformed(const Vector2D &o) const {
52  return rot_.get_rotated(o) + trans_;
53  }
54 
55  //! Perform the transformation on an 2D vector
56  /**
57  \note: The transformation is done firstly applying the rotation and then
58  the translation
59  **/
60  Vector2D operator*(const Vector2D &v) const { return get_transformed(v); }
61 
62  //! compose two transformations
63  /**
64  \ note The transformations are composed such that for any vector v
65  (rt1*rt2)*v = rt1*(rt2*v)
66  **/
68  return compose(*this, tr);
69  }
70 
71  //! See help for operator*
73  *this = compose(*this, o);
74  return *this;
75  }
76 
77  //! Compute the transformation d which, when composed with b, gives this one.
78  //! That is a(x)== d(b(x)) for all x.
80  Transformation2D ret = compose(*this, b.get_inverse());
81  return ret;
82  }
83 
84  //! See help for operator/
86  *this = *this / o;
87  return *this;
88  }
89 
90  //! Returns the rotation
91  const Rotation2D get_rotation() const { return rot_; }
92 
93  void set_rotation(double angle) { rot_.set_angle(angle); }
94 
95  //! Returns the translation
96  const Vector2D get_translation() const { return trans_; }
97 
98  //! Sets the translation
99  void set_translation(const Vector2D &v) {
100  trans_[0] = v[0];
101  trans_[1] = v[1];
102  }
103 
105  rot_.show(out);
106  out << " || " << trans_;
107  });
108 
109  //! Returns the inverse transformation
110  Transformation2D get_inverse() const;
111 
112  private:
113  Vector2D trans_; // tranlation
114  Rotation2D rot_; // rotation
115 };
116 
118 
119 //! Returns a transformation that does not do anything
120 /**
121  See Transformation2D
122 **/
125 }
126 
127 //! Generates a Transformation2D object from a rotation around a point
128 /**
129  Generates a Transformation2D to rotate about a point rather than the origin.
130  \param[in] point Center to rotate about
131  \param[in] rotation The rotation to perform (defined taking the origin as
132  reference, not the new point).
133  See Transformation2D
134 */
136  const Rotation2D &rotation) {
137  return Transformation2D(rotation, (rotation.get_rotated(-point) + point));
138 }
139 
140 //! compose two transformations
141 /** For any vector v (a*b)*v = a*(b*v).
142  See Transformation2D
143  */
145  const Transformation2D &b) {
148 }
149 
150 IMPALGEBRA_END_NAMESPACE
151 #endif /* IMPALGEBRA_TRANSFORMATION_2D_H */
Basic types used by IMP.
Classes and operations related with rotations.
VectorD< 2 > Vector2D
Definition: VectorD.h:583
Stores a 2D rotation matrix.
Definition: Rotation2D.h:34
const Rotation2D get_rotation() const
Returns the rotation.
Rotation2D compose(const Rotation2D &a, const Rotation2D &b)
compose two rotations a and b
Definition: Rotation2D.h:105
Simple 2D vector class.
Transformation2D get_inverse() const
Returns the inverse transformation.
#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.
const Vector2D get_translation() const
Returns the translation.
Transformation2D()
constructor. An invalid transformation is built
Transformation2D get_rotation_about_point(const Vector2D &point, const Rotation2D &rotation)
Generates a Transformation2D object from a rotation around a point.
Vector2D operator*(const Vector2D &v) const
Perform the transformation on an 2D vector.
A Cartesian vector in D-dimensions.
Definition: VectorD.h:48
Rotation2D get_identity_rotation_2d()
Builds an identity rotation in 2D.
Definition: Rotation2D.h:88
Transformation2D(const Vector2D &t)
Constructor for a transformation with an identity rotation.
void set_translation(const Vector2D &v)
Sets the translation.
const Transformation2D & operator*=(const Transformation2D &o)
See help for operator*.
Simple 2D transformation class.
Transformation2D operator*(const Transformation2D &tr) const
compose two transformations
Vector2D get_rotated(const Vector2D &o) const
rotates a 2D point
Definition: Rotation2D.h:45
Transformation2D operator/(const Transformation2D &b) const
void set_angle(double angle)
sets the angle for the rotation
Definition: Rotation2D.h:69
const Transformation2D & operator/=(const Transformation2D &o)
See help for operator/.
Vector2D get_transformed(const Vector2D &o) const
Perform the transformation on an 2D vector.
Transformation2D get_identity_transformation_2d()
Returns a transformation that does not do anything.