VTK  9.2.20220706
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 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
151 {
152 public:
154  double Element[4][4];
155 
159  static vtkMatrix4x4* New();
160 
161  vtkTypeMacro(vtkMatrix4x4, vtkObject);
162  void PrintSelf(ostream& os, vtkIndent indent) override;
163 
169  {
170  vtkMatrix4x4::DeepCopy(*this->Element, source);
171  this->Modified();
172  }
173 
178  static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
179  {
180  vtkMatrix4x4::DeepCopy(destination, *source->Element);
181  }
182 
187  static void DeepCopy(double destination[16], const double source[16]);
188 
193  void DeepCopy(const double elements[16])
194  {
195  this->DeepCopy(*this->Element, elements);
196  this->Modified();
197  }
198 
202  void Zero()
203  {
204  vtkMatrix4x4::Zero(*this->Element);
205  this->Modified();
206  }
207  static void Zero(double elements[16]);
208 
212  void Identity()
213  {
214  vtkMatrix4x4::Identity(*this->Element);
215  this->Modified();
216  }
217  static void Identity(double elements[16]);
218 
222  bool IsIdentity();
223 
228  static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
229  {
230  vtkMatrix4x4::Invert(*in->Element, *out->Element);
231  out->Modified();
232  }
233  void Invert() { vtkMatrix4x4::Invert(this, this); }
234  static void Invert(const double inElements[16], double outElements[16]);
235 
239  static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
240  {
242  out->Modified();
243  }
244  void Transpose() { vtkMatrix4x4::Transpose(this, this); }
245  static void Transpose(const double inElements[16], double outElements[16]);
246 
248 
251  static void MatrixFromRotation(double angle, double x, double y, double z, vtkMatrix4x4* result);
252  static void MatrixFromRotation(double angle, double x, double y, double z, double matrix[16]);
254 
261  static void PoseToMatrix(double pos[3], double ori[4], vtkMatrix4x4* mat);
262 
267  void MultiplyPoint(const float in[4], float out[4])
268  {
269  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
270  }
271  void MultiplyPoint(const double in[4], double out[4])
272  {
273  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
274  }
275 
276  static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
277  static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
278 
282  float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
283  double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
284  {
285  return this->MultiplyDoublePoint(in);
286  }
287  float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
288  {
289  this->MultiplyPoint(in, this->FloatPoint);
290  return this->FloatPoint;
291  }
292  double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
293  {
294  this->MultiplyPoint(in, this->DoublePoint);
295  return this->DoublePoint;
296  }
297 
299 
302  static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
303  static void Multiply4x4(const double a[16], const double b[16], double c[16]);
304  static void Multiply4x4(const double a[16], const double b[16], float c[16]);
305  static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
307 
311  void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
312  {
314  }
315  static void Adjoint(const double inElements[16], double outElements[16]);
316 
320  double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
321  static double Determinant(const double elements[16]);
322 
326  void SetElement(int i, int j, double value);
327 
331  double GetElement(int i, int j) const { return this->Element[i][j]; }
332 
336  double* GetData() { return *this->Element; }
337 
341  const double* GetData() const { return *this->Element; }
342 
343 protected:
344  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }
345  ~vtkMatrix4x4() override = default;
346 
347  float FloatPoint[4];
348  double DoublePoint[4];
349 
350 private:
351  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
352  void operator=(const vtkMatrix4x4&) = delete;
353 };
354 
355 //----------------------------------------------------------------------------
356 // Multiplies matrices a and b and stores the result in c.
357 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
358 {
359  double tmp[16];
360 
361  for (int i = 0; i < 16; i += 4)
362  {
363  for (int j = 0; j < 4; j++)
364  {
365  tmp[i + j] =
366  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
367  }
368  }
369 
370  for (int k = 0; k < 16; k++)
371  {
372  c[k] = tmp[k];
373  }
374 }
375 
376 //----------------------------------------------------------------------------
377 // Multiplies matrices a and b and stores the result in c.
378 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
379 {
380  for (int i = 0; i < 16; i += 4)
381  {
382  for (int j = 0; j < 4; j++)
383  {
384  c[i + j] =
385  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
386  }
387  }
388 }
389 
390 //----------------------------------------------------------------------------
391 // Multiplies matrices a and b and stores the result in c.
393  const double a[16], const double b[16], float c[16])
394 {
395  for (int i = 0; i < 4; i++)
396  {
397  for (int j = 0; j < 4; j++)
398  {
399  int it4 = i * 4;
400  c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
401  a[it4 + 3] * b[j + 12];
402  }
403  }
404 }
405 
406 //----------------------------------------------------------------------------
408 {
410 }
411 
412 //----------------------------------------------------------------------------
413 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
414 {
415  if (this->Element[i][j] != value)
416  {
417  this->Element[i][j] = value;
418  this->Modified();
419  }
420 }
421 
422 //----------------------------------------------------------------------------
424 {
425  double* M = *this->Element;
426  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 &&
427  M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
428  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
429 }
430 
431 #endif
a simple class to control print indentation
Definition: vtkIndent.h:119
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
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:168
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:193
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:331
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:407
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:271
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:336
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:267
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:311
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:212
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:320
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:282
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:413
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:178
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:202
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:341
void Transpose()
Definition: vtkMatrix4x4.h:244
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:154
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:283
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:392
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:287
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:228
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:239
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:292
~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:423
abstract base class for most VTK objects
Definition: vtkObject.h:82
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(...)