Public Types | Public Member Functions | Static Public Attributes

TRTK::Transform2D< T > Class Template Reference

Affine or projective transformation in 2D. More...

#include <Transform2D.hpp>

List of all members.

Public Types

enum  Unit { DEGREES, RADIANS }
enum  Error {
  DIVISION_BY_ZERO, INVALID_ARGUMENT, INVALID_UNIT, UNKNOWN_ERROR,
  WRONG_COORDINATE_SIZE
}
typedef T value_type
typedef Eigen::Matrix< T, 3, 3 > Matrix3T
typedef Eigen::Matrix< T, 3, 1 > Vector3T
typedef Eigen::Matrix< T, 2, 1 > Vector2T
typedef Coordinate< T > coordinate_type

Public Member Functions

 Transform2D ()
 Constructs an instance of Transform2D.
 Transform2D (const Matrix3T &)
 Constructs an instance of Transform2D.
 Transform2D (T a11, T a12, T a13, T a21, T a22, T a23, T a31, T a32, T a33)
 Constructs an instance of Transform2D.
template<class U >
 Transform2D (const Transform2D< U > &transform2D)
 Copy constructor.
virtual ~Transform2D ()
 Destroys the instance of Transform2D.
T & a11 ()
 Element access (readable and writable).
T & a12 ()
 Element access (readable and writable).
T & a13 ()
 Element access (readable and writable).
T & a21 ()
 Element access (readable and writable).
T & a22 ()
 Element access (readable and writable).
T & a23 ()
 Element access (readable and writable).
T & a31 ()
 Element access (readable and writable).
T & a32 ()
 Element access (readable and writable).
T & a33 ()
 Element access (readable and writable).
const T & a11 () const
 Read-only element access.
const T & a12 () const
 Read-only element access.
const T & a13 () const
 Read-only element access.
const T & a21 () const
 Read-only element access.
const T & a22 () const
 Read-only element access.
const T & a23 () const
 Read-only element access.
const T & a31 () const
 Read-only element access.
const T & a32 () const
 Read-only element access.
const T & a33 () const
 Read-only element access.
const Coordinate< T > operator* (const Coordinate< T > &) const
 Transforms a coordinate with the internally saved transformation.
const Matrix3T operator* (const Matrix3T &) const
 Composition of two transformations.
const Vector2T operator* (const Vector2T &) const
 Transforms a 2D vector with the internally saved transformation.
const Vector3T operator* (const Vector3T &) const
 Transforms a vector with the internally saved transformation.
const Transform2D operator* (const Transform2D &) const
 Composition of two transformations.
const Transform2D operator>> (const Transform2D &) const
 Composition of two transformations.
Matrix3T & getTransformationMatrix ()
 Returns the internal transformation matrix.
const Matrix3T & getTransformationMatrix () const
 Returns the internal transformation matrix.
const Transform2D inverse () const
 Returns the inverse transformation.
Transform2Dreset ()
 Sets the internal matrix to the identity matrix.
Transform2Drotate (const double angle, const Unit unit=RADIANS)
 Rotation.
Transform2Dscale (const T sx, const T sy)
 Non-uniform scaling.
Transform2Dshear (const T sx, const T sy)
 Shear mapping.
Transform2Dtranslate (const T dx, const T dy)
 Translation.
Transform2Dtranslate (const Coordinate< T > &position)
 Translation.
bool is_affine () const
 Returns whether the internally saved transformation is affine or not.

Static Public Attributes

static const double pi = 3.14159265358979323846264338327950288419716939937510

Detailed Description

template<class T>
class TRTK::Transform2D< T >

Affine or projective transformation in 2D.

This class provides means to transform 2D coordinates via an affine or a projective transformation. The transformation can be composed from a sequence of elementary transformations such as translation, scaling, rotation etc., or by directly setting the entries of a \( 3 \times 3 \) transformation matrix. The coordinates may be given as 2D or as 3D coordinates in case of homogeneous coordinates.

The transformation is computed by multiplying a \( 3 \times 3 \) matrix with a 3D homogeneous coordinate, followed by a potential normalization step. That is, if \( x \) is transformed to \( y \), first an intermediate vector \( w \) is computed

