1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkTransform2D.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 // .NAME vtkTransform2D - describes linear transformations via a 3x3 matrix
17 // .SECTION Description
18 // A vtkTransform2D can be used to describe the full range of linear (also
19 // known as affine) coordinate transformations in two dimensions,
20 // which are internally represented as a 3x3 homogeneous transformation
21 // matrix.  When you create a new vtkTransform2D, it is always initialized
22 // to the identity transformation.
23 //
24 // This class performs all of its operations in a right handed
25 // coordinate system with right handed rotations. Some other graphics
26 // libraries use left handed coordinate systems and rotations.
27 
28 #ifndef vtkTransform2D_h
29 #define vtkTransform2D_h
30 
31 #include "vtkCommonTransformsModule.h" // For export macro
32 #include "vtkObject.h"
33 
34 #include "vtkMatrix3x3.h" // Needed for inline methods
35 
36 class vtkPoints2D;
37 
38 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform2D : public vtkObject
39 {
40  public:
41   static vtkTransform2D *New();
42   vtkTypeMacro(vtkTransform2D,vtkObject);
43   void PrintSelf(ostream& os, vtkIndent indent);
44 
45   // Description:
46   // Set the transformation to the identity transformation.
47   void Identity();
48 
49   // Description:
50   // Invert the transformation.
51   void Inverse();
52 
53   // Description:
54   // Create a translation matrix and concatenate it with the current
55   // transformation.
56   void Translate(double x, double y);
Translate(const double x[2])57   void Translate(const double x[2]) { this->Translate(x[0], x[1]); }
Translate(const float x[2])58   void Translate(const float x[2]) { this->Translate(x[0], x[1]); }
59 
60   // Description:
61   // Create a rotation matrix and concatenate it with the current
62   // transformation. The angle is in degrees.
63   void Rotate(double angle);
64 
65   // Description:
66   // Create a scale matrix (i.e. set the diagonal elements to x, y)
67   // and concatenate it with the current transformation.
68   void Scale(double x, double y);
Scale(const double s[2])69   void Scale(const double s[2]) { this->Scale(s[0], s[1]); }
Scale(const float s[2])70   void Scale(const float s[2]) { this->Scale(s[0], s[1]); }
71 
72   // Description:
73   // Set the current matrix directly.
SetMatrix(vtkMatrix3x3 * matrix)74   void SetMatrix(vtkMatrix3x3 *matrix) {
75     this->SetMatrix(matrix->GetData()); }
76   void SetMatrix(const double elements[9]);
77 
78   // Description:
79   // Get the underlying 3x3 matrix.
80   vtkGetObjectMacro(Matrix, vtkMatrix3x3);
81   void GetMatrix(vtkMatrix3x3 *matrix);
82 
83   // Description:
84   // Return the position from the current transformation matrix as an array
85   // of two floating point numbers. This is simply returning the translation
86   // component of the 3x3 matrix.
87   void GetPosition(double pos[2]);
GetPosition(float pos[2])88   void GetPosition(float pos[2]) {
89     double temp[2];
90     this->GetPosition(temp);
91     pos[0] = static_cast<float>(temp[0]);
92     pos[1] = static_cast<float>(temp[1]); }
93 
94   // Description:
95   // Return the x and y scale from the current transformation matrix as an array
96   // of two floating point numbers. This is simply returning the scale
97   // component of the 3x3 matrix.
98   void GetScale(double pos[2]);
GetScale(float pos[2])99   void GetScale(float pos[2]) {
100     double temp[2];
101     this->GetScale(temp);
102     pos[0] = static_cast<float>(temp[0]);
103     pos[1] = static_cast<float>(temp[1]); }
104 
105   // Description:
106   // Return a matrix which is the inverse of the current transformation
107   // matrix.
108   void GetInverse(vtkMatrix3x3 *inverse);
109 
110   // Description:
111   // Return a matrix which is the transpose of the current transformation
112   // matrix.  This is equivalent to the inverse if and only if the
113   // transformation is a pure rotation with no translation or scale.
114   void GetTranspose(vtkMatrix3x3 *transpose);
115 
116   // Description:
117   // Override GetMTime to account for input and concatenation.
118   unsigned long GetMTime();
119 
120   // Description:
121   // Apply the transformation to a series of points, and append the
122   // results to outPts. Where n is the number of points, and the float pointers
123   // are of length 2*n.
124   void TransformPoints(const float *inPts, float *outPts, int n);
125 
126   // Description:
127   // Apply the transformation to a series of points, and append the
128   // results to outPts. Where n is the number of points, and the float pointers
129   // are of length 2*n.
130   void TransformPoints(const double *inPts, double *outPts, int n);
131 
132   // Description:
133   // Apply the transformation to a series of points, and append the
134   // results to outPts.
135   void TransformPoints(vtkPoints2D *inPts, vtkPoints2D *outPts);
136 
137   // Description:
138   // Apply the transformation to a series of points, and append the
139   // results to outPts. Where n is the number of points, and the float pointers
140   // are of length 2*n.
141   void InverseTransformPoints(const float *inPts, float *outPts, int n);
142 
143   // Description:
144   // Apply the transformation to a series of points, and append the
145   // results to outPts. Where n is the number of points, and the float pointers
146   // are of length 2*n.
147   void InverseTransformPoints(const double *inPts, double *outPts, int n);
148 
149   // Description:
150   // Apply the transformation to a series of points, and append the
151   // results to outPts.
152   void InverseTransformPoints(vtkPoints2D *inPts, vtkPoints2D *outPts);
153 
154   // Description:
155   // Use this method only if you wish to compute the transformation in
156   // homogeneous (x,y,w) coordinates, otherwise use TransformPoint().
157   // This method calls this->GetMatrix()->MultiplyPoint().
MultiplyPoint(const float in[3],float out[3])158   void MultiplyPoint(const float in[3], float out[3]) {
159     this->GetMatrix()->MultiplyPoint(in,out);};
MultiplyPoint(const double in[3],double out[3])160   void MultiplyPoint(const double in[3], double out[3]) {
161     this->GetMatrix()->MultiplyPoint(in,out);};
162 
163 protected:
164   vtkTransform2D ();
165   ~vtkTransform2D ();
166 
167   void InternalDeepCopy(vtkTransform2D *t);
168 
169   vtkMatrix3x3 *Matrix;
170   vtkMatrix3x3 *InverseMatrix;
171 
172 private:
173   vtkTransform2D (const vtkTransform2D&);  // Not implemented
174   void operator=(const vtkTransform2D&);  // Not implemented
175 };
176 
177 #endif
178