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) VTK_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 
100  static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
101  {vtkMatrix4x4::Invert(*in->Element, *out->Element); out->Modified(); }
102  void Invert()
103  { vtkMatrix4x4::Invert(this,this); }
104  static void Invert(const double inElements[16], double outElements[16]);
105 
109  static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
110  {vtkMatrix4x4::Transpose(*in->Element, *out->Element); out->Modified(); }
111  void Transpose()
112  { vtkMatrix4x4::Transpose(this,this); }
113  static void Transpose(const double inElements[16], double outElements[16]);
114 
119  void MultiplyPoint(const float in[4], float out[4])
120  {vtkMatrix4x4::MultiplyPoint(*this->Element, in, out); }
121  void MultiplyPoint(const double in[4], double out[4])
122  {vtkMatrix4x4::MultiplyPoint(*this->Element, in, out); }
123 
124  static void MultiplyPoint(const double elements[16],
125  const float in[4], float out[4]);
126  static void MultiplyPoint(const double elements[16],
127  const double in[4], double out[4]);
128 
133  float *MultiplyPoint(const float in[4])
134  {return this->MultiplyFloatPoint(in); }
135  float *MultiplyFloatPoint(const float in[4])
136  {this->MultiplyPoint(in,this->FloatPoint); return this->FloatPoint; }
137  double *MultiplyDoublePoint(const double in[4])
138  {this->MultiplyPoint(in,this->DoublePoint); return this->DoublePoint; }
139 
141 
144  static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b,
145  vtkMatrix4x4 *c);
146  static void Multiply4x4(const double a[16], const double b[16],
147  double c[16]);
149 
153  void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
154  {vtkMatrix4x4::Adjoint(*in->Element, *out->Element);}
155  static void Adjoint(const double inElements[16], double outElements[16]);
156 
160  double Determinant() {return vtkMatrix4x4::Determinant(*this->Element);}
161  static double Determinant(const double elements[16]);
162 
166  void SetElement(int i, int j, double value);
167 
171  double GetElement(int i, int j) const
172  {return this->Element[i][j];}
173 
175 
178  VTK_LEGACY(double *operator[](const unsigned int i));
179  VTK_LEGACY(const double *operator[](unsigned int i) const);
180  VTK_LEGACY(void Adjoint(vtkMatrix4x4 &in, vtkMatrix4x4 &out));
181  VTK_LEGACY(double Determinant(vtkMatrix4x4 &in));
182  VTK_LEGACY(double Determinant(vtkMatrix4x4 *));
183  VTK_LEGACY(void Invert(vtkMatrix4x4 &in, vtkMatrix4x4 &out));
184  VTK_LEGACY(void Transpose(vtkMatrix4x4 &in, vtkMatrix4x4 &out));
185  VTK_LEGACY(static void PointMultiply(const double [16],
186  const float [4], float [4]));
187  VTK_LEGACY(static void PointMultiply(const double [16],
188  const double [4], double [4]));
190 
191 protected:
192  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); };
193  ~vtkMatrix4x4() VTK_OVERRIDE {}
194 
195  float FloatPoint[4];
196  double DoublePoint[4];
197 
198 private:
199  vtkMatrix4x4(const vtkMatrix4x4&) VTK_DELETE_FUNCTION;
200  void operator= (const vtkMatrix4x4&) VTK_DELETE_FUNCTION;
201 };
202 
203 //----------------------------------------------------------------------------
204 // Multiplies matrices a and b and stores the result in c.
205 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16],
206  double c[16])
207 {
208  double tmp[16];
209 
210  for (int i = 0; i < 16; i += 4)
211  {
212  for (int j = 0; j < 4; j++)
213  {
214  tmp[i + j] = a[i + 0] * b[j + 0] +
215  a[i + 1] * b[j + 4] +
216  a[i + 2] * b[j + 8] +
217  a[i + 3] * b[j + 12];
218  }
219  }
220 
221  for (int k = 0; k < 16; k++)
222  {
223  c[k] = tmp[k];
224  }
225 }
226 
227 //----------------------------------------------------------------------------
229  const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
230 {
232 }
233 
234 //----------------------------------------------------------------------------
235 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
236 {
237  if (this->Element[i][j] != value)
238  {
239  this->Element[i][j] = value;
240  this->Modified();
241  }
242 }
243 
244 #endif
245 
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
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:153
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:135
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:171
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:235
~vtkMatrix4x4() override
Definition: vtkMatrix4x4.h:193
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:121
void Transpose()
Definition: vtkMatrix4x4.h:111
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:119
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:228
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:100
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:92
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:137
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:109
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:160
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, Python or Tcl.
Definition: vtkMatrix4x4.h:133
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...