VTK
vtkMatrix3x3.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMatrix3x3.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 vtkMatrix3x3_h
30 #define vtkMatrix3x3_h
31 
32 #include "vtkCommonMathModule.h" // For export macro
33 #include "vtkObject.h"
34 
36 {
37  // Some of the methods in here have a corresponding static (class)
38  // method taking a pointer to 9 doubles that constitutes a user
39  // supplied matrix. This allows C++ clients to allocate double arrays
40  // on the stack and manipulate them using vtkMatrix3x3 methods.
41  // This is an alternative to allowing vtkMatrix3x3 instances to be
42  // created on the stack (which is frowned upon) or doing lots of
43  // temporary heap allocation within vtkTransform2D methods,
44  // which is inefficient.
45 
46 public:
48  static vtkMatrix3x3 *New();
49 
50  vtkTypeMacro(vtkMatrix3x3,vtkObject);
51  void PrintSelf(ostream& os, vtkIndent indent);
52 
54 
57  {vtkMatrix3x3::DeepCopy(*this->Element,source); this->Modified(); }
58 //BTX
59  static void DeepCopy(double Elements[9], vtkMatrix3x3 *source)
60  {vtkMatrix3x3::DeepCopy(Elements,*source->Element); }
61  static void DeepCopy(double Elements[9], const double newElements[9]);
62 //ETX
64 
66 
67  void DeepCopy(const double Elements[9])
68  { this->DeepCopy(*this->Element,Elements); this->Modified(); }
70 
72 
73  void Zero()
74  { vtkMatrix3x3::Zero(*this->Element); this->Modified(); }
75 //BTX
76  static void Zero(double Elements[9]);
77 //ETX
79 
81 
82  void Identity()
83  { vtkMatrix3x3::Identity(*this->Element); this->Modified();}
84 //BTX
85  static void Identity(double Elements[9]);
86 //ETX
88 
90 
92  static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
93  {vtkMatrix3x3::Invert(*in->Element,*out->Element); out->Modified(); }
94  void Invert()
95  { vtkMatrix3x3::Invert(this,this); }
96 //BTX
97  static void Invert(const double inElements[9], double outElements[9]);
98 //ETX
100 
101 
103 
104  static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
105  {vtkMatrix3x3::Transpose(*in->Element,*out->Element); out->Modified(); }
106  void Transpose()
107  { vtkMatrix3x3::Transpose(this,this); }
108 //BTX
109  static void Transpose(const double inElements[9], double outElements[9]);
110 //ETX
112 
114 
116  void MultiplyPoint(const float in[3], float out[3])
117  {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
118  void MultiplyPoint(const double in[3], double out[3])
119  {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
121 
122 //BTX
123  static void MultiplyPoint(const double Elements[9],
124  const float in[3], float out[3]);
125  static void MultiplyPoint(const double Elements[9],
126  const double in[3], double out[3]);
127 //ETX
128 
130 
133 //BTX
134  static void Multiply3x3(const double a[9], const double b[9],
135  double c[9]);
136 //ETX
138 
140 
142  {vtkMatrix3x3::Adjoint(*in->Element,*out->Element);}
143 //BTX
144  static void Adjoint(const double inElements[9], double outElements[9]);
145 //ETX
147 
149 
150  double Determinant() {return vtkMatrix3x3::Determinant(*this->Element);}
151 //BTX
152  static double Determinant(const double Elements[9]);
153 //ETX
155 
157  void SetElement(int i, int j, double value);
158 
160 
161  double GetElement(int i, int j) const
162  {return this->Element[i][j];}
164 
165 //BTX
166  double *operator[](const unsigned int i)
167  {return &(this->Element[i][0]);}
168  const double *operator[](unsigned int i) const
169  { return &(this->Element[i][0]); }
170  bool operator==(const vtkMatrix3x3&);
171  bool operator!=(const vtkMatrix3x3&);
173  {this->Adjoint(&in,&out);}
175  {return this->Determinant(&in);}
177  {return vtkMatrix3x3::Determinant(*in->Element);}
179  {this->Invert(&in,&out);}
181  {this->Transpose(&in,&out);}
182  static void PointMultiply(const double Elements[9],
183  const float in[3], float out[3]);
184  static void PointMultiply(const double Elements[9],
185  const double in[3], double out[3]);
186 //ETX
187 
188  // Descption:
189  // Returns true if this matrix is equal to the identity matrix.
190  bool IsIdentity();
191 
193  double * GetData() { return *this->Element; }
194 
195 //BTX
196 protected:
197  vtkMatrix3x3();
198  ~vtkMatrix3x3();
199 
200  double Element[3][3]; // The elements of the 3x3 matrix
201 
202 private:
203  vtkMatrix3x3(const vtkMatrix3x3&); // Not implemented
204  void operator=(const vtkMatrix3x3&); // Not implemented
205 //ETX
206 };
207 
208 inline void vtkMatrix3x3::SetElement(int i, int j, double value)
209 {
210  if (this->Element[i][j] != value)
211  {
212  this->Element[i][j] = value;
213  this->Modified();
214  }
215 }
216 
218 {
219  double *M = *this->Element;
220  if (M[0] == 1.0 && M[4] == 1.0 && M[8] == 1.0 &&
221  M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[5] == 0.0 &&
222  M[6] == 0.0 && M[7] == 0.0)
223  {
224  return true;
225  }
226  else
227  {
228  return false;
229  }
230 }
231 
232 inline bool vtkMatrix3x3::operator==(const vtkMatrix3x3 &other)
233 {
234  for (int i = 0; i < 3; ++i)
235  {
236  for (int j = 0; j < 3; ++j)
237  {
238  if (Element[i][j] != other.Element[i][j])
239  {
240  return false;
241  }
242  }
243  }
244  return true;
245 }
246 
247 inline bool vtkMatrix3x3::operator!=(const vtkMatrix3x3 &other)
248 {
249  for (int i = 0; i < 3; ++i)
250  {
251  for (int j = 0; j < 3; ++j)
252  {
253  if (Element[i][j] != other.Element[i][j])
254  {
255  return true;
256  }
257  }
258  }
259  return false;
260 }
261 
262 #endif
void DeepCopy(vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:56
void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Definition: vtkMatrix3x3.h:141
bool operator!=(const vtkMatrix3x3 &)
Definition: vtkMatrix3x3.h:247
abstract base class for most VTK objects
Definition: vtkObject.h:61
void DeepCopy(const double Elements[9])
Definition: vtkMatrix3x3.h:67
double Determinant()
Definition: vtkMatrix3x3.h:150
void Transpose(vtkMatrix3x3 &in, vtkMatrix3x3 &out)
Definition: vtkMatrix3x3.h:180
void Invert(vtkMatrix3x3 &in, vtkMatrix3x3 &out)
Definition: vtkMatrix3x3.h:178
const double * operator[](unsigned int i) const
Definition: vtkMatrix3x3.h:168
static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Definition: vtkMatrix3x3.h:104
static void DeepCopy(double Elements[9], vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:59
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
static void Multiply3x3(vtkMatrix3x3 *a, vtkMatrix3x3 *b, vtkMatrix3x3 *c)
Definition: vtkMatrix3x3.h:131
double GetElement(int i, int j) const
Definition: vtkMatrix3x3.h:161
void Adjoint(vtkMatrix3x3 &in, vtkMatrix3x3 &out)
Definition: vtkMatrix3x3.h:172
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
double Determinant(vtkMatrix3x3 *in)
Definition: vtkMatrix3x3.h:176
void Transpose()
Definition: vtkMatrix3x3.h:106
virtual void Modified()
void SetElement(int i, int j, double value)
Definition: vtkMatrix3x3.h:208
double * operator[](const unsigned int i)
Definition: vtkMatrix3x3.h:166
double * GetData()
Definition: vtkMatrix3x3.h:193
bool operator==(const vtkMatrix3x3 &)
Definition: vtkMatrix3x3.h:232
double Determinant(vtkMatrix3x3 &in)
Definition: vtkMatrix3x3.h:174
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
double Element[3][3]
Definition: vtkMatrix3x3.h:200
void Identity()
Definition: vtkMatrix3x3.h:82
#define M(row, col)
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
bool IsIdentity()
Definition: vtkMatrix3x3.h:217
static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Definition: vtkMatrix3x3.h:92
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
void Invert()
Definition: vtkMatrix3x3.h:94
void MultiplyPoint(const float in[3], float out[3])
Definition: vtkMatrix3x3.h:116
static vtkObject * New()
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:35
void MultiplyPoint(const double in[3], double out[3])
Definition: vtkMatrix3x3.h:118
#define VTKCOMMONMATH_EXPORT