uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Transform.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 
27 
28 /*
29  * Copyright (C) 2012 Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>
30  *
31  * This library is free software; you can redistribute it and/or modify
32  * it under the terms of the GNU Lesser General Public License as
33  * published by the Free Software Foundation; either version 2.1 of the
34  * License, or (at your option) any later version.
35  *
36  * This library is distributed in the hope that it will be useful, but
37  * WITHOUT ANY WARRANTY; without even the implied warranty of
38  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39  * Lesser General Public License for more details.
40  *
41  * You should have received a copy of the GNU Lesser General Public
42  * License along with this library; if not, write to the Free Software
43  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
44  * 02110-1301 USA
45  *
46  */
47 
48 
49 #ifndef U_TRANSFORM_H
50 #define U_TRANSFORM_H
51 
52 #include <Eigen/Geometry>
53 
54 
55 namespace uLib {
56 
60 
62 protected:
63  Eigen::Affine3f m_T;
65 public:
67  m_T(Matrix4f::Identity()),
68  m_Parent(NULL)
69  {}
70 
72  m_T(Matrix4f::Identity()),
73  m_Parent(parent)
74  {}
75 
77  m_T(copy.m_T),
78  m_Parent(copy.m_Parent)
79  {}
80 
81  Eigen::Affine3f& GetTransform() { return m_T; }
82 
83  inline AffineTransform *GetParent() const { return this->m_Parent; }
84 
85  inline void SetParent(AffineTransform *name) { this->m_Parent = name; }
86 
87  inline void SetMatrix (Matrix4f &mat) { m_T.matrix() = mat; }
88  inline Matrix4f& GetMatrix () { return m_T.matrix(); }
89 
91  {
92  if(!m_Parent) return m_T.matrix();
93  else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A //
94  }
95 
96  inline void SetPosition(const Vector3f &v) { this->m_T.translation() = v; }
97 
98  inline Vector3f GetPosition() const { return this->m_T.translation(); }
99 
100  inline void SetRotation(const Matrix3f &m) { this->m_T.linear() = m; }
101 
102  inline Matrix3f GetRotation() const { return this->m_T.rotation(); }
103 
104  inline void Translate(const Vector3f &v) { this->m_T.translate(v); }
105 
106  inline void Scale(const Vector3f &v) { this->m_T.scale(v); }
107 
108  inline Vector3f GetScale() const { return this->m_T.linear() * Vector3f(1,1,1); } // FIXXXXXXX
109 
110 
111  inline void Rotate(const Matrix3f &m) { this->m_T.rotate(m); }
112 
113 
114  inline void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); }
115 
116  inline void QuaternionRotate(const Vector4f &q)
117  { this->m_T.rotate(Eigen::Quaternion<float>(q)); }
118 
119  inline void EulerYZYRotate(const Vector3f &e) {
120  Matrix3f mat;
121  mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY())
122  * Eigen::AngleAxisf(e.y(), Vector3f::UnitZ())
123  * Eigen::AngleAxisf(e.z(), Vector3f::UnitY());
124  m_T.rotate(mat);
125  }
126 
127  inline void FlipAxes(int first, int second)
128  {
129  Matrix3f mat = Matrix3f::Identity();
130  mat.col(first).swap(mat.col(second));
131  m_T.rotate(mat);
132  }
133 };
134 
135 
136 
137 }
138 
139 
140 
141 #endif//U_TRANSFORM_H
void Rotate(const Matrix3f &m)
Definition: Transform.h:111
void Scale(const Vector3f &v)
Definition: Transform.h:106
Eigen::Matrix3f Matrix3f
Definition: Dense.h:129
void SetMatrix(Matrix4f &mat)
Definition: Transform.h:87
AffineTransform(const AffineTransform &copy)
Definition: Transform.h:76
Eigen::Vector4f Vector4f
Definition: Dense.h:140
Matrix4f GetWorldMatrix() const
Definition: Transform.h:90
Vector3f GetPosition() const
Definition: Transform.h:98
Eigen::Affine3f & GetTransform()
Definition: Transform.h:81
AffineTransform * m_Parent
Definition: Transform.h:64
Eigen::Vector3f Vector3f
Definition: Dense.h:139
Matrix3f GetRotation() const
Definition: Transform.h:102
Vector3f GetScale() const
Definition: Transform.h:108
void SetPosition(const Vector3f &v)
Definition: Transform.h:96
Definition: Transform.h:61
void SetParent(AffineTransform *name)
Definition: Transform.h:85
AffineTransform * GetParent() const
Definition: Transform.h:83
void EulerYZYRotate(const Vector3f &e)
Definition: Transform.h:119
Matrix4f & GetMatrix()
Definition: Transform.h:88
void Translate(const Vector3f &v)
Definition: Transform.h:104
Eigen::Matrix4f Matrix4f
Definition: Dense.h:130
void SetRotation(const Matrix3f &m)
Definition: Transform.h:100
AffineTransform(AffineTransform *parent)
Definition: Transform.h:71
Eigen::Affine3f m_T
Definition: Transform.h:63
void FlipAxes(int first, int second)
Definition: Transform.h:127
void QuaternionRotate(const Vector4f &q)
Definition: Transform.h:116
void PreRotate(const Matrix3f &m)
Definition: Transform.h:114
AffineTransform()
Definition: Transform.h:66