\[ \begin{pmatrix} w_1 \\ w_2 \\ w_3 \end{pmatrix} = \begin{pmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ 1 \end{pmatrix} \]

followed by a normalization step

\[ \begin{pmatrix} y_1 \\ y_2 \\ 1 \end{pmatrix} = \frac{1}{w_3} \begin{pmatrix} w_1 \\ w_2 \\ w_3 \end{pmatrix} \]

In case of affine transformations

\[ y = Ax + b \]

or

\[ \begin{pmatrix} y_1 \\ y_2 \\ 1 \end{pmatrix} = \begin{pmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ 1 \end{pmatrix} \]

the subsequent normalization step can be omitted, since the last entry of the above intermediate vector \( w \) would be \( 1 \) in any event.

Most functions check for certain assertions (e.g., if the coordinate size is valid) and trigger an assertion failure, if the assumption does not hold. This is meant for debugging purposes only, and can be disabled by defining the macro NDEBUG.

Here are some examples of how to use the Transform2D class:

Example 1:

 TRTK::Coordinate<double> coordinate(1, 4);
 TRTK::Transform2D<double> transform;

 const double pi = transform::pi;
 transform.rotate(pi/2).translate(2, 0);

 cout << transform * coordinate << endl;

Output:

 (-2, 1)

Example 2:

 using namespace TRTK;

 Coordinate<double> coordinate(1, 4);

 Transform2D<double> transform1;
 Transform2D<double> transform2;
 Transform2D<double> transform3;
 Transform2D<double> transform4;

 transform1.translate(1, 1);

 // rotation of 90 degrees
 transform2.a11() =  0;
 transform2.a12() =  1;
 transform2.a21() = -1;
 transform2.a22() =  0;

 transform3.translate(-1, 0);

 transform4 = transform3 * transform2 * transform1;

 cout << transform4 * coordinate << endl;

 transform4.reset() = transform1 >> transform2 >> transform3;

 cout << transform4 * coordinate << endl;

 cout << endl << transform4.getTransformationMatrix() << endl;

Output:

 (4, -2)
 (4, -2)

  0  1  0
 -1  0 -1
  0  0  1
See also:
Transform2D and Coordinate
Author:
Christoph Haenisch
Version:
0.1.2
Date:
last changed on 2011-09-24

Definition at line 201 of file Transform2D.hpp.


Constructor & Destructor Documentation

template<class T >
TRTK::Transform2D< T >::Transform2D (  )

Constructs an instance of Transform2D.

Template Parameters:
Tscalar type

The internal matrix is set to the identity matrix.

See also:
reset()

Definition at line 304 of file Transform2D.hpp.

template<class T >
TRTK::Transform2D< T >::Transform2D ( const Matrix3T &  matrix )

Constructs an instance of Transform2D.

Template Parameters:
Tscalar type
Parameters:
[in]matrixTranformation matrix.

Sets the internal matrix to the given matrix.

See also:
reset()

Definition at line 322 of file Transform2D.hpp.

template<class T>
TRTK::Transform2D< T >::Transform2D ( a11,
a12,
a13,
a21,
a22,
a23,
a31,
a32,
a33 
)

Constructs an instance of Transform2D.

Template Parameters:
Tscalar type

Sets the internal matrix to the given coefficients.

See also:
reset()

Definition at line 351 of file Transform2D.hpp.

template<class T >
template<class U >
TRTK::Transform2D< T >::Transform2D ( const Transform2D< U > &  transform2D )

Copy constructor.

Template Parameters:
Tscalar type of the newly created instance
Uscalar type of the copied instance
See also:
reset()

Definition at line 384 of file Transform2D.hpp.

template<class T >
TRTK::Transform2D< T >::~Transform2D (  ) [virtual]

Destroys the instance of Transform2D.

Template Parameters:
Tscalar type

Definition at line 409 of file Transform2D.hpp.


Member Function Documentation

template<class T >
T & TRTK::Transform2D< T >::a11 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{11} \).
See also:
reset()

Definition at line 424 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a11 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{11} \).
See also:
reset()

Definition at line 571 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a12 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{12} \).
See also:
reset()

Definition at line 440 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a12 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{12} \).
See also:
reset()

Definition at line 587 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a13 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{13} \).
See also:
reset()

Definition at line 456 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a13 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{13} \).
See also:
reset()

Definition at line 603 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a21 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{21} \).
See also:
reset()

Definition at line 472 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a21 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{21} \).
See also:
reset()

Definition at line 619 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a22 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{22} \).
See also:
reset()

Definition at line 488 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a22 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{22} \).
See also:
reset()

Definition at line 635 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a23 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{23} \).
See also:
reset()

Definition at line 504 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a23 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{23} \).
See also:
reset()

Definition at line 651 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a31 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{31} \).
See also:
reset()

Definition at line 667 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a31 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{31} \).
See also:
reset()

Definition at line 520 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a32 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{32} \).
See also:
reset()

