VTK  9.3.1
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 
29 VTK_ABI_NAMESPACE_BEGIN
30 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
31 {
32 public:
34  double Element[4][4];
35 
39  static vtkMatrix4x4* New();
40 
41  vtkTypeMacro(vtkMatrix4x4, vtkObject);
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
49  {
50  vtkMatrix4x4::DeepCopy(*this->Element, source);
51  this->Modified();
52  }
53 
58  static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
59  {
60  vtkMatrix4x4::DeepCopy(destination, *source->Element);
61  }
62 
67  static void DeepCopy(double destination[16], const double source[16]);
68 
73  void DeepCopy(const double elements[16])
74  {
75  vtkMatrix4x4::DeepCopy(*this->Element, elements);
76  this->Modified();
77  }
78 
82  void Zero()
83  {
84  vtkMatrix4x4::Zero(*this->Element);
85  this->Modified();
86  }
87  static void Zero(double elements[16]);
88 
92  void Identity()
93  {
94  vtkMatrix4x4::Identity(*this->Element);
95  this->Modified();
96  }
97  static void Identity(double elements[16]);
98 
102  bool IsIdentity();
103 
108  static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
109  {
110  vtkMatrix4x4::Invert(*in->Element, *out->Element);
111  out->Modified();
112  }
113  void Invert() { vtkMatrix4x4::Invert(this, this); }
114  static void Invert(const double inElements[16], double outElements[16]);
115 
119  static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
120  {
122  out->Modified();
123  }
124  void Transpose() { vtkMatrix4x4::Transpose(this, this); }
125  static void Transpose(const double inElements[16], double outElements[16]);
126 
128 
131  static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
132  static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
134 
141  static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
142 
147  void MultiplyPoint(const float in[4], float out[4])
148  {
149  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
150  }
151  void MultiplyPoint(const double in[4], double out[4])
152  {
153  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
154  }
155 
156  static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
157  static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
158 
162  float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
163  double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
164  {
165  return this->MultiplyDoublePoint(in);
166  }
167  float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
168  {
169  this->MultiplyPoint(in, this->FloatPoint);
170  return this->FloatPoint;
171  }
172  double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
173  {
174  this->MultiplyPoint(in, this->DoublePoint);
175  return this->DoublePoint;
176  }
177 
179 
182  static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
183  static void Multiply4x4(const double a[16], const double b[16], double c[16]);
184  static void Multiply4x4(const double a[16], const double b[16], float c[16]);
185  static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
187 
191  void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
192  {
194  }
195  static void Adjoint(const double inElements[16], double outElements[16]);
196 
200  double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
201  static double Determinant(const double elements[16]);
202 
206  void SetElement(int i, int j, double value);
207 
211  double GetElement(int i, int j) const { return this->Element[i][j]; }
212 
216  double* GetData() { return *this->Element; }
217 
221  const double* GetData() const { return *this->Element; }
222 
223 protected:
224  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }
225  ~vtkMatrix4x4() override = default;
226 
227  float FloatPoint[4];
228  double DoublePoint[4];
229 
230 private:
231  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
232  void operator=(const vtkMatrix4x4&) = delete;
233 };
234 
235 //----------------------------------------------------------------------------
236 // Multiplies matrices a and b and stores the result in c.
237 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
238 {
239  double tmp[16];
240 
241  for (int i = 0; i < 16; i += 4)
242  {
243  for (int j = 0; j < 4; j++)
244  {
245  tmp[i + j] =
246  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
247  }
248  }
249 
250  for (int k = 0; k < 16; k++)
251  {
252  c[k] = tmp[k];
253  }
254 }
255 
256 //----------------------------------------------------------------------------
257 // Multiplies matrices a and b and stores the result in c.
258 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
259 {
260  for (int i = 0; i < 16; i += 4)
261  {
262  for (int j = 0; j < 4; j++)
263  {
264  c[i + j] =
265  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
266  }
267  }
268 }
269 
270 //----------------------------------------------------------------------------
271 // Multiplies matrices a and b and stores the result in c.
273  const double a[16], const double b[16], float c[16])
274 {
275  for (int i = 0; i < 4; i++)
276  {
277  for (int j = 0; j < 4; j++)
278  {
279  int it4 = i * 4;
280  c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
281  a[it4 + 3] * b[j + 12];
282  }
283  }
284 }
285 
286 //----------------------------------------------------------------------------
288 {
290 }
291 
292 //----------------------------------------------------------------------------
293 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
294 {
295  if (this->Element[i][j] != value)
296  {
297  this->Element[i][j] = value;
298  this->Modified();
299  }
300 }
301 
302 //----------------------------------------------------------------------------
304 {
305  double* M = *this->Element;
306  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 &&
307  M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
308  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
309 }
310 
311 VTK_ABI_NAMESPACE_END
312 #endif
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:58
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:163
abstract base class for most VTK objects
Definition: vtkObject.h:51
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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:272
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:191
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:167
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:211
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:293
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:151
void Transpose()
Definition: vtkMatrix4x4.h:124
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:147
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:48
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:287
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:216
a simple class to control print indentation
Definition: vtkIndent.h:28
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press, 1990).
Definition: vtkMatrix4x4.h:108
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:92
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:172
virtual void Modified()
Update the modification time for this object.
static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix4x4.h:119
#define VTK_SIZEHINT(...)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
bool IsIdentity()
Returns true if this matrix is equal to the identity matrix.
Definition: vtkMatrix4x4.h:303
double Determinant()
Compute the determinant of the matrix and return it.
Definition: vtkMatrix4x4.h:200
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:34
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:162
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:73
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:82
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:221