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 
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]) VTK_SIZEHINT(4)
134  {return this->MultiplyFloatPoint(in); }
135  float *MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
136  {this->MultiplyPoint(in,this->FloatPoint); return this->FloatPoint; }
137  double *MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(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 
177  double *GetData() { return *this->Element; }
178 
179 protected:
180  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); };
181  ~vtkMatrix4x4() override {}
182 
183  float FloatPoint[4];
184  double DoublePoint[4];
185 
186 private:
187  vtkMatrix4x4(const vtkMatrix4x4&) = delete;
188  void operator= (const vtkMatrix4x4&) = delete;
189 };
190 
191 //----------------------------------------------------------------------------
192 // Multiplies matrices a and b and stores the result in c.
193 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16],
194  double c[16])
195 {
196  double tmp[16];
197 
198  for (int i = 0; i < 16; i += 4)
199  {
200  for (int j = 0; j < 4; j++)
201  {
202  tmp[i + j] = a[i + 0] * b[j + 0] +
203  a[i + 1] * b[j + 4] +
204  a[i + 2] * b[j + 8] +
205  a[i + 3] * b[j + 12];
206  }
207  }
208 
209  for (int k = 0; k < 16; k++)
210  {
211  c[k] = tmp[k];
212  }
213 }
214 
215 //----------------------------------------------------------------------------
217  const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
218 {
220 }
221 
222 //----------------------------------------------------------------------------
223 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
224 {
225  if (this->Element[i][j] != value)
226  {
227  this->Element[i][j] = value;
228  this->Modified();
229  }
230 }
231 
232 #endif
233 
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 SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:223
~vtkMatrix4x4() override
Definition: vtkMatrix4x4.h:181
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:216
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:177
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
#define VTK_SIZEHINT(...)
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 or Python.
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...