VTK  9.2.20221001
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 =========================================================================*/
144 #ifndef vtkMatrix4x4_h
145 #define vtkMatrix4x4_h
146 
147 #include "vtkCommonMathModule.h" // For export macro
148 #include "vtkObject.h"
149 
150 VTK_ABI_NAMESPACE_BEGIN
151 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
152 {
153 public:
155  double Element[4][4];
156 
160  static vtkMatrix4x4* New();
161 
162  vtkTypeMacro(vtkMatrix4x4, vtkObject);
163  void PrintSelf(ostream& os, vtkIndent indent) override;
164 
170  {
171  vtkMatrix4x4::DeepCopy(*this->Element, source);
172  this->Modified();
173  }
174 
179  static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
180  {
181  vtkMatrix4x4::DeepCopy(destination, *source->Element);
182  }
183 
188  static void DeepCopy(double destination[16], const double source[16]);
189 
194  void DeepCopy(const double elements[16])
195  {
196  this->DeepCopy(*this->Element, elements);
197  this->Modified();
198  }
199 
203  void Zero()
204  {
205  vtkMatrix4x4::Zero(*this->Element);
206  this->Modified();
207  }
208  static void Zero(double elements[16]);
209 
213  void Identity()
214  {
215  vtkMatrix4x4::Identity(*this->Element);
216  this->Modified();
217  }
218  static void Identity(double elements[16]);
219 
223  bool IsIdentity();
224 
229  static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
230  {
231  vtkMatrix4x4::Invert(*in->Element, *out->Element);
232  out->Modified();
233  }
234  void Invert() { vtkMatrix4x4::Invert(this, this); }
235  static void Invert(const double inElements[16], double outElements[16]);
236 
240  static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
241  {
243  out->Modified();
244  }
245  void Transpose() { vtkMatrix4x4::Transpose(this, this); }
246  static void Transpose(const double inElements[16], double outElements[16]);
247 
249 
252  static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
253  static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
255 
262  static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
263 
268  void MultiplyPoint(const float in[4], float out[4])
269  {
270  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
271  }
272  void MultiplyPoint(const double in[4], double out[4])
273  {
274  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
275  }
276 
277  static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
278  static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
279 
283  float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
284  double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
285  {
286  return this->MultiplyDoublePoint(in);
287  }
288  float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
289  {
290  this->MultiplyPoint(in, this->FloatPoint);
291  return this->FloatPoint;
292  }
293  double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
294  {
295  this->MultiplyPoint(in, this->DoublePoint);
296  return this->DoublePoint;
297  }
298 
300 
303  static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
304  static void Multiply4x4(const double a[16], const double b[16], double c[16]);
305  static void Multiply4x4(const double a[16], const double b[16], float c[16]);
306  static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
308 
312  void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
313  {
315  }
316  static void Adjoint(const double inElements[16], double outElements[16]);
317 
321  double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
322  static double Determinant(const double elements[16]);
323 
327  void SetElement(int i, int j, double value);
328 
332  double GetElement(int i, int j) const { return this->Element[i][j]; }
333 
337  double* GetData() { return *this->Element; }
338 
342  const double* GetData() const { return *this->Element; }
343 
344 protected:
345  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }
346  ~vtkMatrix4x4() override = default;
347 
348  float FloatPoint[4];
349  double DoublePoint[4];
350 
351 private:
352  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
353  void operator=(const vtkMatrix4x4&) = delete;
354 };
355 
356 //----------------------------------------------------------------------------
357 // Multiplies matrices a and b and stores the result in c.
358 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
359 {
360  double tmp[16];
361 
362  for (int i = 0; i < 16; i += 4)
363  {
364  for (int j = 0; j < 4; j++)
365  {
366  tmp[i + j] =
367  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
368  }
369  }
370 
371  for (int k = 0; k < 16; k++)
372  {
373  c[k] = tmp[k];
374  }
375 }
376 
377 //----------------------------------------------------------------------------
378 // Multiplies matrices a and b and stores the result in c.
379 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
380 {
381  for (int i = 0; i < 16; i += 4)
382  {
383  for (int j = 0; j < 4; j++)
384  {
385  c[i + j] =
386  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
387  }
388  }
389 }
390 
391 //----------------------------------------------------------------------------
392 // Multiplies matrices a and b and stores the result in c.
394  const double a[16], const double b[16], float c[16])
395 {
396  for (int i = 0; i < 4; i++)
397  {
398  for (int j = 0; j < 4; j++)
399  {
400  int it4 = i * 4;
401  c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
402  a[it4 + 3] * b[j + 12];
403  }
404  }
405 }
406 
407 //----------------------------------------------------------------------------
409 {
411 }
412 
413 //----------------------------------------------------------------------------
414 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
415 {
416  if (this->Element[i][j] != value)
417  {
418  this->Element[i][j] = value;
419  this->Modified();
420  }
421 }
422 
423 //----------------------------------------------------------------------------
425 {
426  double* M = *this->Element;
427  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 &&
428  M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
429  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
430 }
431 
432 VTK_ABI_NAMESPACE_END
433 #endif
a simple class to control print indentation
Definition: vtkIndent.h:120
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:152
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:169
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:194
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:332
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:408
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:272
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:337
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:268
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:312
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:213
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:321
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:283
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:414
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:179
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:203
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:342
void Transpose()
Definition: vtkMatrix4x4.h:245
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:155
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:284
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:393
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:288
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:229
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:240
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:293
~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:424
abstract base class for most VTK objects
Definition: vtkObject.h:83
virtual void Modified()
Update the modification time for this object.
@ value
Definition: vtkX3D.h:232
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)