last update 20 Sep 2009 |
#include <cvrMatrixTransform.h>
Classes | |
class | helper2x2 |
Helper for 2x2 matrix transformations. More... | |
class | helper2x3 |
Helper for 2x3 matrix transformations. More... | |
class | helper3x3 |
Helper for 2x3 matrix transformations. More... | |
class | helper4x3 |
Helper for 4x3 matrix transformations. More... | |
class | helper4x4 |
Helper for 4x4 matrix transformations. More... | |
class | helperBase |
Base class of helpers. More... | |
class | parameters |
The parameters for the class matrixTransform<T>. More... | |
Public Member Functions | |
matrixTransform () | |
matrixTransform (const parameters &par) | |
matrixTransform (const matrixTransform< I > &other) | |
virtual | ~matrixTransform () |
virtual bool | apply (matrix< value_type > &srcdest) const |
virtual bool | apply (const matrix< value_type > &src, matrix< value_type > &dest) const |
virtual bool | apply (matrix< value_type > &srcdest, fpoint &offset) const |
virtual bool | apply (const matrix< value_type > &src, matrix< value_type > &dest, fpoint &offset) const |
matrixTransform & | copy (const matrixTransform< I > &other) |
matrixTransform & | operator= (const matrixTransform< I > &other) |
virtual const std::string & | name () const |
virtual matrixTransform< I > * | clone () const |
virtual matrixTransform< I > * | newInstance () const |
const parameters & | getParameters () const |
virtual bool | updateParameters () |
bool | setMatrix (const fmatrix &transMat) |
Point transformation tools | |
The following tools permit to transform individual points, which is useful when looking for the direct and inverse transformations of particular pixels.
Before using any of this methods you MUST call the use() method first, in order for this class to know in what context it has to work, i.e., since the position of a pixel in the transformed matrix depends entirely on the dimension of the original image and the parameter settings, the use() method precomputes everything necessary to later transform each pixel more efficiently. | |
bool | use (const ipoint &size) |
void | forwards (const fpoint &orig, fpoint &dest) const |
void | backwards (const fpoint &dest, fpoint &orig) const |
Protected Member Functions | |
parameters & | getParameters () |
Protected Attributes | |
helperBase * | helper_ |
fpoint | offset_ |
ipoint | usedSize_ |
This is a template class, used to geometrically transform an image using a linear transformation expressed through a matrix.
It is usefull for rotation and scaling operations.
It is usefull for rotation, scaling and translation operations.
The point is obtained with
It can be used for rotation, scaling and translation operations, but using the third line, more interesting mappings can be achieved.
The point is obtained with .
It can be used for rotation, scaling and translation operations, but using the third line, more interesting mappings can be achieved.
Please note that this configuration is in principle equivalent to a 3x3 matrix, as the third column is "absorved" by the z=0 assumption for the pixel positions on the image plane.
The point is obtained with .
It can be used for rotation, scaling and translation operations, but using the z coordinates, more interesting mappings can be achieved, like perspective projections.
The point is obtained with .
It can be used for rotation, scaling and translation operations, but using the z coordinates, more interesting mappings can be achieved, like perspective projections.
// type definitions just for shorter names. typedef cvr::nearestNeighborInterpolation<cvr::rgbaPixel> inter_type; typedef cvr::matrixTransform< inter_type > trans_type; trans_type transformer; // get an image to work with cvr::ioImage loader; cvr::viewer2D view("Image"); cvr::image img,img2; if (!loader.load("../img/testImg.bmp",img)) { std::cout << loader.getStatusString() << std::endl; exit(1); } cvr::fmatrix mat,pro; // generate a projection matrix to give a perspective effect pro = cvr::projection(1000.0f); cvr::ipoint o = img.size()/2; // animation of 360 images rotated. for (int deg=0;deg<=360;++deg) { float rad=degToRad(static_cast<float>(deg)); // angle in radians // generate a transformation matrix using several elemental operations mat = cvr::translation(fpoint3D(o.x,o.y,0)) * pro * cvr::rotation(fpoint3D(0.0f,0.0f,0.0f),fpoint3D(1,0,0),rad) * cvr::translation(fpoint3D(-o.x,-o.y,0)); transformer.setMatrix(mat); transformer.apply(img,img2); view.show(img2); }
cvr::matrixTransform< I >::matrixTransform | ( | ) |
Default constructor.
cvr::matrixTransform< I >::matrixTransform | ( | const parameters & | par | ) |
Construct a functor using the given parameters.
cvr::matrixTransform< I >::matrixTransform | ( | const matrixTransform< I > & | other | ) |
virtual cvr::matrixTransform< I >::~matrixTransform | ( | ) | [virtual] |
Destructor.
virtual bool cvr::matrixTransform< I >::apply | ( | const matrix< value_type > & | src, | |
matrix< value_type > & | dest, | |||
fpoint & | offset | |||
) | const [virtual] |
Transform geometrically the source image and leave the result on the destination container.
If the parameters specify to AdjustDimensions, then the offset value will contain the relative position of the dest origin with respect to the original image coordinate system. To all other resize policies, the value of offset is set to (0,0).
If you need to find out where in the rotated image is located the origin of the initial image, then that would be in -offset.
src | matrix<value_type> with the source data. | |
dest | matrix<value_type> where the result will be left. | |
offset | position of the origin of the result with respect to the coordinate system of the original image. |
Implements cvr::geometricTransform< I >.
virtual bool cvr::matrixTransform< I >::apply | ( | matrix< value_type > & | srcdest, | |
fpoint & | offset | |||
) | const [virtual] |
Transform geometrically the given image and leave the result on the same container.
If the parameters specify to AdjustDimensions, then the offset value will contain the relative position of the srcdest origin with respect to the original image coordinate system. To all other resize policies, the value of offset is set to (0,0).
If you need to find out where in the rotated image is located the origin of the initial image, then that would be in -offset.
srcdest | matrix<T> with the source data. The result will be left here too. | |
offset | position of the origin of the result with respect to the coordinate system of the original image. |
Reimplemented from cvr::geometricTransform< I >.
virtual bool cvr::matrixTransform< I >::apply | ( | const matrix< value_type > & | src, | |
matrix< value_type > & | dest | |||
) | const [virtual] |
Transform geometrically the source image and leave the result on the destination container.
Operates on a copy of the given parameters.
src | matrix<value_type> with the source data. | |
dest | matrix<value_type> where the result will be left. |
Implements cvr::geometricTransform< I >.
virtual bool cvr::matrixTransform< I >::apply | ( | matrix< value_type > & | srcdest | ) | const [virtual] |
Transform geometrically the given image and leave the result on the same container.
srcdest | matrix<T> with the source data. The result will be left here too. |
Reimplemented from cvr::geometricTransform< I >.
void cvr::matrixTransform< I >::backwards | ( | const fpoint & | dest, | |
fpoint & | orig | |||
) | const |
Inverse transform the given point coordinates.
dest
in the transformed system, it computes the coordinates of that point in the original coordinate system.
virtual matrixTransform<I>* cvr::matrixTransform< I >::clone | ( | ) | const [virtual] |
matrixTransform& cvr::matrixTransform< I >::copy | ( | const matrixTransform< I > & | other | ) |
void cvr::matrixTransform< I >::forwards | ( | const fpoint & | orig, | |
fpoint & | dest | |||
) | const |
Transform the given point coordinates.
parameters& cvr::matrixTransform< I >::getParameters | ( | ) | [protected] |
const parameters& cvr::matrixTransform< I >::getParameters | ( | ) | const |
virtual const std::string& cvr::matrixTransform< I >::name | ( | ) | const [virtual] |
virtual matrixTransform<I>* cvr::matrixTransform< I >::newInstance | ( | ) | const [virtual] |
matrixTransform& cvr::matrixTransform< I >::operator= | ( | const matrixTransform< I > & | other | ) |
bool cvr::matrixTransform< I >::setMatrix | ( | const fmatrix & | transMat | ) |
Shortcut for setting the transformation matrix without changing the rest of the parameters.
The matrix has to have valid dimensions: 2x2, 2x3, 3x3, 4x4 or 4x3.
virtual bool cvr::matrixTransform< I >::updateParameters | ( | ) | [virtual] |
bool cvr::matrixTransform< I >::use | ( | const ipoint & | size | ) |
Provide the size of the matrix from which it will be assumed the positions will be taken.
size | Size of the matrix from which the positions will be analyzed |
true
if everything is ok, or false
if the matrix set in the parameters is not invertible or some other weird problem.
helperBase* cvr::matrixTransform< I >::helper_ [protected] |
Pointer to the actual helper being used.
This pointer is managed by the updateParameters() method.
fpoint cvr::matrixTransform< I >::offset_ [protected] |
Last offset computed in use();.
ipoint cvr::matrixTransform< I >::usedSize_ [protected] |
Last size indicated with use().