VTK  9.2.6
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 =========================================================================*/
44 #ifndef vtkMatrix4x4_h
45 #define vtkMatrix4x4_h
46 
47 #include "vtkCommonMathModule.h" // For export macro
48 #include "vtkObject.h"
49 
50 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
51 {
52 public:
54  double Element[4][4];
55 
59  static vtkMatrix4x4* New();
60 
61  vtkTypeMacro(vtkMatrix4x4, vtkObject);
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
69  {
70  vtkMatrix4x4::DeepCopy(*this->Element, source);
71  this->Modified();
72  }
73 
78  static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
79  {
80  vtkMatrix4x4::DeepCopy(destination, *source->Element);
81  }
82 
87  static void DeepCopy(double destination[16], const double source[16]);
88 
93  void DeepCopy(const double elements[16])
94  {
95  this->DeepCopy(*this->Element, elements);
96  this->Modified();
97  }
98 
102  void Zero()
103  {
104  vtkMatrix4x4::Zero(*this->Element);
105  this->Modified();
106  }
107  static void Zero(double elements[16]);
108 
112  void Identity()
113  {
114  vtkMatrix4x4::Identity(*this->Element);
115  this->Modified();
116  }
117  static void Identity(double elements[16]);
118 
122  bool IsIdentity();
123 
128  static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
129  {
130  vtkMatrix4x4::Invert(*in->Element, *out->Element);
131  out->Modified();
132  }
133  void Invert() { vtkMatrix4x4::Invert(this, this); }
134  static void Invert(const double inElements[16], double outElements[16]);
135 
139  static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
140  {
142  out->Modified();
143  }
144  void Transpose() { vtkMatrix4x4::Transpose(this, this); }
145  static void Transpose(const double inElements[16], double outElements[16]);
146 
148 
151  static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
152  static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
154 
161  static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
162 
167  void MultiplyPoint(const float in[4], float out[4])
168  {
169  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
170  }
171  void MultiplyPoint(const double in[4], double out[4])
172  {
173  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
174  }
175 
176  static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
177  static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
178 
182  float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
183  double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
184  {
185  return this->MultiplyDoublePoint(in);
186  }
187  float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
188  {
189  this->MultiplyPoint(in, this->FloatPoint);
190  return this->FloatPoint;
191  }
192  double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
193  {
194  this->MultiplyPoint(in, this->DoublePoint);
195  return this->DoublePoint;
196  }
197 
199 
202  static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
203  static void Multiply4x4(const double a[16], const double b[16], double c[16]);
204  static void Multiply4x4(const double a[16], const double b[16], float c[16]);
205  static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
207 
211  void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
212  {
214  }
215  static void Adjoint(const double inElements[16], double outElements[16]);
216 
220  double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
221  static double Determinant(const double elements[16]);
222 
226  void SetElement(int i, int j, double value);
227 
231  double GetElement(int i, int j) const { return this->Element[i][j]; }
232 
236  double* GetData() { return *this->Element; }
237 
241  const double* GetData() const { return *this->Element; }
242 
243 protected:
244  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }
245  ~vtkMatrix4x4() override = default;
246 
247  float FloatPoint[4];
248  double DoublePoint[4];
249 
250 private:
251  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
252  void operator=(const vtkMatrix4x4&) = delete;
253 };
254 
255 //----------------------------------------------------------------------------
256 // Multiplies matrices a and b and stores the result in c.
257 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
258 {
259  double tmp[16];
260 
261  for (int i = 0; i < 16; i += 4)
262  {
263  for (int j = 0; j < 4; j++)
264  {
265  tmp[i + j] =
266  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
267  }
268  }
269 
270  for (int k = 0; k < 16; k++)
271  {
272  c[k] = tmp[k];
273  }
274 }
275 
276 //----------------------------------------------------------------------------
277 // Multiplies matrices a and b and stores the result in c.
278 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
279 {
280  for (int i = 0; i < 16; i += 4)
281  {
282  for (int j = 0; j < 4; j++)
283  {
284  c[i + j] =
285  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
286  }
287  }
288 }
289 
290 //----------------------------------------------------------------------------
291 // Multiplies matrices a and b and stores the result in c.
293  const double a[16], const double b[16], float c[16])
294 {
295  for (int i = 0; i < 4; i++)
296  {
297  for (int j = 0; j < 4; j++)
298  {
299  int it4 = i * 4;
300  c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
301  a[it4 + 3] * b[j + 12];
302  }
303  }
304 }
305 
306 //----------------------------------------------------------------------------
308 {
310 }
311 
312 //----------------------------------------------------------------------------
313 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
314 {
315  if (this->Element[i][j] != value)
316  {
317  this->Element[i][j] = value;
318  this->Modified();
319  }
320 }
321 
322 //----------------------------------------------------------------------------
324 {
325  double* M = *this->Element;
326  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 &&
327  M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
328  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
329 }
330 
331 #endif
a simple class to control print indentation
Definition: vtkIndent.h:49
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:51
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:68
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:93
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:231
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:307
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:171
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:236
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:167
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:211
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:112
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:220
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:182
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:313
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:78
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:102
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:241
void Transpose()
Definition: vtkMatrix4x4.h:144
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:54
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:183
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:292
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:187
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:128
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:139
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:192
~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:323
abstract base class for most VTK objects
Definition: vtkObject.h:72
virtual void Modified()
Update the modification time for this object.
@ value
Definition: vtkX3D.h:226
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)