cgv
Loading...
Searching...
No Matches
pose.h
Go to the documentation of this file.
1#pragma once
2
3#include "fvec.h"
4#include "fmat.h"
5#include "quaternion.h"
6#include <cassert>
7
12namespace cgv {
13 namespace math {
14
16template <typename T> fmat<T, 3, 3>& pose_orientation(fmat<T, 3, 4>& pose) { return reinterpret_cast<fmat<T, 3, 3>&>(pose); }
17template <typename T> const fmat<T, 3, 3>& pose_orientation(const fmat<T, 3, 4>& pose) { return reinterpret_cast<const fmat<T, 3, 3>&>(pose); }
19template <typename T> fvec<T, 3>& pose_position(fmat<T, 3, 4>& pose) { return reinterpret_cast<fvec<T, 3>&>(pose(0, 3)); }
20template <typename T> const fvec<T, 3>& pose_position(const fmat<T, 3, 4>& pose) { return reinterpret_cast<const fvec<T, 3>&>(pose(0, 3)); }
21
23template <typename T>
24fvec<T, 3> pose_transform_point(const fmat<T, 3, 4>& pose, const fvec<T, 3>& p) { return pose_orientation(pose)* p + pose_position(pose); }
26template <typename T>
27fvec<T, 3> pose_transform_point(const quaternion<T>& q, const fvec<T,3>& pos, const fvec<T, 3>& p) { return q.get_rotated(p) + pos; }
29template <typename T>
30fvec<T, 3> pose_transform_vector(const fmat<T, 3, 4>& pose, const fvec<T, 3>& v) { return pose_orientation(pose) * v; }
32template <typename T>
35template <typename T>
38template <typename T> void invert_pose(fmat<T, 3, 4>& pose) { pose_orientation(pose).transpose(); pose_position(pose) = -pose_orientation(pose)*pose_position(pose); }
40template <typename T> fmat<T, 3, 4> pose_inverse(const fmat<T, 3, 4>& pose) { fmat<T, 3, 4> inv_pose = pose; invert_pose(inv_pose); return inv_pose; }
42template <typename T> fmat<T, 3, 4> pose_construct(const fmat<T, 3, 3>& orientation, const fvec<T, 3>& position) { fmat<T, 3, 4> pose; pose_orientation(pose) = orientation; pose_position(pose) = position; return pose; }
44template <typename T> fmat<T, 3, 4> pose_construct(const quaternion<T>& orientation, const fvec<T, 3>& position) { fmat<T, 3, 4> pose; orientation.put_matrix(pose_orientation(pose)); pose_position(pose) = position; return pose; }
46template <typename T> void pose_append(fmat<T, 3, 4>& pose_1, const fmat<T, 3, 4>& pose_2) {
47 pose_position(pose_1) += pose_orientation(pose_1)*pose_position(pose_2);
48 pose_orientation(pose_1) *= pose_orientation(pose_2);
49}
56template <typename T> fmat<T, 3, 4> pose_concat(const fmat<T, 3, 4>& pose_1, const fmat<T, 3, 4>& pose_2) {
57 fmat<T, 3, 4> pose = pose_1;
58 pose_append(pose, pose_2);
59 return pose;
60}
61
62 }
63}
matrix of fixed size dimensions
Definition fmat.h:23
A vector with zero based index.
Definition fvec.h:26
implements a quaternion.
Definition quaternion.h:21
vec_type get_rotated(const vec_type &v) const
return rotated vector
Definition quaternion.h:200
void put_matrix(mat_type &M) const
compute equivalent 3x3 rotation matrix
Definition quaternion.h:139
the cgv namespace
Definition print.h:11
fvec< T, 3 > pose_transform_vector(const fmat< T, 3, 4 > &pose, const fvec< T, 3 > &v)
transform vector with pose matrix
Definition pose.h:30
fvec< T, 3 > & pose_position(fmat< T, 3, 4 > &pose)
extract position vector from pose matrix
Definition pose.h:19
fmat< T, 3, 4 > pose_concat(const fmat< T, 3, 4 > &pose_1, const fmat< T, 3, 4 > &pose_2)
return concatenate of two pose transformations
Definition pose.h:56
void pose_transform(const fmat< T, 3, 4 > &pose_transform, fmat< T, 3, 4 > &pose)
inplace transformation of a pose matrix with another pose transformation matrix
Definition pose.h:51
fvec< T, 3 > pose_transform_point(const fmat< T, 3, 4 > &pose, const fvec< T, 3 > &p)
transform point with pose matrix
Definition pose.h:24
void pose_append(fmat< T, 3, 4 > &pose_1, const fmat< T, 3, 4 > &pose_2)
inplace concatenation of a pose matrix
Definition pose.h:46
fmat< T, 3, 4 > pose_construct(const fmat< T, 3, 3 > &orientation, const fvec< T, 3 > &position)
construct pose from rotation matrix and position vector
Definition pose.h:42
fmat< T, 3, 3 > & pose_orientation(fmat< T, 3, 4 > &pose)
extract orientation matrix from pose matrix
Definition pose.h:16
fvec< T, 3 > inverse_pose_transform_vector(const fmat< T, 3, 4 > &pose, const fvec< T, 3 > &v)
transform vector with inverse of pose matrix
Definition pose.h:36
void invert_pose(fmat< T, 3, 4 > &pose)
inplace inversion of pose transformation
Definition pose.h:38
fmat< T, 3, 4 > pose_inverse(const fmat< T, 3, 4 > &pose)
return a pose matrix with the inverse pose transformation
Definition pose.h:40
fvec< T, 3 > inverse_pose_transform_point(const fmat< T, 3, 4 > &pose, const fvec< T, 3 > &p)
transform point with inverse of pose matrix
Definition pose.h:33