VTK  9.3.0
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
32 #ifndef vtkMatrix4x4_h
33 #define vtkMatrix4x4_h
34 
35 #include "vtkCommonMathModule.h" // For export macro
36 #include "vtkObject.h"
37 
38 VTK_ABI_NAMESPACE_BEGIN
39 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
40 {
41 public:
43  double Element[4][4];
44 
48  static vtkMatrix4x4* New();
49 
50  vtkTypeMacro(vtkMatrix4x4, vtkObject);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
58  {
59  vtkMatrix4x4::DeepCopy(*this->Element, source);
60  this->Modified();
61  }
62 
67  static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
68  {
69  vtkMatrix4x4::DeepCopy(destination, *source->Element);
70  }
71 
76  static void DeepCopy(double destination[16], const double source[16]);
77 
82  void DeepCopy(const double elements[16])
83  {
84  vtkMatrix4x4::DeepCopy(*this->Element, elements);
85  this->Modified();
86  }
87 
91  void Zero()
92  {
93  vtkMatrix4x4::Zero(*this->Element);
94  this->Modified();
95  }
96  static void Zero(double elements[16]);
97 
101  void Identity()
102  {
103  vtkMatrix4x4::Identity(*this->Element);
104  this->Modified();
105  }
106  static void Identity(double elements[16]);
107 
111  bool IsIdentity();
112 
117  static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
118  {
119  vtkMatrix4x4::Invert(*in->Element, *out->Element);
120  out->Modified();
121  }
122  void Invert() { vtkMatrix4x4::Invert(this, this); }
123  static void Invert(const double inElements[16], double outElements[16]);
124 
128  static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
129  {
131  out->Modified();
132  }
133  void Transpose() { vtkMatrix4x4::Transpose(this, this); }
134  static void Transpose(const double inElements[16], double outElements[16]);
135 
137 
140  static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
141  static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
143 
150  static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
151 
156  void MultiplyPoint(const float in[4], float out[4])
157  {
158  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
159  }
160  void MultiplyPoint(const double in[4], double out[4])
161  {
162  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
163  }
164 
165  static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
166  static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
167 
171  float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
172  double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
173  {
174  return this->MultiplyDoublePoint(in);
175  }
176  float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
177  {
178  this->MultiplyPoint(in, this->FloatPoint);
179  return this->FloatPoint;
180  }
181  double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
182  {
183  this->MultiplyPoint(in, this->DoublePoint);
184  return this->DoublePoint;
185  }
186 
188 
191  static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
192  static void Multiply4x4(const double a[16], const double b[16], double c[16]);
193  static void Multiply4x4(const double a[16], const double b[16], float c[16]);
194  static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
196 
200  void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
201  {
203  }
204  static void Adjoint(const double inElements[16], double outElements[16]);
205 
209  double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
210  static double Determinant(const double elements[16]);
211 
215  void SetElement(int i, int j, double value);
216 
220  double GetElement(int i, int j) const { return this->Element[i][j]; }
221 
225  double* GetData() { return *this->Element; }
226 
230  const double* GetData() const { return *this->Element; }
231 
232 protected:
233  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }
234  ~vtkMatrix4x4() override = default;
235 
236  float FloatPoint[4];
237  double DoublePoint[4];
238 
239 private:
240  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
241  void operator=(const vtkMatrix4x4&) = delete;
242 };
243 
244 //----------------------------------------------------------------------------
245 // Multiplies matrices a and b and stores the result in c.
246 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
247 {
248  double tmp[16];
249 
250  for (int i = 0; i < 16; i += 4)
251  {
252  for (int j = 0; j < 4; j++)
253  {
254  tmp[i + j] =
255  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
256  }
257  }
258 
259  for (int k = 0; k < 16; k++)
260  {
261  c[k] = tmp[k];
262  }
263 }
264 
265 //----------------------------------------------------------------------------
266 // Multiplies matrices a and b and stores the result in c.
267 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
268 {
269  for (int i = 0; i < 16; i += 4)
270  {
271  for (int j = 0; j < 4; j++)
272  {
273  c[i + j] =
274  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
275  }
276  }
277 }
278 
279 //----------------------------------------------------------------------------
280 // Multiplies matrices a and b and stores the result in c.
282  const double a[16], const double b[16], float c[16])
283 {
284  for (int i = 0; i < 4; i++)
285  {
286  for (int j = 0; j < 4; j++)
287  {
288  int it4 = i * 4;
289  c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
290  a[it4 + 3] * b[j + 12];
291  }
292  }
293 }
294 
295 //----------------------------------------------------------------------------
297 {
299 }
300 
301 //----------------------------------------------------------------------------
302 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
303 {
304  if (this->Element[i][j] != value)
305  {
306  this->Element[i][j] = value;
307  this->Modified();
308  }
309 }
310 
311 //----------------------------------------------------------------------------
313 {
314  double* M = *this->Element;
315  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 &&
316  M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
317  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
318 }
319 
320 VTK_ABI_NAMESPACE_END
321 #endif
a simple class to control print indentation
Definition: vtkIndent.h:38
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
static vtkMatrix4x4 * New()
Construct a 4x4 identity matrix.
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:57
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:82
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:220
static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16])
Construct a matrix from a rotation.
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:296
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:160
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:225
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:156
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:200
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:101
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.
Definition: vtkMatrix4x4.h:209
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:171
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:302
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:67
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:91
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:230
void Transpose()
Definition: vtkMatrix4x4.h:133
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:43
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:172
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:281
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])
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:176
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:117
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...
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:128
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:181
~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:312
abstract base class for most VTK objects
Definition: vtkObject.h:61
virtual void Modified()
Update the modification time for this object.
@ value
Definition: vtkX3D.h:220
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)