VTK  9.3.20240327
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
132 #ifndef vtkMatrix4x4_h
133 #define vtkMatrix4x4_h
134 
135 #include "vtkCommonMathModule.h" // For export macro
136 #include "vtkObject.h"
137 
138 VTK_ABI_NAMESPACE_BEGIN
139 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
140 {
141 public:
143  double Element[4][4];
144 
148  static vtkMatrix4x4* New();
149 
150  vtkTypeMacro(vtkMatrix4x4, vtkObject);
151  void PrintSelf(ostream& os, vtkIndent indent) override;
152 
158  {
159  vtkMatrix4x4::DeepCopy(*this->Element, source);
160  this->Modified();
161  }
162 
167  static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
168  {
169  vtkMatrix4x4::DeepCopy(destination, *source->Element);
170  }
171 
176  static void DeepCopy(double destination[16], const double source[16]);
177 
182  void DeepCopy(const double elements[16])
183  {
184  vtkMatrix4x4::DeepCopy(*this->Element, elements);
185  this->Modified();
186  }
187 
191  void Zero()
192  {
193  vtkMatrix4x4::Zero(*this->Element);
194  this->Modified();
195  }
196  static void Zero(double elements[16]);
197 
201  void Identity()
202  {
203  vtkMatrix4x4::Identity(*this->Element);
204  this->Modified();
205  }
206  static void Identity(double elements[16]);
207 
211  bool IsIdentity();
212 
217  static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
218  {
219  vtkMatrix4x4::Invert(*in->Element, *out->Element);
220  out->Modified();
221  }
222  void Invert() { vtkMatrix4x4::Invert(this, this); }
223  static void Invert(const double inElements[16], double outElements[16]);
224 
228  static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
229  {
231  out->Modified();
232  }
233  void Transpose() { vtkMatrix4x4::Transpose(this, this); }
234  static void Transpose(const double inElements[16], double outElements[16]);
235 
237 
240  static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
241  static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
243 
250  static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
251 
256  void MultiplyPoint(const float in[4], float out[4])
257  {
258  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
259  }
260  void MultiplyPoint(const double in[4], double out[4])
261  {
262  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
263  }
264 
265  static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
266  static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
267 
271  float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
272  double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
273  {
274  return this->MultiplyDoublePoint(in);
275  }
276  float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
277  {
278  this->MultiplyPoint(in, this->FloatPoint);
279  return this->FloatPoint;
280  }
281  double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
282  {
283  this->MultiplyPoint(in, this->DoublePoint);
284  return this->DoublePoint;
285  }
286 
288 
291  static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
292  static void Multiply4x4(const double a[16], const double b[16], double c[16]);
293  static void Multiply4x4(const double a[16], const double b[16], float c[16]);
294  static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
296 
300  void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
301  {
303  }
304  static void Adjoint(const double inElements[16], double outElements[16]);
305 
309  double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
310  static double Determinant(const double elements[16]);
311 
315  void SetElement(int i, int j, double value);
316 
320  double GetElement(int i, int j) const { return this->Element[i][j]; }
321 
325  double* GetData() { return *this->Element; }
326 
330  const double* GetData() const { return *this->Element; }
331 
332 protected:
333  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }
334  ~vtkMatrix4x4() override = default;
335 
336  float FloatPoint[4];
337  double DoublePoint[4];
338 
339 private:
340  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
341  void operator=(const vtkMatrix4x4&) = delete;
342 };
343 
344 //----------------------------------------------------------------------------
345 // Multiplies matrices a and b and stores the result in c.
346 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
347 {
348  double tmp[16];
349 
350  for (int i = 0; i < 16; i += 4)
351  {
352  for (int j = 0; j < 4; j++)
353  {
354  tmp[i + j] =
355  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
356  }
357  }
358 
359  for (int k = 0; k < 16; k++)
360  {
361  c[k] = tmp[k];
362  }
363 }
364 
365 //----------------------------------------------------------------------------
366 // Multiplies matrices a and b and stores the result in c.
367 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
368 {
369  for (int i = 0; i < 16; i += 4)
370  {
371  for (int j = 0; j < 4; j++)
372  {
373  c[i + j] =
374  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
375  }
376  }
377 }
378 
379 //----------------------------------------------------------------------------
380 // Multiplies matrices a and b and stores the result in c.
382  const double a[16], const double b[16], float c[16])
383 {
384  for (int i = 0; i < 4; i++)
385  {
386  for (int j = 0; j < 4; j++)
387  {
388  int it4 = i * 4;
389  c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
390  a[it4 + 3] * b[j + 12];
391  }
392  }
393 }
394 
395 //----------------------------------------------------------------------------
397 {
399 }
400 
401 //----------------------------------------------------------------------------
402 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
403 {
404  if (this->Element[i][j] != value)
405  {
406  this->Element[i][j] = value;
407  this->Modified();
408  }
409 }
410 
411 //----------------------------------------------------------------------------
413 {
414  double* M = *this->Element;
415  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 &&
416  M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
417  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
418 }
419 
420 VTK_ABI_NAMESPACE_END
421 #endif
a simple class to control print indentation
Definition: vtkIndent.h:108
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:140
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:157
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:182
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:320
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:396
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:260
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:325
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:256
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:300
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:201
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:309
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:271
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:402
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:167
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:191
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:330
void Transpose()
Definition: vtkMatrix4x4.h:233
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:143
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:272
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:381
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:276
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:217
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:228
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:281
~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:412
abstract base class for most VTK objects
Definition: vtkObject.h:161
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(...)