VTK  9.1.0
vtkMatrix4x4.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkMatrix4x4.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=========================================================================*/
38#ifndef vtkMatrix4x4_h
39#define vtkMatrix4x4_h
40
41#include "vtkCommonMathModule.h" // For export macro
42#include "vtkObject.h"
43
44class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
45{
46public:
48 double Element[4][4];
49
53 static vtkMatrix4x4* New();
54
55 vtkTypeMacro(vtkMatrix4x4, vtkObject);
56 void PrintSelf(ostream& os, vtkIndent indent) override;
57
63 {
64 vtkMatrix4x4::DeepCopy(*this->Element, source);
65 this->Modified();
66 }
67
72 static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
73 {
74 vtkMatrix4x4::DeepCopy(destination, *source->Element);
75 }
76
81 static void DeepCopy(double destination[16], const double source[16]);
82
87 void DeepCopy(const double elements[16])
88 {
89 this->DeepCopy(*this->Element, elements);
90 this->Modified();
91 }
92
96 void Zero()
97 {
98 vtkMatrix4x4::Zero(*this->Element);
99 this->Modified();
100 }
101 static void Zero(double elements[16]);
102
106 void Identity()
107 {
108 vtkMatrix4x4::Identity(*this->Element);
109 this->Modified();
110 }
111 static void Identity(double elements[16]);
112
116 bool IsIdentity();
117
122 static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
123 {
125 out->Modified();
126 }
127 void Invert() { vtkMatrix4x4::Invert(this, this); }
128 static void Invert(const double inElements[16], double outElements[16]);
129
133 static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
134 {
136 out->Modified();
137 }
138 void Transpose() { vtkMatrix4x4::Transpose(this, this); }
139 static void Transpose(const double inElements[16], double outElements[16]);
140
145 void MultiplyPoint(const float in[4], float out[4])
146 {
147 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
148 }
149 void MultiplyPoint(const double in[4], double out[4])
150 {
151 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
152 }
153
154 static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
155 static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
156
160 float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
161 double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
162 {
163 return this->MultiplyDoublePoint(in);
164 }
165 float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
166 {
167 this->MultiplyPoint(in, this->FloatPoint);
168 return this->FloatPoint;
169 }
170 double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
171 {
172 this->MultiplyPoint(in, this->DoublePoint);
173 return this->DoublePoint;
174 }
175
177
180 static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
181 static void Multiply4x4(const double a[16], const double b[16], double c[16]);
182 static void Multiply4x4(const double a[16], const double b[16], float c[16]);
183 static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
185
189 void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
190 {
192 }
193 static void Adjoint(const double inElements[16], double outElements[16]);
194
198 double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
199 static double Determinant(const double elements[16]);
200
204 void SetElement(int i, int j, double value);
205
209 double GetElement(int i, int j) const { return this->Element[i][j]; }
210
214 double* GetData() { return *this->Element; }
215
219 const double* GetData() const { return *this->Element; }
220
221protected:
223 ~vtkMatrix4x4() override = default;
224
225 float FloatPoint[4];
226 double DoublePoint[4];
227
228private:
229 vtkMatrix4x4(const vtkMatrix4x4&) = delete;
230 void operator=(const vtkMatrix4x4&) = delete;
231};
232
233//----------------------------------------------------------------------------
234// Multiplies matrices a and b and stores the result in c.
235inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
236{
237 double tmp[16];
238
239 for (int i = 0; i < 16; i += 4)
240 {
241 for (int j = 0; j < 4; j++)
242 {
243 tmp[i + j] =
244 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
245 }
246 }
247
248 for (int k = 0; k < 16; k++)
249 {
250 c[k] = tmp[k];
251 }
252}
253
254//----------------------------------------------------------------------------
255// Multiplies matrices a and b and stores the result in c.
256inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
257{
258 for (int i = 0; i < 16; i += 4)
259 {
260 for (int j = 0; j < 4; j++)
261 {
262 c[i + j] =
263 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
264 }
265 }
266}
267
268//----------------------------------------------------------------------------
269// Multiplies matrices a and b and stores the result in c.
271 const double a[16], const double b[16], float c[16])
272{
273 for (int i = 0; i < 4; i++)
274 {
275 for (int j = 0; j < 4; j++)
276 {
277 int it4 = i * 4;
278 c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
279 a[it4 + 3] * b[j + 12];
280 }
281 }
282}
283
284//----------------------------------------------------------------------------
286{
288}
289
290//----------------------------------------------------------------------------
291inline void vtkMatrix4x4::SetElement(int i, int j, double value)
292{
293 if (this->Element[i][j] != value)
294 {
295 this->Element[i][j] = value;
296 this->Modified();
297 }
298}
299
300//----------------------------------------------------------------------------
302{
303 double* M = *this->Element;
304 return M[0] == 1.0 && M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[4] == 0.0 && M[5] == 1.0 &&
305 M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
306 M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
307}
308
309#endif
a simple class to control print indentation
Definition: vtkIndent.h:43
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:45
static void Transpose(const double inElements[16], double outElements[16])
static double Determinant(const double elements[16])
void DeepCopy(const vtkMatrix4x4 *source)
Set the elements of the matrix to the same values as the elements of the given source matrix.
Definition: vtkMatrix4x4.h:62
static vtkMatrix4x4 * New()
Construct a 4x4 identity matrix.
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:87
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:209
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:170
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
Multiplies matrices a and b and stores the result in c.
Definition: vtkMatrix4x4.h:285
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:149
static void Adjoint(const double inElements[16], double outElements[16])
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:145
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:189
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:106
double Determinant()
Compute the determinant of the matrix and return it.
Definition: vtkMatrix4x4.h:198
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:291
static void DeepCopy(double destination[16], const vtkMatrix4x4 *source)
Set the elements of the given destination buffer to the same values as the elements of the given sour...
Definition: vtkMatrix4x4.h:72
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:96
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:214
void Transpose()
Definition: vtkMatrix4x4.h:138
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:48
static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16])
Multiplies matrices a and b and stores the result in c.
Definition: vtkMatrix4x4.h:270
static void DeepCopy(double destination[16], const double source[16])
Copies the given source buffer to the given destination buffer.
static void Invert(const double inElements[16], double outElements[16])
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:122
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:160
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:161
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:165
static void Identity(double elements[16])
static void MultiplyPoint(const double elements[16], const double in[4], double out[4])
static void Zero(double elements[16])
static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix4x4.h:133
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:219
~vtkMatrix4x4() override=default
static void MultiplyPoint(const double elements[16], const float in[4], float out[4])
bool IsIdentity()
Returns true if this matrix is equal to the identity matrix.
Definition: vtkMatrix4x4.h:301
abstract base class for most VTK objects
Definition: vtkObject.h:63
virtual void Modified()
Update the modification time for this object.
@ value
Definition: vtkX3D.h:226
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)