IMP  2.0.0
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,
23  const Transformation2D &b);
24 #endif
25 
26 //! Simple 2D transformation class
27 /** \geometry
28 */
29 class IMPALGEBRAEXPORT Transformation2D: public GeometricPrimitiveD<2>
30 {
31 public:
32 
33  //! constructor. An invalid transformation is built
35 
36  //! basic constructor from a Rotation2D and translation vector
38  const Vector2D& t=Vector2D(0.0,0.0)):
39  trans_(t), rot_(r){}
40 
41  //! Constructor for a transformation with an identity rotation.
43  trans_(t), rot_(get_identity_rotation_2d()){}
44 
46 
47  //! Perform the transformation on an 2D vector
48  /**
49  \param[in] o vector where the transformation is applied
50  \note: The transformation is done firstly applying the rotation and then
51  the translation
52  **/
53  Vector2D get_transformed(const Vector2D &o) const {
54  return rot_.get_rotated(o) + trans_;
55  }
56 
57  //! Perform the transformation on an 2D vector
58  /**
59  \note: The transformation is done firstly applying the rotation and then
60  the translation
61  **/
62  Vector2D operator*(const Vector2D &v) const {
63  return get_transformed(v);
64  }
65 
66  //! compose two transformations
67  /**
68  \ note The transformations are composed such that for any vector v
69  (rt1*rt2)*v = rt1*(rt2*v)
70  **/
72  return compose(*this, tr);
73  }
74 
75  //! See help for operator*
77  *this=compose(*this, o);
78  return *this;
79  }
80 
81  //! Compute the transformation d which, when composed with b, gives this one.
82  //! That is a(x)== d(b(x)) for all x.
84  Transformation2D ret= compose(*this, b.get_inverse());
85  return ret;
86  }
87 
88  //! See help for operator/
90  *this= *this/o;
91  return *this;
92  }
93 
94  //! Returns the rotation
95  const Rotation2D get_rotation() const {return rot_;}
96 
97  void set_rotation(double angle) {
98  rot_.set_angle(angle);
99  }
100 
101  //! Returns the translation
102  const Vector2D get_translation()const{return trans_;}
103 
104  //! Sets the translation
105  void set_translation(const Vector2D &v) {
106  trans_[0]=v[0];
107  trans_[1]=v[1];
108  }
109 
111  rot_.show(out);
112  out << " || " << trans_;
113  });
114 
115  //! Returns the inverse transformation
116  Transformation2D get_inverse() const;
117 
118 private:
119  Vector2D trans_; //tranlation
120  Rotation2D rot_; //rotation
121 };
122 
124 
125 //! Returns a transformation that does not do anything
126 /**
127  \relatesalso Transformation2D
128 **/
131 }
132 
133 //! Generates a Transformation2D object from a rotation around a point
134 /**
135  Generates a Transformation2D to rotate about a point rather than the origin.
136  \param[in] point Center to rotate about
137  \param[in] rotation The rotation to perform (defined taking the origin as
138  reference, not the new point).
139  \relatesalso Transformation2D
140 */
142  const Rotation2D &rotation) {
143  return Transformation2D(rotation, (rotation.get_rotated(-point)+point));
144 }
145 
146 //! compose two transformations
147  /** For any vector v (a*b)*v = a*(b*v).
148  \relatesalso Transformation2D
149  */
151  const Transformation2D &b){
154 }
155 
156 
157 
158 IMPALGEBRA_END_NAMESPACE
159 #endif /* IMPALGEBRA_TRANSFORMATION_2D_H */