Definition at line 537 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a32 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{32} \).
See also:
reset()

Definition at line 683 of file Transform2D.hpp.

template<class T >
T & TRTK::Transform2D< T >::a33 (  )

Element access (readable and writable).

Template Parameters:
Tscalar type
Returns:
Reference to internal matrix element \( a_{33} \).
See also:
reset()

Definition at line 554 of file Transform2D.hpp.

template<class T >
const T & TRTK::Transform2D< T >::a33 (  ) const

Read-only element access.

Template Parameters:
Tscalar type
Returns:
Internal matrix element \( a_{33}\).
See also:
reset()

Definition at line 699 of file Transform2D.hpp.

template<class T >
Transform2D< T >::Matrix3T & TRTK::Transform2D< T >::getTransformationMatrix (  )

Returns the internal transformation matrix.

Template Parameters:
Tscalar type
Returns:
Returns the internal transformation as 3x3 matrix representation.

Definition at line 1033 of file Transform2D.hpp.

template<class T >
const Transform2D< T >::Matrix3T & TRTK::Transform2D< T >::getTransformationMatrix (  ) const

Returns the internal transformation matrix.

Template Parameters:
Tscalar type
Returns:
Returns the internal transformation as 3x3 matrix representation.

Definition at line 1047 of file Transform2D.hpp.

template<class T >
const Transform2D< T > TRTK::Transform2D< T >::inverse (  ) const

Returns the inverse transformation.

Template Parameters:
Tscalar type
Returns:
A new copy.

Definition at line 1061 of file Transform2D.hpp.

template<class T >
bool TRTK::Transform2D< T >::is_affine (  ) const [inline]

Returns whether the internally saved transformation is affine or not.

Template Parameters:
Tscalar type
Returns:
Returns true, if the internal matrix is affine.

Definition at line 1252 of file Transform2D.hpp.

template<class T>
const Coordinate< T > TRTK::Transform2D< T >::operator* ( const Coordinate< T > &  coordinate ) const

Transforms a coordinate with the internally saved transformation.

Template Parameters:
Tscalar type
Parameters:
[in]coordinateCoordinate to be transformed. coordinate may be homogeneous.
Returns:
Transformed coordinate of the same size as the input coordinate.

The given coordinate must be of size two or three. If coordinate has a size of three (homogeneous coordinate), it is assumed that its last component is equal to one.

Example:

 TRTK::Coordinate<double> coordinate(1, 4);
 TRTK::Transform2D<double> transform;

 const double pi = TRTK::Transform2D<double>::pi;
 transform.rotate(pi/2).translate(2, 0);

 cout << transform * coordinate << endl;

Output:

 (-2, 1)

Definition at line 738 of file Transform2D.hpp.

template<class T>
const Transform2D< T > TRTK::Transform2D< T >::operator* ( const Transform2D< T > &  transform ) const

Composition of two transformations.

Template Parameters:
Tscalar type
Parameters:
[in]transformA transformation described by Transform2D.
Returns:
A Transform2D object describing the composition of the two transformations.

This function computes the composition of the currently internally saved transformation with the transformation given by transform. Here, the composition is a simple matrix multiplication.

Example:

 typedef TRTK::Transform2D<double> Transform;

 Transform T1(1,  1,  0,
              0,  2,  2,
              0,  0,  1);

 Transform T2(1,  0,  3,
              0, -1,  0,
              0,  0,  1);

 Transform T3 = T1 * T2;

 std::cout << T3.getTransformationMatrix();

Output:

 1 -1  3
 0 -2  2
 0  0  1
See also:
operator>>()

Definition at line 964 of file Transform2D.hpp.

template<class T>
const Transform2D< T >::Vector3T TRTK::Transform2D< T >::operator* ( const Vector3T &  vector ) const

Transforms a vector with the internally saved transformation.

Template Parameters:
Tscalar type
Parameters:
[in]vector3D vector to be transformed.
Returns:
Transformed 3D vector.

The vector is assumed to be a normalized homogeneous coordinate, i.e. its last component is assumed to be equal to one.

Example:

 TRTK::Transform2D<double> transform;
 TRTK::Transform2D<double>::Vector3T vec(1, 4, 1);

 const double pi = TRTK::Transform2D<double>::pi;
 transform.rotateZ(pi/2).translate(2, 0);

 std::cout << transform * vec;

Output:

 -2
 1
 1

Definition at line 856 of file Transform2D.hpp.

template<class T>
const Transform2D< T >::Vector2T TRTK::Transform2D< T >::operator* ( const Vector2T &  vector ) const

Transforms a 2D vector with the internally saved transformation.

