#include <projective.h>
Public Member Functions | |
T * | array () |
Has the same meaning as in class Matrix<T, Size+1>. | |
const T * | array () const |
Has the same meaning as in class Matrix<T, Size+1>. | |
void | getLinearComponent (Matrix< T, Size > *res) const |
void | getTranslationVector (Vector< T, Size > *res) const |
Matrix< T, Size > | linearComponent () const |
void | linearMultiply (const Vector< T, Size > &vector, Vector< T, Size > *res) const |
MatrixP & | loadIdentity () |
MatrixP & | loadMatrix (const Matrix< T, Size > &matrix) |
MatrixP & | loadRotation2 (const T &angle) |
MatrixP & | loadRotation3 (const T &angle, const Vector< T, Size > &axis) |
MatrixP & | loadScaling (const Vector< T, Size > &coeffs) |
MatrixP & | loadScaling (const T &coeff) |
MatrixP & | loadTranslation (const Vector< T, Size > &v) |
MatrixP & | loadZero () |
Matrix< T, Size+1 > & | matrix () |
Returns a reference to the matrix as a Matrix<T, Size+1>. | |
const Matrix< T, Size+1 > & | matrix () const |
Returns a reference to the matrix as a Matrix<T, Size+1>. | |
MatrixP (const Matrix< T, Size > &other) | |
MatrixP (const Matrix< T, Size+1 > &other) | |
MatrixP (const MatrixP &other) | |
MatrixP () | |
void | multiply (const Vector< T, Size+1 > &vector, Vector< T, Size+1 > *res) const |
void | multiply (const Vector< T, Size > &vector, Vector< T, Size > *res) const |
void | multiply (const MatrixP &other, MatrixP *res) const |
T & | operator() (int row, int col) |
Has the same meaning as in class Matrix<T, Size+1>. | |
const T & | operator() (int row, int col) const |
Has the same meaning as in class Matrix<T, Size+1>. | |
Vector< T, Size+1 > | operator* (const Vector< T, Size+1 > &vector) const |
Vector< T, Size > | operator* (const Vector< T, Size > &vector) const |
MatrixP | operator* (const MatrixP &other) const |
MatrixP & | operator*= (const MatrixP &other) |
MatrixP & | operator= (const MatrixP &other) |
T & | operator[] (int i) |
Has the same meaning as in class Matrix<T, Size+1>. | |
const T & | operator[] (int i) const |
Has the same meaning as in class Matrix<T, Size+1>. | |
MatrixP & | prerotate2 (const T &angle) |
MatrixP & | prerotate3 (const T &angle, const Vector< T, Size > &axis) |
MatrixP & | prescale (const Vector< T, Size > &coeffs) |
MatrixP & | prescale (const T &coeff) |
MatrixP & | pretranslate (const Vector< T, Size > &v) |
void | resetLastRow () |
void | resetTranslationVector () |
MatrixP & | rotate2 (const T &angle) |
MatrixP & | rotate3 (const T &angle, const Vector< T, Size > &axis) |
MatrixP & | scale (const Vector< T, Size > &coeffs) |
MatrixP & | scale (const T &coeff) |
void | setLinearComponent (const Matrix< T, Size > &matrix) |
void | setTranslationVector (const Vector< T, Size > &v) |
MatrixP & | translate (const Vector< T, Size > &v) |
Vector< T, Size > | translationVector () const |
Protected Attributes | |
Matrix< T, Size+1 > | m_mat |
The matrix itself. |
It's sometimes useful to add one dimension to the space you're working in. For instance, that allows to represent translations as matrices, which is otherwise impossible.
Internally, a MatrixP<T, n> is just a Matrix<T, n+1>. The difference is that it's regarded as a homography acting on the n-dimensional projective space, instead of being regarded as a linear map acting on the n-dimensional vector space.
The correspondence between "ordinary" vectors of size n and "projective" vectors of size n+1 is as follows. Given an ordinary vector , the corresponding projective vector is
. Conversely, given a projective vector
, the corresponding ordinary vector is
. If
, then the projective vector doesn't correspond to any ordinary one, and is called a "direction at infinity".
The following typedefs are provided to cover the usual cases:
typedef MatrixP<double, 2> MatrixP2d; typedef MatrixP<double, 3> MatrixP3d; typedef MatrixP<double, 4> MatrixP4d; typedef MatrixP<float, 2> MatrixP2f; typedef MatrixP<float, 3> MatrixP3f; typedef MatrixP<float, 4> MatrixP4f; typedef MatrixP<std::complex<double>, 2> MatrixP2cd; typedef MatrixP<std::complex<double>, 3> MatrixP3cd; typedef MatrixP<std::complex<double>, 4> MatrixP4cd; typedef MatrixP<std::complex<float>, 2> MatrixP2cf; typedef MatrixP<std::complex<float>, 3> MatrixP3cf; typedef MatrixP<std::complex<float>, 4> MatrixP4cf;
For example, in an OpenGL application, the Modelview and Projection matrices can be represented as objects of MatrixP3d or MatrixP3f according to whether one prefers to work over doubles or over floats.
Another example is Qt's QMatrix class: it is equivalent to Eigen's MatrixP2d.
Tthe meaning of the entries in a MatrixP is as follows:
Here,
Note that the last row is supposed to always be equal to 0,...,0,1. Don't alter it unless you know what you're doing. However keeping it is still useful for instance for OpenGL compatibility.
When multiplying another Vector<T, Size> V by such a MatrixP, the linear component is first applied, and then the result is translated by the translation vector. Thus, the result is
Constructs a MatrixP from a Matrix<T, Size> by calling loadMatrix().
T* array | ( | ) | [inline] |
Has the same meaning as in class Matrix<T, Size+1>.
const T* array | ( | ) | const [inline] |
Has the same meaning as in class Matrix<T, Size+1>.
void getLinearComponent | ( | Matrix< T, Size > * | res | ) | const [inline] |
Stores into *res the linear component, i.e. the (Size x Size) topleft block.
void getTranslationVector | ( | Vector< T, Size > * | res | ) | const [inline] |
Copies into *res the Size first entries of the last column of the matrix.
Matrix<T, Size> linearComponent | ( | ) | const [inline] |
Returns the linear component, i.e. the (Size x Size) topleft block.
Applies the linear component of the homography represented by *this to vector, and stores the result in *res. This is the same thing as multiply( const Vector<T,Size> &, Vector<T, Size> *) const, except that the translation coefficients of *this are ignored. In other words the last column of *this is ignored and the computation is done as if it were 0,...0,1.
MatrixP& loadIdentity | ( | ) | [inline] |
Calls Matrix::loadIdentity().
Loads into *this a MatrixP constructed from a Matrix<T, Size>, by calling setLinearComponent(), and then resetLastRow() and resetTranslationVector(). The last row and last column are filled with 0's, except for the bottom-right corner entry which is set to 1. The resulting MatrixP has the same action on vectors as the original Matrix had.
MatrixP& loadRotation2 | ( | const T & | angle | ) | [inline] |
Sets *this to be the rotation matrix of given angle in radians. See Matrix::loadRotation2(). The template parameter Size must equal 2.
Sets *this to be the rotation matrix of given angle in radians around given axis vector. See Matrix::loadRotation3(). The template parameter Size must equal 3.
Sets *this to be the scaling matrix with given vector of scaling coefficients.
MatrixP& loadScaling | ( | const T & | coeff | ) | [inline] |
Sets *this to be the scaling matrix with given homogeneous scaling coefficient.
Sets *this to be a translation matrix, with translation vector given by v.
MatrixP& loadZero | ( | ) | [inline] |
Calls Matrix::loadZero().
const Matrix<T, Size+1>& matrix | ( | ) | const [inline] |
Returns a reference to the matrix as a Matrix<T, Size+1>.
Calls Matrix::multiply(). Thus, for vectors of size Size+1, the multiplication is done as if *this were an ordinary matrix. This method is faster than operator* because it doesn't perform useless copies.
Applies the homography represented by *this to vector, and stores the result in *res. Thus the linear component of *this is applied to vector, and then vector is translated by the translation coefficients of *this. This method is faster than operator* because it doesn't perform useless copies.
Matrix-matrix product. Calls Matrix::multiply(). This stores in *res the product (*this) * other. This method is faster than operator*= and operator* because it doesn't perform useless copies.
T& operator() | ( | int | row, | |
int | col | |||
) | [inline] |
Has the same meaning as in class Matrix<T, Size+1>.
const T& operator() | ( | int | row, | |
int | col | |||
) | const [inline] |
Has the same meaning as in class Matrix<T, Size+1>.
Calls Matrix::operator*(). Thus, for vectors of size Size+1, the multiplication is done as if *this were an ordinary matrix.
Returns the product of vector by *this, as computed by multiply( const Vector<T, Size> &, Vector<T, Size> * ).
Matrix-matrix product. Calls Matrix::operator*(). For better performance use multiply(const MatrixP &, MatrixP *) const instead.
Matrix-matrix product. Calls Matrix::operator*=().
Calls Matrix::operator=().
T& operator[] | ( | int | i | ) | [inline] |
Has the same meaning as in class Matrix<T, Size+1>.
const T& operator[] | ( | int | i | ) | const [inline] |
Has the same meaning as in class Matrix<T, Size+1>.
MatrixP& prerotate2 | ( | const T & | angle | ) | [inline] |
Multiplies *this on the left by the rotation matrix of given angle in radians. See Matrix::loadRotation2(). The template parameter Size must equal 2.
Multiplies *this on the left by the rotation matrix of given angle in radians around given axis vector. See Matrix::loadRotation3(). The template parameter Size must equal 3.
Multiplies *this on the left by the scaling matrix with given vector of scaling coefficients.
MatrixP& prescale | ( | const T & | coeff | ) | [inline] |
Multiplies *this on the left by the scaling matrix with given homogeneous scaling coefficient.
Multiplies *this on the left by the translation matrix with translation vector given by v.
void resetLastRow | ( | ) | [inline] |
Sets the last row to be 0,...,0,1.
void resetTranslationVector | ( | ) | [inline] |
Sets the last column entries to 0, except for the last row which is left unmodified.
MatrixP& rotate2 | ( | const T & | angle | ) | [inline] |
Multiplies *this on the right by the rotation matrix of given angle in radians. See Matrix::loadRotation2(). The template parameter Size must equal 2.
Multiplies *this on the right by the rotation matrix of given angle in radians around given axis vector. See Matrix::loadRotation3(). The template parameter Size must equal 3.
Multiplies *this on the right by the scaling matrix with given vector of scaling coefficients.
MatrixP& scale | ( | const T & | coeff | ) | [inline] |
Multiplies *this on the right by the scaling matrix with given homogeneous scaling coefficient.
void setLinearComponent | ( | const Matrix< T, Size > & | matrix | ) | [inline] |
Sets the linear component of *this, i.e. the (Size x Size) topleft block. The last row and column are unaffected
void setTranslationVector | ( | const Vector< T, Size > & | v | ) | [inline] |
Copies v into the Size first entries of the last column of the matrix.
Multiplies *this on the right by the translation matrix with translation vector given by v.
Vector<T, Size> translationVector | ( | ) | const [inline] |
Returns a vector whose coords are the Size first entries of the last column of the matrix.