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 =========================================================================*/
32 #ifndef vtkMatrix4x4_h
33 #define vtkMatrix4x4_h
34 
35 #include "vtkCommonMathModule.h" // For export macro
36 #include "vtkObject.h"
37 
39 {
40  // Some of the methods in here have a corresponding static (class)
41  // method taking a pointer to 16 doubles that constitutes a user
42  // supplied matrix. This allows C++ clients to allocate double arrays
43  // on the stack and manipulate them using vtkMatrix4x4 methods.
44  // This is an alternative to allowing vtkMatrix4x4 instances to be
45  // created on the stack (which is frowned upon) or doing lots of
46  // temporary heap allocation within vtkTransform and vtkActor methods,
47  // which is inefficient.
48 
49 public:
50  double Element[4][4];
51 
53  static vtkMatrix4x4 *New();
54 
55  vtkTypeMacro(vtkMatrix4x4,vtkObject);
56  void PrintSelf(ostream& os, vtkIndent indent);
57 
59 
62  {vtkMatrix4x4::DeepCopy(*this->Element,source); this->Modified(); }
63 //BTX
64  static void DeepCopy(double Elements[16], const vtkMatrix4x4 *source)
65  {vtkMatrix4x4::DeepCopy(Elements,*source->Element); }
66  static void DeepCopy(double Elements[16], const double newElements[16]);
67 //ETX
69 
71 
72  void DeepCopy(const double Elements[16])
73  { this->DeepCopy(*this->Element,Elements); this->Modified(); }
75 
77 
78  void Zero()
79  { vtkMatrix4x4::Zero(*this->Element); this->Modified(); }
80 //BTX
81  static void Zero(double Elements[16]);
82 //ETX
84 
86 
87  void Identity()
88  { vtkMatrix4x4::Identity(*this->Element); this->Modified();}
89 //BTX
90  static void Identity(double Elements[16]);
91 //ETX
93 
95 
97  static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
98  {vtkMatrix4x4::Invert(*in->Element,*out->Element); out->Modified(); }
99  void Invert()
100  { vtkMatrix4x4::Invert(this,this); }
101 //BTX
102  static void Invert(const double inElements[16], double outElements[16]);
103 //ETX
105 
106 
108 
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 //BTX
114  static void Transpose(const double inElements[16], double outElements[16]);
115 //ETX
117 
119 
121  void MultiplyPoint(const float in[4], float out[4])
122  {vtkMatrix4x4::MultiplyPoint(*this->Element,in,out); }
123  void MultiplyPoint(const double in[4], double out[4])
124  {vtkMatrix4x4::MultiplyPoint(*this->Element,in,out); }
126 
127 //BTX
128  static void MultiplyPoint(const double Elements[16],
129  const float in[4], float out[4]);
130  static void MultiplyPoint(const double Elements[16],
131  const double in[4], double out[4]);
132 //ETX
133 
135 
137  float *MultiplyPoint(const float in[4])
138  {return this->MultiplyFloatPoint(in); }
139  float *MultiplyFloatPoint(const float in[4])
140  {this->MultiplyPoint(in,this->FloatPoint); return this->FloatPoint; }
141  double *MultiplyDoublePoint(const double in[4])
142  {this->MultiplyPoint(in,this->DoublePoint); return this->DoublePoint; }
144 
146 
147  static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b,
148  vtkMatrix4x4 *c);
149 //BTX
150  static void Multiply4x4(const double a[16], const double b[16],
151  double c[16]);
152 //ETX
154 
156 
157  void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
158  {vtkMatrix4x4::Adjoint(*in->Element,*out->Element);}
159 //BTX
160  static void Adjoint(const double inElements[16], double outElements[16]);
161 //ETX
163 
165 
166  double Determinant() {return vtkMatrix4x4::Determinant(*this->Element);}
167 //BTX
168  static double Determinant(const double Elements[16]);
169 //ETX
171 
173  void SetElement(int i, int j, double value);
174 
176 
177  double GetElement(int i, int j) const
178  {return this->Element[i][j];}
180 
181 //BTX
182  double *operator[](const unsigned int i)
183  {return &(this->Element[i][0]);}
184  const double *operator[](unsigned int i) const
185  { return &(this->Element[i][0]); }
187  {this->Adjoint(&in,&out);}
189  {return this->Determinant(&in);}
191  {return vtkMatrix4x4::Determinant(*in->Element);}
193  {this->Invert(&in,&out);}
195  {this->Transpose(&in,&out);}
196  static void PointMultiply(const double Elements[16],
197  const float in[4], float out[4]);
198  static void PointMultiply(const double Elements[16],
199  const double in[4], double out[4]);
200 //ETX
201 
202 protected:
203  vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); };
205 
206  float FloatPoint[4];
207  double DoublePoint[4];
208 private:
209  // Useful for viewing a double[16] as a double[4][4]
210  typedef double (*SqMatPtr)[4];
211  typedef const double (*ConstSqMatPtr)[4];
212 
213  vtkMatrix4x4(const vtkMatrix4x4&); // Not implemented
214  void operator= (const vtkMatrix4x4&); // Not implemented
215 };
216 
217 //----------------------------------------------------------------------------
218 // Multiplies matrices a and b and stores the result in c.
219 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16],
220  double c[16])
221 {
222  ConstSqMatPtr aMat = reinterpret_cast<ConstSqMatPtr>(a);
223  ConstSqMatPtr bMat = reinterpret_cast<ConstSqMatPtr>(b);
224 
225  double tmp[16];
226  SqMatPtr cMat = reinterpret_cast<SqMatPtr>(tmp);
227 
228  for (int i = 0; i < 4; i++)
229  {
230  for (int k = 0; k < 4; k++)
231  {
232  cMat[i][k] = aMat[i][0] * bMat[0][k] +
233  aMat[i][1] * bMat[1][k] +
234  aMat[i][2] * bMat[2][k] +
235  aMat[i][3] * bMat[3][k];
236  }
237  }
238 
239  // Copy to final dest
240  memcpy(c, tmp, 16 * sizeof(double));
241 }
242 
243 //----------------------------------------------------------------------------
245  const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
246 {
248 }
249 
250 //----------------------------------------------------------------------------
251 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
252 {
253  if (this->Element[i][j] != value)
254  {
255  this->Element[i][j] = value;
256  this->Modified();
257  }
258 }
259 
260 #endif
261 
void Transpose(vtkMatrix4x4 &in, vtkMatrix4x4 &out)
Definition: vtkMatrix4x4.h:194
abstract base class for most VTK objects
Definition: vtkObject.h:61
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:38
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Definition: vtkMatrix4x4.h:157
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:139
double GetElement(int i, int j) const
Definition: vtkMatrix4x4.h:177
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
void SetElement(int i, int j, double value)
Definition: vtkMatrix4x4.h:251
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:123
void Transpose()
Definition: vtkMatrix4x4.h:111
void Invert()
Definition: vtkMatrix4x4.h:99
void MultiplyPoint(const float in[4], float out[4])
Definition: vtkMatrix4x4.h:121
void DeepCopy(const vtkMatrix4x4 *source)
Definition: vtkMatrix4x4.h:61
virtual void PrintSelf(ostream &os, vtkIndent indent)
static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
Definition: vtkMatrix4x4.h:244
a simple class to control print indentation
Definition: vtkIndent.h:38
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Definition: vtkMatrix4x4.h:97
void Identity()
Definition: vtkMatrix4x4.h:87
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:141
const double * operator[](unsigned int i) const
Definition: vtkMatrix4x4.h:184
virtual void Modified()
static void DeepCopy(double Elements[16], const vtkMatrix4x4 *source)
Definition: vtkMatrix4x4.h:64
static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Definition: vtkMatrix4x4.h:109
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
double Determinant()
Definition: vtkMatrix4x4.h:166
double Determinant(vtkMatrix4x4 *in)
Definition: vtkMatrix4x4.h:190
double Element[4][4]
Definition: vtkMatrix4x4.h:50
void Invert(vtkMatrix4x4 &in, vtkMatrix4x4 &out)
Definition: vtkMatrix4x4.h:192
float * MultiplyPoint(const float in[4])
Definition: vtkMatrix4x4.h:137
double Determinant(vtkMatrix4x4 &in)
Definition: vtkMatrix4x4.h:188
void DeepCopy(const double Elements[16])
Definition: vtkMatrix4x4.h:72
static vtkObject * New()
void Adjoint(vtkMatrix4x4 &in, vtkMatrix4x4 &out)
Definition: vtkMatrix4x4.h:186
double * operator[](const unsigned int i)
Definition: vtkMatrix4x4.h:182
#define VTKCOMMONMATH_EXPORT