VTK  9.2.6
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=========================================================================*/
34
35#ifndef vtkMatrix4x4_h
36#define vtkMatrix4x4_h
37
38#include "vtkCommonMathModule.h" // For export macro
39#include "vtkObject.h"
40
41class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
42{
43public:
45 double Element[4][4];
46
50 static vtkMatrix4x4* New();
51
52 vtkTypeMacro(vtkMatrix4x4, vtkObject);
53 void PrintSelf(ostream& os, vtkIndent indent) override;
54
60 {
61 vtkMatrix4x4::DeepCopy(*this->Element, source);
62 this->Modified();
63 }
64
69 static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
70 {
71 vtkMatrix4x4::DeepCopy(destination, *source->Element);
72 }
73
78 static void DeepCopy(double destination[16], const double source[16]);
79
84 void DeepCopy(const double elements[16])
85 {
86 this->DeepCopy(*this->Element, elements);
87 this->Modified();
88 }
89
93 void Zero()
94 {
95 vtkMatrix4x4::Zero(*this->Element);
96 this->Modified();
97 }
98 static void Zero(double elements[16]);
99
103 void Identity()
104 {
105 vtkMatrix4x4::Identity(*this->Element);
106 this->Modified();
107 }
108 static void Identity(double elements[16]);
109
113 bool IsIdentity();
114
119 static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
120 {
122 out->Modified();
123 }
124 void Invert() { vtkMatrix4x4::Invert(this, this); }
125 static void Invert(const double inElements[16], double outElements[16]);
126
130 static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
131 {
133 out->Modified();
134 }
135 void Transpose() { vtkMatrix4x4::Transpose(this, this); }
136 static void Transpose(const double inElements[16], double outElements[16]);
137
139
142 static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
143 static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
145
152 static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
153
158 void MultiplyPoint(const float in[4], float out[4])
159 {
160 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
161 }
162 void MultiplyPoint(const double in[4], double out[4])
163 {
164 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
165 }
166
167 static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
168 static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
169
173 float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
174 double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
175 {
176 return this->MultiplyDoublePoint(in);
177 }
178 float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
179 {
180 this->MultiplyPoint(in, this->FloatPoint);
181 return this->FloatPoint;
182 }
183 double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
184 {
185 this->MultiplyPoint(in, this->DoublePoint);
186 return this->DoublePoint;
187 }
188
190
193 static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
194 static void Multiply4x4(const double a[16], const double b[16], double c[16]);
195 static void Multiply4x4(const double a[16], const double b[16], float c[16]);
196 static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
198
202 void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
203 {
205 }
206 static void Adjoint(const double inElements[16], double outElements[16]);
207
211 double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
212 static double Determinant(const double elements[16]);
213
217 void SetElement(int i, int j, double value);
218
222 double GetElement(int i, int j) const { return this->Element[i][j]; }
223
227 double* GetData() { return *this->Element; }
228
232 const double* GetData() const { return *this->Element; }
233
234protected:
236 ~vtkMatrix4x4() override = default;
237
238 float FloatPoint[4];
239 double DoublePoint[4];
240
241private:
242 vtkMatrix4x4(const vtkMatrix4x4&) = delete;
243 void operator=(const vtkMatrix4x4&) = delete;
244};
245
246//----------------------------------------------------------------------------
247// Multiplies matrices a and b and stores the result in c.
248inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
249{
250 double tmp[16];
251
252 for (int i = 0; i < 16; i += 4)
253 {
254 for (int j = 0; j < 4; j++)
255 {
256 tmp[i + j] =
257 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
258 }
259 }
260
261 for (int k = 0; k < 16; k++)
262 {
263 c[k] = tmp[k];
264 }
265}
266
267//----------------------------------------------------------------------------
268// Multiplies matrices a and b and stores the result in c.
269inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
270{
271 for (int i = 0; i < 16; i += 4)
272 {
273 for (int j = 0; j < 4; j++)
274 {
275 c[i + j] =
276 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
277 }
278 }
279}
280
281//----------------------------------------------------------------------------
282// Multiplies matrices a and b and stores the result in c.
284 const double a[16], const double b[16], float c[16])
285{
286 for (int i = 0; i < 4; i++)
287 {
288 for (int j = 0; j < 4; j++)
289 {
290 int it4 = i * 4;
291 c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
292 a[it4 + 3] * b[j + 12];
293 }
294 }
295}
296
297//----------------------------------------------------------------------------
299{
301}
302
303//----------------------------------------------------------------------------
304inline void vtkMatrix4x4::SetElement(int i, int j, double value)
305{
306 if (this->Element[i][j] != value)
307 {
308 this->Element[i][j] = value;
309 this->Modified();
310 }
311}
312
313//----------------------------------------------------------------------------
315{
316 double* M = *this->Element;
317 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 &&
318 M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
319 M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
320}
321
322#endif
a simple class to control print indentation
Definition vtkIndent.h:40
represent and manipulate 4x4 transformation matrices
double DoublePoint[4]
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.
static vtkMatrix4x4 * New()
Construct a 4x4 identity matrix.
float FloatPoint[4]
void DeepCopy(const double elements[16])
Non-static member function.
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16])
Construct a matrix from a rotation.
double * MultiplyDoublePoint(const double in[4])
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.
void MultiplyPoint(const double in[4], double out[4])
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.
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
void Identity()
Set equal to Identity matrix.
static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4 *result)
Construct a matrix from a rotation.
double Determinant()
Compute the determinant of the matrix and return it.
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
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...
void Zero()
Set all of the elements to zero.
double * GetData()
Returns the raw double array holding the matrix.
double Element[4][4]
The internal data is public for historical reasons. Do not use!
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.
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,...
static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4 *mat)
Given an orientation and position this function will fill in a matrix representing the transformation...
float * MultiplyPoint(const float in[4])
For use in Java or Python.
double * MultiplyPoint(const double in[4])
float * MultiplyFloatPoint(const float in[4])
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.
const double * GetData() const
Returns the raw double array holding the matrix.
~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.
virtual void Modified()
Update the modification time for this object.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)