VTK  9.5.20250528
vtkMatrix4x4.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
23#ifndef vtkMatrix4x4_h
24#define vtkMatrix4x4_h
25
26#include "vtkCommonMathModule.h" // For export macro
27#include "vtkObject.h"
28#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
29
30VTK_ABI_NAMESPACE_BEGIN
31class VTKCOMMONMATH_EXPORT VTK_MARSHALAUTO vtkMatrix4x4 : public vtkObject
32{
33public:
35 double Element[4][4];
36
40 static vtkMatrix4x4* New();
41
42 vtkTypeMacro(vtkMatrix4x4, vtkObject);
43 void PrintSelf(ostream& os, vtkIndent indent) override;
44
50 {
51 vtkMatrix4x4::DeepCopy(*this->Element, source);
52 this->Modified();
53 }
54
59 static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
60 {
61 vtkMatrix4x4::DeepCopy(destination, *source->Element);
62 }
63
68 static void DeepCopy(double destination[16], const double source[16]);
69
74 void DeepCopy(const double elements[16])
75 {
76 vtkMatrix4x4::DeepCopy(*this->Element, elements);
77 this->Modified();
78 }
79
83 void Zero()
84 {
85 vtkMatrix4x4::Zero(*this->Element);
86 this->Modified();
87 }
88 static void Zero(double elements[16]);
89
93 void Identity()
94 {
95 vtkMatrix4x4::Identity(*this->Element);
96 this->Modified();
97 }
98 static void Identity(double elements[16]);
99
103 bool IsIdentity();
104
109 static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
110 {
112 out->Modified();
113 }
114 void Invert() { vtkMatrix4x4::Invert(this, this); }
115 static void Invert(const double inElements[16], double outElements[16]);
116
120 static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
121 {
123 out->Modified();
124 }
125 void Transpose() { vtkMatrix4x4::Transpose(this, this); }
126 static void Transpose(const double inElements[16], double outElements[16]);
127
129
132 static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
133 static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
135
142 static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
143
148 void MultiplyPoint(const float in[4], float out[4])
149 {
150 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
151 }
152 void MultiplyPoint(const double in[4], double out[4])
153 {
154 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
155 }
156
157 static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
158 static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
159
163 float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
164 double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
165 {
166 return this->MultiplyDoublePoint(in);
167 }
168 float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
169 {
170 this->MultiplyPoint(in, this->FloatPoint);
171 return this->FloatPoint;
172 }
173 double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
174 {
175 this->MultiplyPoint(in, this->DoublePoint);
176 return this->DoublePoint;
177 }
178
180
183 static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
184 static void Multiply4x4(const double a[16], const double b[16], double c[16]);
185 static void Multiply4x4(const double a[16], const double b[16], float c[16]);
186 static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
188
192 void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
193 {
195 }
196 static void Adjoint(const double inElements[16], double outElements[16]);
197
201 double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
202 static double Determinant(const double elements[16]);
203
207 void SetElement(int i, int j, double value);
208
212 double GetElement(int i, int j) const { return this->Element[i][j]; }
213
217 double* GetData() VTK_SIZEHINT(16) { return *this->Element; }
218
222 const double* GetData() const { return *this->Element; }
223
227 void SetData(const double data[16]) { vtkMatrix4x4::DeepCopy(data); }
228
229protected:
231 ~vtkMatrix4x4() override = default;
232
233 float FloatPoint[4];
234 double DoublePoint[4];
235
236private:
237 vtkMatrix4x4(const vtkMatrix4x4&) = delete;
238 void operator=(const vtkMatrix4x4&) = delete;
239};
240
241//----------------------------------------------------------------------------
242// Multiplies matrices a and b and stores the result in c.
243inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
244{
245 double tmp[16];
246
247 for (int i = 0; i < 16; i += 4)
248 {
249 for (int j = 0; j < 4; j++)
250 {
251 tmp[i + j] =
252 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
253 }
254 }
255
256 for (int k = 0; k < 16; k++)
257 {
258 c[k] = tmp[k];
259 }
260}
261
262//----------------------------------------------------------------------------
263// Multiplies matrices a and b and stores the result in c.
264inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
265{
266 for (int i = 0; i < 16; i += 4)
267 {
268 for (int j = 0; j < 4; j++)
269 {
270 c[i + j] =
271 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
272 }
273 }
274}
275
276//----------------------------------------------------------------------------
277// Multiplies matrices a and b and stores the result in c.
279 const double a[16], const double b[16], float c[16])
280{
281 for (int i = 0; i < 4; i++)
282 {
283 for (int j = 0; j < 4; j++)
284 {
285 int it4 = i * 4;
286 c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
287 a[it4 + 3] * b[j + 12];
288 }
289 }
290}
291
292//----------------------------------------------------------------------------
294{
296}
297
298//----------------------------------------------------------------------------
299inline void vtkMatrix4x4::SetElement(int i, int j, double value)
300{
301 if (this->Element[i][j] != value)
302 {
303 this->Element[i][j] = value;
304 this->Modified();
305 }
306}
307
308//----------------------------------------------------------------------------
310{
311 double* M = *this->Element;
312 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 &&
313 M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
314 M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
315}
316
317VTK_ABI_NAMESPACE_END
318#endif
a simple class to control print indentation
Definition vtkIndent.h:29
represent and manipulate 4x4 transformation matrices
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.
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 SetData(const double data[16])
Copies data into the matrix.
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.
abstract base class for most VTK objects
Definition vtkObject.h:53
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(...)
#define VTK_MARSHALAUTO