Template Parameters:
Tscalar type
Parameters:
[in]vector2D vector to be transformed.
Returns:
Transformed 2D vector.

Example:

 TRTK::Transform2D<double> transform;
 TRTK::Transform2D<double>::Vector2T vec(1, 4);

 const double pi = TRTK::Transform2D<double>::pi;
 transform.rotateZ(pi/2).translate(2, 0);

 std::cout << transform * vec;

Output:

 -2
 1

Definition at line 807 of file Transform2D.hpp.

template<class T>
const Transform2D< T >::Matrix3T TRTK::Transform2D< T >::operator* ( const Matrix3T &  matrix ) const

Composition of two transformations.

Template Parameters:
Tscalar type
Parameters:
[in]matrix3x3 transformation matrix.
Returns:
3x3 transformation matrix.

This function computes the composition of the currently internally saved transformation with the transformation given by matrix. Here, the composition is a simple matrix multiplication.

Example:

 typedef TRTK::Transform2D<double> Transform;

 Transform T1(1,  1,  0,
              0,  2,  2,
              0,  0,  1);

 Transform::Matrix3T A;

 A << 1,  0,  3,
      0, -1,  0,
      0,  0,  1;

 Transform T2 = T1 * A;

 std::cout << T2.getTransformationMatrix();

Output:

 1 -1  3
 0 -2  2
 0  0  1

Definition at line 913 of file Transform2D.hpp.

template<class T >
const Transform2D< T > TRTK::Transform2D< T >::operator>> ( const Transform2D< T > &  transform ) const

Composition of two transformations.

Template Parameters:
Tscalar type
Parameters:
[in]transformA transformation described by Transform2D.
Returns:
A Transform2D object describing the composition of the two transformations.

This function computes the composition of the currently internally saved transformation with the transformation given by transform. Here, the composition is a simple matrix multiplication.

Example:

 typedef TRTK::Transform2D<double> Transform;

 Transform T1(1,  1,  0,
              0,  2,  2,
              0,  0,  1);

 Transform T2(1,  0,  3,
              0, -1,  0,
              0,  0,  1);

 Transform T3 = T1 >> T2; // == T2 * T1

 std::cout << T3.getTransformationMatrix();

Output:

 1  1  3
 0 -2 -2
 0  0  1
See also:
operator*()

Definition at line 1016 of file Transform2D.hpp.

template<class T >
Transform2D< T > & TRTK::Transform2D< T >::reset (  )

Sets the internal matrix to the identity matrix.

Template Parameters:
Tscalar type
Returns:
*this

Definition at line 1075 of file Transform2D.hpp.

template<class T >
Transform2D< T > & TRTK::Transform2D< T >::rotate ( const double  angle,
const Unit  unit = RADIANS 
)

Rotation.

Template Parameters:
Tscalar type
Parameters:
[in]angleAngle in degrees or radian.
[in]unitThe unit of angle.
Returns:
*this

Definition at line 1095 of file Transform2D.hpp.

template<class T>
Transform2D< T > & TRTK::Transform2D< T >::scale ( const T  sx,
const T  sy 
)

Non-uniform scaling.

Template Parameters:
Tscalar type
Parameters:
[in]sxScaling factor in x direction.
[in]syScaling factor in y direction.

This function scales the axes of the currently internally saved transformation.

Returns:
*this

Definition at line 1147 of file Transform2D.hpp.

template<class T>
Transform2D< T > & TRTK::Transform2D< T >::shear ( const T  sx,
const T  sy 
)

Shear mapping.

Template Parameters:
Tscalar type
Parameters:
[in]sxHorizontal shear (parallel to the x-axis).
[in]syVertical shear (parallel to the y-axis).

This function performs a shear mapping on the currently internally saved transformation.

Returns:
*this

Definition at line 1175 of file Transform2D.hpp.

template<class T>
Transform2D< T > & TRTK::Transform2D< T >::translate ( const Coordinate< T > &  position )

Translation.

Template Parameters:
Tscalar type
Parameters:
[in]positionTranslation (must be a coordinate of size 2)

This function adds a translation to the currently stored transformation.

Returns:
*this

Definition at line 1228 of file Transform2D.hpp.

template<class T>
Transform2D< T > & TRTK::Transform2D< T >::translate ( const T  dx,
const T  dy 
)

Translation.

Template Parameters:
Tscalar type
Parameters:
[in]dxTranslation in x direction.
[in]dyTranslation in y direction.

This function adds a translation to the currently stored transformation.

Returns:
*this

Definition at line 1202 of file Transform2D.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines