VTK
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 =========================================================================*/
35 #ifndef vtkMatrix4x4_h
36 #define vtkMatrix4x4_h
37 
38 #include "vtkCommonMathModule.h" // For export macro
39 #include "vtkObject.h"
40 
41 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
42 {
43 public:
45  double Element[4][4];
46 
50  static vtkMatrix4x4 *New();
51 
52  vtkTypeMacro(vtkMatrix4x4,vtkObject);
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
60  {vtkMatrix4x4::DeepCopy(*this->Element, source); this->Modified(); }
61 
66  static void DeepCopy(double destination[16], const vtkMatrix4x4 *source)
67  {vtkMatrix4x4::DeepCopy(destination, *source->Element); }
68 
73  static void DeepCopy(double destination[16], const double source[16]);
74 
79  void DeepCopy(const double elements[16])
80  { this->DeepCopy(*this->Element, elements); this->Modified(); }
81 
85  void Zero()
86  { vtkMatrix4x4::Zero(*this->Element); this->Modified(); }
87  static void Zero(double elements[16]);
88 
92  void Identity()
93  { vtkMatrix4x4::Identity(*this->Element); this->Modified();}
94  static void Identity(double elements[16]);
95 
99  bool IsIdentity();
100 
105  static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
106  {vtkMatrix4x4::Invert(*in->Element, *out->Element); out->Modified(); }
107  void Invert()
108  { vtkMatrix4x4::Invert(this,this); }
109  static void Invert(const double inElements[16], double outElements[16]);
110 
114  static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
115  {vtkMatrix4x4::Transpose(*in->Element, *out->Element); out->Modified(); }
116  void Transpose()
117  { vtkMatrix4x4::Transpose(this,this); }
118  static void Transpose(const double inElements[16], double outElements[16]);
119 
124  void MultiplyPoint(const float in[4], float out[4])
125  {vtkMatrix4x4::MultiplyPoint(*this->Element, in, out); }
126  void MultiplyPoint(const double in[4], double out[4])
127  {vtkMatrix4x4::MultiplyPoint(*this->Element, in, out); }
128 
129  static void MultiplyPoint(const double elements[16],
130  const float in[4], float out[4]);
131  static void MultiplyPoint(const double elements[16],
132  const double in[4], double out[4]);
133 
137  float *MultiplyPoint(const float in[4]) VTK_SIZEHINT(4)
138  {return this->MultiplyFloatPoint(in); }
139  double *MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
140  {return this->MultiplyDoublePoint(in); }
141  float *MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
142  {this->MultiplyPoint(in,this->FloatPoint); return this->FloatPoint; }
143  double *MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
144  {this->MultiplyPoint(in,this->DoublePoint); return this->DoublePoint; }
145 
147 
150  static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b,
151  vtkMatrix4x4 *c);
152  static void Multiply4x4(const double a[16], const double b[16],
153  double c[16]);
155 
159  void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
160  {vtkMatrix4x4::Adjoint(*in->Element, *out->Element);}
161  static void Adjoint(const double inElements[16], double outElements[16]);
162 
166  double Determinant() {return vtkMatrix4x4::Determinant(*this->Element);}
167  static double Determinant(const double elements[16]);
168 
172  void SetElement(int i, int j, double value);
173 
177  double GetElement(int i, int j) const
178  {return this->Element[i][j];}
179 
183  double *GetData() { return *this->Element; }
184 
188  const double *GetData() const { return *this->Element; }
189 
190 protected:
191  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); };
192  ~vtkMatrix4x4() override {}
193 
194  float FloatPoint[4];
195  double DoublePoint[4];
196 
197 private:
198  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
199  void operator= (const vtkMatrix4x4&) = delete;
200 };
201 
202 //----------------------------------------------------------------------------
203 // Multiplies matrices a and b and stores the result in c.
204 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16],
205  double c[16])
206 {
207  double tmp[16];
208 
209  for (int i = 0; i < 16; i += 4)
210  {
211  for (int j = 0; j < 4; j++)
212  {
213  tmp[i + j] = a[i + 0] * b[j + 0] +
214  a[i + 1] * b[j + 4] +
215  a[i + 2] * b[j + 8] +
216  a[i + 3] * b[j + 12];
217  }
218  }
219 
220  for (int k = 0; k < 16; k++)
221  {
222  c[k] = tmp[k];
223  }
224 }
225 
226 //----------------------------------------------------------------------------
228  const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
229 {
231 }
232 
233 //----------------------------------------------------------------------------
234 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
235 {
236  if (this->Element[i][j] != value)
237  {
238  this->Element[i][j] = value;
239  this->Modified();
240  }
241 }
242 
243 //----------------------------------------------------------------------------
245 {
246  double *M = *this->Element;
247  return
248  M[0] == 1.0 && M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 &&
249  M[4] == 0.0 && M[5] == 1.0 && M[6] == 0.0 && M[7] == 0.0 &&
250  M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
251  M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
252 }
253 
254 #endif
255 
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:66
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:139
abstract base class for most VTK objects
Definition: vtkObject.h:59
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:159
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:141
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:177
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:234
~vtkMatrix4x4() override
Definition: vtkMatrix4x4.h:192
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:126
void Transpose()
Definition: vtkMatrix4x4.h:116
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:124
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:59
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:227
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:183
a simple class to control print indentation
Definition: vtkIndent.h:39
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press, 1990).
Definition: vtkMatrix4x4.h:105
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:92
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:143
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:114
#define VTK_SIZEHINT(...)
bool IsIdentity()
Returns true if this matrix is equal to the identity matrix.
Definition: vtkMatrix4x4.h:244
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
double Determinant()
Compute the determinant of the matrix and return it.
Definition: vtkMatrix4x4.h:166
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:45
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:137
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:79
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:85
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:188