FaceGen 3 SDKs Reference
Loading...
Searching...
No Matches
matrixCTA.hpp
1//
2// Copyright (c) Singular Inversions Inc. 2000.
3//
4// File: matrixCTA.hpp
5// Description: FutMatrixCTAC class declaration
6// Authors: Andrew Beatty
7// Created: 27/06/00
8//
9// This class represents an affine transform. An affine transform consists of
10// a linear transform plus a translation. In homogeneous representation this is
11// just a matrix of the form (as a 2D example):
12//
13// [ m11 m12 t1 ] [ x ] [ x' ]
14// [ m21 m22 t2 ] * [ y ] = [ y' ]
15// [ 0 0 1 ] [ 1 ] [ 1 ]
16//
17// Thus internally we store only (2D example):
18//
19// [ m11 m12 ] [ t1 ]
20// [ m21 m22 ] and [ t2 ]
21//
22// Note that the group of affine transforms is closed under addition and
23// multplication (as defined on the homogeneous matrix representation) and
24// that the inverse of any non-singular affine transform is also an affine
25// transform.
26//
27#ifndef FR2_MATRIXCTA_HPP
28#define FR2_MATRIXCTA_HPP
29
30#include "matrixCT.hpp"
31#include "vect2.hpp"
32
33namespace Fg {
34
35// We just use the default copy constructor and operator=, but we add
36// a constructor from the linear and translational components.
37//
38template <class T,const int size>
40{
41public:
42 FutMatrixCTAC() {};
43 FutMatrixCTAC(const FR2MatrixCTC<T,size,size>&, // Construct from a
44 const FR2MatrixCTC<T,size,1>&); // linear plus trans.
45
46 FutMatrixCTAC operator*(const FutMatrixCTAC&) const;// Multiply two of these.
47
48 FR2MatrixCTC<T,size,size> m_mat; // The linear transform component
49 FR2MatrixCTC<T,size,1> m_vec; // The translational component
50};
51
52//***********************************************************************
53// Aliases
54//***********************************************************************
55//
60
61//***********************************************************************
62// Constructor 2
63//***********************************************************************
64//
65template <class T,const int size>
67
70 : m_mat(m), m_vec(t) {};
71
72//***********************************************************************
73// Operator*
74//***********************************************************************
75//
76template <class T,const int size>
77inline FutMatrixCTAC<T,size> FutMatrixCTAC<T,size>::operator*(
78
79 const FutMatrixCTAC<T,size>& m2) const
80{
81 FutMatrixCTAC<T,size> retval;
82
83 retval.m_mat = m_mat * m2.m_mat;
84 retval.m_vec = m_vec + fr2MatMulCT<T,size,size,1>(m_mat,m2.m_vec);
85
86 return retval;
87}
88
89//***********************************************************************
90// Related Global Functions
91//***********************************************************************
92//
93// If hard-coded 2-vects or 3-vects are being used (for speed) then we
94// want to be compatible with that as well.
95//
96template <class T>
97inline FR2Vect2TC<T> operator*(
98
99 const FutMatrixCTAC<T,2>& m,
100 FR2Vect2TC<T> v)
101{
102 FR2Vect2TC<T> retval;
103
104 retval.x1 = m.m_mat[0][0] * v.x1 + m.m_mat[0][1] * v.x2 + m.m_vec[0][0];
105 retval.x2 = m.m_mat[1][0] * v.x1 + m.m_mat[1][1] * v.x2 + m.m_vec[1][0];
106
107 return retval;
108}
109
110template <class T>
111inline FR2Vect3TC<T> operator*(
112
113 const FutMatrixCTAC<T,3>& m,
114 FR2Vect3TC<T> v)
115{
116 return FR2Vect3TC<T>(
117
118 m.m_mat[0][0]*v.x1 + m.m_mat[0][1]*v.x2 + m.m_mat[0][2]*v.x3 +
119 m.m_vec[0][0],
120 m.m_mat[1][0]*v.x1 + m.m_mat[1][1]*v.x2 + m.m_mat[1][2]*v.x3 +
121 m.m_vec[1][0],
122 m.m_mat[2][0]*v.x1 + m.m_mat[2][1]*v.x2 + m.m_mat[2][2]*v.x3 +
123 m.m_vec[2][0]);
124}
125
126template<class T,const int size>
127std::ostream& operator<<(std::ostream& s,const FutMatrixCTAC<T,size> &v)
128{
129 s << "mat: " << v.m_mat << '\n';
130 s << "vec: " << v.m_vec << '\n';
131 return s;
132}
133
134}
135
136#endif