cgv
rigid_transform.h
1 #pragma once
2 
3 #include <cgv/math/fvec.h>
4 #include <cgv/math/quaternion.h>
5 #include <cgv/math/fmat.h>
6 
7 namespace cgv {
8  namespace math {
9 
12 template <typename T>
14 {
15 public:
26 protected:
31 public:
33  rigid_transform() : q(1,0,0,0), t(0,0,0) {}
35  rigid_transform(const quat_type& _q, const vec_type& _t) : q(_q), t(_t) {}
37  void transform_vector(vec_type& v) const { q.rotate(v); }
39  void transform_point(vec_type& p) const { q.rotate(p); p += t; }
43  rigid_transform<T>& operator += (const rigid_transform<T>& T) { q += T.q; t += T.t; return *this; }
45  rigid_transform<T>& operator *= (T s) { q.vec() *= s; t *= s; return *this; }
47  rigid_transform<T> operator * (T s) const { rigid_transform<T> r(*this); r *= s; return r; }
49  void normalize() { q.normalize(); }
51  rigid_transform<T> inverse() const { return rigid_transform<T>(q.inverse(), q.inverse().apply(-t)); }
53  vec_type get_transformed_vector(const vec_type& v) const { return q.apply(v); }
55  vec_type get_transformed_point(const vec_type& p) const { return q.apply(p)+t; }
57  const vec_type& get_translation() const { return t; }
59  vec_type& ref_translation() { return t; }
61  const quat_type& get_quaternion() const { return q; }
63  quat_type& ref_quaternion() { return q; }
65  hmat_type get_hmat() const {
66  T M[9];
67  q.put_matrix(M);
68  hmat_type H;
69  H.set_col(0, hvec_type(M[0], M[3], M[6], 0));
70  H.set_col(1, hvec_type(M[1], M[4], M[7], 0));
71  H.set_col(2, hvec_type(M[2], M[5], M[8], 0));
72  H.set_col(3, hvec_type(t(0), t(1), t(2), 1));
73  return H;
74  }
77  T M[9];
78  q.put_matrix(M);
79  hmat_type H;
80  H.set_row(0, hvec_type(M[0], M[3], M[6], 0));
81  H.set_row(1, hvec_type(M[1], M[4], M[7], 0));
82  H.set_row(2, hvec_type(M[2], M[5], M[8], 0));
83  H.set_row(3, hvec_type(t(0), t(1), t(2), 1));
84  return H;
85  }
86 };
87 
88  }
89 }
cgv::math::rigid_transform::ref_translation
vec_type & ref_translation()
return the translational part
Definition: rigid_transform.h:59
cgv::math::fvec::normalize
double normalize()
normalize the vector using the L2-Norm and return the length
Definition: fvec.h:260
cgv::math::fmat
matrix of fixed size dimensions
Definition: fmat.h:23
cgv::math::rigid_transform::transform_point
void transform_point(vec_type &p) const
apply transformation to point
Definition: rigid_transform.h:39
cgv::math::rigid_transform::get_translation
const vec_type & get_translation() const
return the translational part
Definition: rigid_transform.h:57
cgv::math::rigid_transform::t
vec_type t
and translation vector
Definition: rigid_transform.h:30
cgv::math::fvec< T, 3 >
cgv::math::quaternion::apply
vec_type apply(const vec_type &v) const
rotate vector according to quaternion
Definition: quaternion.h:202
cgv::math::quaternion
Definition: quaternion.h:15
cgv::math::rigid_transform::quat_type
cgv::math::quaternion< T > quat_type
type of quaternions
Definition: rigid_transform.h:21
cgv::math::rigid_transform::vec_type
cgv::math::fvec< T, 3 > vec_type
type of 3d vector
Definition: rigid_transform.h:17
cgv::math::fmat::set_col
void set_col(unsigned j, const fvec< T, N > &v)
set column j of the matrix to vector v
Definition: fmat.h:163
cgv::math::rigid_transform::get_transposed_hmat
hmat_type get_transposed_hmat() const
convert transformation to transpose of homogeneous transformation
Definition: rigid_transform.h:76
cgv::math::rigid_transform::operator+=
rigid_transform< T > & operator+=(const rigid_transform< T > &T)
multiply quaternion and translation with scalar
Definition: rigid_transform.h:43
cgv::math::rigid_transform::operator*
rigid_transform< T > operator*(const rigid_transform< T > &M) const
concatenate two rigid transformations
Definition: rigid_transform.h:41
cgv::math::fmat::set_row
void set_row(unsigned i, const fvec< T, M > &v)
set row i of the matrix to vector v
Definition: fmat.h:154
cgv::math::rigid_transform::mat_type
cgv::math::fmat< T, 3, 3 > mat_type
type of 3x3 matrix
Definition: rigid_transform.h:23
cgv::math::quaternion::inverse
quaternion< T > inverse() const
return the inverse
Definition: quaternion.h:215
cgv::math::rigid_transform::ref_quaternion
quat_type & ref_quaternion()
return the rotation as quaternion
Definition: rigid_transform.h:63
cgv::math::rigid_transform::inverse
rigid_transform< T > inverse() const
return the inverse transformation
Definition: rigid_transform.h:51
cgv::math::rigid_transform::get_transformed_vector
vec_type get_transformed_vector(const vec_type &v) const
apply transformation to vector
Definition: rigid_transform.h:53
cgv::math::rigid_transform::get_transformed_point
vec_type get_transformed_point(const vec_type &p) const
apply transformation to point
Definition: rigid_transform.h:55
cgv::math::rigid_transform
Definition: rigid_transform.h:14
cgv::math::rigid_transform::transform_vector
void transform_vector(vec_type &v) const
apply transformation to vector
Definition: rigid_transform.h:37
cgv::math::rigid_transform::get_hmat
hmat_type get_hmat() const
convert transformation to homogeneous transformation
Definition: rigid_transform.h:65
cgv::math::rigid_transform::hvec_type
cgv::math::fvec< T, 4 > hvec_type
type of homogenous vector
Definition: rigid_transform.h:19
cgv::math::rigid_transform::q
quat_type q
store transformation as quaternion
Definition: rigid_transform.h:28
cgv::math::quaternion::put_matrix
void put_matrix(mat_type &M) const
compute equivalent 3x3 rotation matrix
Definition: quaternion.h:122
cgv::math::rigid_transform::rigid_transform
rigid_transform(const quat_type &_q, const vec_type &_t)
construct from quaternion and translation vector to the transformation that first rotates and then tr...
Definition: rigid_transform.h:35
cgv::math::quaternion::rotate
void rotate(vec_type &v) const
rotate vector according to quaternion
Definition: quaternion.h:181
cgv::math::rigid_transform::rigid_transform
rigid_transform()
construct identity
Definition: rigid_transform.h:33
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::math::rigid_transform::hmat_type
cgv::math::fmat< T, 4, 4 > hmat_type
type of 4x4 matrix
Definition: rigid_transform.h:25
cgv::math::rigid_transform::get_quaternion
const quat_type & get_quaternion() const
return the rotation as quaternion
Definition: rigid_transform.h:61
cgv::math::rigid_transform::operator*=
rigid_transform< T > & operator*=(T s)
multiply quaternion and translation with scalar
Definition: rigid_transform.h:45