VTK  9.0.20200813
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 =========================================================================*/
29 #ifndef vtkMatrix4x4_h
30 #define vtkMatrix4x4_h
31 
32 #include "vtkCommonMathModule.h" // For export macro
33 #include "vtkObject.h"
34 
35 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
36 {
37 public:
39  double Element[4][4];
40 
44  static vtkMatrix4x4* New();
45 
46  vtkTypeMacro(vtkMatrix4x4, vtkObject);
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
54  {
55  vtkMatrix4x4::DeepCopy(*this->Element, source);
56  this->Modified();
57  }
58 
63  static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
64  {
65  vtkMatrix4x4::DeepCopy(destination, *source->Element);
66  }
67 
72  static void DeepCopy(double destination[16], const double source[16]);
73 
78  void DeepCopy(const double elements[16])
79  {
80  this->DeepCopy(*this->Element, elements);
81  this->Modified();
82  }
83 
87  void Zero()
88  {
89  vtkMatrix4x4::Zero(*this->Element);
90  this->Modified();
91  }
92  static void Zero(double elements[16]);
93 
97  void Identity()
98  {
99  vtkMatrix4x4::Identity(*this->Element);
100  this->Modified();
101  }
102  static void Identity(double elements[16]);
103 
107  bool IsIdentity();
108 
113  static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
114  {
115  vtkMatrix4x4::Invert(*in->Element, *out->Element);
116  out->Modified();
117  }
118  void Invert() { vtkMatrix4x4::Invert(this, this); }
119  static void Invert(const double inElements[16], double outElements[16]);
120 
124  static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
125  {
127  out->Modified();
128  }
129  void Transpose() { vtkMatrix4x4::Transpose(this, this); }
130  static void Transpose(const double inElements[16], double outElements[16]);
131 
136  void MultiplyPoint(const float in[4], float out[4])
137  {
138  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
139  }
140  void MultiplyPoint(const double in[4], double out[4])
141  {
142  vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
143  }
144 
145  static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
146  static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
147 
151  float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
152  double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
153  {
154  return this->MultiplyDoublePoint(in);
155  }
156  float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
157  {
158  this->MultiplyPoint(in, this->FloatPoint);
159  return this->FloatPoint;
160  }
161  double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
162  {
163  this->MultiplyPoint(in, this->DoublePoint);
164  return this->DoublePoint;
165  }
166 
168 
171  static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
172  static void Multiply4x4(const double a[16], const double b[16], double c[16]);
173  static void Multiply4x4(const double a[16], const double b[16], float c[16]);
174  static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
176 
180  void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
181  {
183  }
184  static void Adjoint(const double inElements[16], double outElements[16]);
185 
189  double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
190  static double Determinant(const double elements[16]);
191 
195  void SetElement(int i, int j, double value);
196 
200  double GetElement(int i, int j) const { return this->Element[i][j]; }
201 
205  double* GetData() { return *this->Element; }
206 
210  const double* GetData() const { return *this->Element; }
211 
212 protected:
213  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }
214  ~vtkMatrix4x4() override = default;
215 
216  float FloatPoint[4];
217  double DoublePoint[4];
218 
219 private:
220  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
221  void operator=(const vtkMatrix4x4&) = delete;
222 };
223 
224 //----------------------------------------------------------------------------
225 // Multiplies matrices a and b and stores the result in c.
226 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
227 {
228  double tmp[16];
229 
230  for (int i = 0; i < 16; i += 4)
231  {
232  for (int j = 0; j < 4; j++)
233  {
234  tmp[i + j] =
235  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
236  }
237  }
238 
239  for (int k = 0; k < 16; k++)
240  {
241  c[k] = tmp[k];
242  }
243 }
244 
245 //----------------------------------------------------------------------------
246 // Multiplies matrices a and b and stores the result in c.
247 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
248 {
249  for (int i = 0; i < 16; i += 4)
250  {
251  for (int j = 0; j < 4; j++)
252  {
253  c[i + j] =
254  a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
255  }
256  }
257 }
258 
259 //----------------------------------------------------------------------------
260 // Multiplies matrices a and b and stores the result in c.
262  const double a[16], const double b[16], float c[16])
263 {
264  for (int i = 0; i < 4; i++)
265  {
266  for (int j = 0; j < 4; j++)
267  {
268  int it4 = i * 4;
269  c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
270  a[it4 + 3] * b[j + 12];
271  }
272  }
273 }
274 
275 //----------------------------------------------------------------------------
277 {
279 }
280 
281 //----------------------------------------------------------------------------
282 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
283 {
284  if (this->Element[i][j] != value)
285  {
286  this->Element[i][j] = value;
287  this->Modified();
288  }
289 }
290 
291 //----------------------------------------------------------------------------
293 {
294  double* M = *this->Element;
295  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 &&
296  M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
297  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
298 }
299 
300 #endif
vtkMatrix4x4::SetElement
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:282
vtkMatrix4x4::DeepCopy
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:53
vtkMatrix4x4::Transpose
void Transpose()
Definition: vtkMatrix4x4.h:129
vtkX3D::value
Definition: vtkX3D.h:226
vtkMatrix4x4::Element
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:39
vtkMatrix4x4::DeepCopy
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:63
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkMatrix4x4::MultiplyPoint
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:151
vtkMatrix4x4::GetElement
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:200
vtkMatrix4x4::MultiplyPoint
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:140
vtkObject::Modified
virtual void Modified()
Update the modification time for this object.
vtkMatrix4x4::MultiplyAndTranspose4x4
static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16])
Definition: vtkMatrix4x4.h:261
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkMatrix4x4::Determinant
double Determinant()
Compute the determinant of the matrix and return it.
Definition: vtkMatrix4x4.h:189
vtkMatrix4x4::GetData
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:210
vtkMatrix4x4::IsIdentity
bool IsIdentity()
Returns true if this matrix is equal to the identity matrix.
Definition: vtkMatrix4x4.h:292
vtkMatrix4x4::MultiplyPoint
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:152
vtkMatrix4x4::GetData
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:205
vtkMatrix4x4::vtkMatrix4x4
vtkMatrix4x4()
Definition: vtkMatrix4x4.h:213
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkMatrix4x4::Adjoint
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:180
vtkMatrix4x4::MultiplyPoint
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:136
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkMatrix4x4::MultiplyFloatPoint
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:156
vtkObject.h
vtkMatrix4x4::Invert
void Invert()
Definition: vtkMatrix4x4.h:118
vtkMatrix4x4::Multiply4x4
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:276
vtkMatrix4x4::DeepCopy
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:78
vtkMatrix4x4::Invert
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:113
vtkMatrix4x4::MultiplyDoublePoint
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:161
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:959
vtkMatrix4x4::Identity
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:97
vtkMatrix4x4::Zero
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:87
vtkMatrix4x4::Transpose
static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix4x4.h:124