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 "vtkObject.h"
33 
35 {
36  // Some of the methods in here have a corresponding static (class)
37  // method taking a pointer to 9 doubles that constitutes a user
38  // supplied matrix. This allows C++ clients to allocate double arrays
39  // on the stack and manipulate them using vtkMatrix3x3 methods.
40  // This is an alternative to allowing vtkMatrix3x3 instances to be
41  // created on the stack (which is frowned upon) or doing lots of
42  // temporary heap allocation within vtkTransform2D methods,
43  // which is inefficient.
44 
45 public:
47  static vtkMatrix3x3 *New();
48 
49  vtkTypeMacro(vtkMatrix3x3,vtkObject);
50  void PrintSelf(ostream& os, vtkIndent indent);
51 
53 
55  void DeepCopy(vtkMatrix3x3 *source)
56  {vtkMatrix3x3::DeepCopy(*this->Element,source); this->Modified(); }
57 //BTX
58  static void DeepCopy(double Elements[9], vtkMatrix3x3 *source)
59  {vtkMatrix3x3::DeepCopy(Elements,*source->Element); }
60  static void DeepCopy(double Elements[9], const double newElements[9]);
61 //ETX
63 
65 
66  void DeepCopy(const double Elements[9])
67  { this->DeepCopy(*this->Element,Elements); this->Modified(); }
69 
71 
72  void Zero()
73  { vtkMatrix3x3::Zero(*this->Element); this->Modified(); }
74 //BTX
75  static void Zero(double Elements[9]);
76 //ETX
78 
80 
81  void Identity()
82  { vtkMatrix3x3::Identity(*this->Element); this->Modified();}
83 //BTX
84  static void Identity(double Elements[9]);
85 //ETX
87 
89 
91  static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
92  {vtkMatrix3x3::Invert(*in->Element,*out->Element); out->Modified(); }
93  void Invert()
94  { vtkMatrix3x3::Invert(this,this); }
95 //BTX
96  static void Invert(const double inElements[9], double outElements[9]);
97 //ETX
99 
100 
102 
103  static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
104  {vtkMatrix3x3::Transpose(*in->Element,*out->Element); out->Modified(); }
105  void Transpose()
106  { vtkMatrix3x3::Transpose(this,this); }
107 //BTX
108  static void Transpose(const double inElements[9], double outElements[9]);
109 //ETX
111 
113 
115  void MultiplyPoint(const float in[3], float out[3])
116  {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
117  void MultiplyPoint(const double in[3], double out[3])
118  {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
120 
121 //BTX
122  static void MultiplyPoint(const double Elements[9],
123  const float in[3], float out[3]);
124  static void MultiplyPoint(const double Elements[9],
125  const double in[3], double out[3]);
126 //ETX
127 
129 
132 //BTX
133  static void Multiply3x3(const double a[9], const double b[9],
134  double c[9]);
135 //ETX
137 
139 
141  {vtkMatrix3x3::Adjoint(*in->Element,*out->Element);}
142 //BTX
143  static void Adjoint(const double inElements[9], double outElements[9]);
144 //ETX
146 
148 
149  double Determinant() {return vtkMatrix3x3::Determinant(*this->Element);}
150 //BTX
151  static double Determinant(const double Elements[9]);
152 //ETX
154 
156  void SetElement(int i, int j, double value);
157 
159 
160  double GetElement(int i, int j) const
161  {return this->Element[i][j];}
163 
164 //BTX
165  double *operator[](const unsigned int i)
166  {return &(this->Element[i][0]);}
167  const double *operator[](unsigned int i) const
168  { return &(this->Element[i][0]); }
169  bool operator==(const vtkMatrix3x3&);
170  bool operator!=(const vtkMatrix3x3&);
172  {this->Adjoint(&in,&out);}
174  {return this->Determinant(&in);}
176  {return vtkMatrix3x3::Determinant(*in->Element);}
178  {this->Invert(&in,&out);}
180  {this->Transpose(&in,&out);}
181  static void PointMultiply(const double Elements[9],
182  const float in[3], float out[3]);
183  static void PointMultiply(const double Elements[9],
184  const double in[3], double out[3]);
185 //ETX
186 
187  // Descption:
188  // Returns true if this matrix is equal to the identity matrix.
189  bool IsIdentity();
190 
192  double * GetData() { return *this->Element; }
193 
194 //BTX
195 protected:
196  vtkMatrix3x3();
197  ~vtkMatrix3x3();
198 
199  double Element[3][3]; // The elements of the 3x3 matrix
200 
201 private:
202  vtkMatrix3x3(const vtkMatrix3x3&); // Not implemented
203  void operator=(const vtkMatrix3x3&); // Not implemented
204 //ETX
205 };
206 
207 inline void vtkMatrix3x3::SetElement(int i, int j, double value)
208 {
209  if (this->Element[i][j] != value)
210  {
211  this->Element[i][j] = value;
212  this->Modified();
213  }
214 }
215 
217 {
218  double *M = *this->Element;
219  if (M[0] == 1.0 && M[4] == 1.0 && M[8] == 1.0 &&
220  M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[5] == 0.0 &&
221  M[6] == 0.0 && M[7] == 0.0)
222  {
223  return true;
224  }
225  else
226  {
227  return false;
228  }
229 }
230 
231 inline bool vtkMatrix3x3::operator==(const vtkMatrix3x3 &other)
232 {
233  for (int i = 0; i < 3; ++i)
234  {
235  for (int j = 0; j < 3; ++j)
236  {
237  if (Element[i][j] != other.Element[i][j])
238  {
239  return false;
240  }
241  }
242  }
243  return true;
244 }
245 
246 inline bool vtkMatrix3x3::operator!=(const vtkMatrix3x3 &other)
247 {
248  for (int i = 0; i < 3; ++i)
249  {
250  for (int j = 0; j < 3; ++j)
251  {
252  if (Element[i][j] != other.Element[i][j])
253  {
254  return true;
255  }
256  }
257  }
258  return false;
259 }
260 
261 #endif
void DeepCopy(vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:55
void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Definition: vtkMatrix3x3.h:140
bool operator!=(const vtkMatrix3x3 &)
Definition: vtkMatrix3x3.h:246
abstract base class for most VTK objects
Definition: vtkObject.h:60
void DeepCopy(const double Elements[9])
Definition: vtkMatrix3x3.h:66
double Determinant()
Definition: vtkMatrix3x3.h:149
void Transpose(vtkMatrix3x3 &in, vtkMatrix3x3 &out)
Definition: vtkMatrix3x3.h:179
void Invert(vtkMatrix3x3 &in, vtkMatrix3x3 &out)
Definition: vtkMatrix3x3.h:177
const double * operator[](unsigned int i) const
Definition: vtkMatrix3x3.h:167
static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Definition: vtkMatrix3x3.h:103
static void DeepCopy(double Elements[9], vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:58
static void Multiply3x3(vtkMatrix3x3 *a, vtkMatrix3x3 *b, vtkMatrix3x3 *c)
Definition: vtkMatrix3x3.h:130
double GetElement(int i, int j) const
Definition: vtkMatrix3x3.h:160
void Adjoint(vtkMatrix3x3 &in, vtkMatrix3x3 &out)
Definition: vtkMatrix3x3.h:171
VTK_COMMON_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
double Determinant(vtkMatrix3x3 *in)
Definition: vtkMatrix3x3.h:175
void Transpose()
Definition: vtkMatrix3x3.h:105
#define VTK_COMMON_EXPORT
virtual void Modified()
void SetElement(int i, int j, double value)
Definition: vtkMatrix3x3.h:207
double * operator[](const unsigned int i)
Definition: vtkMatrix3x3.h:165
double * GetData()
Definition: vtkMatrix3x3.h:192
bool operator==(const vtkMatrix3x3 &)
Definition: vtkMatrix3x3.h:231
double Determinant(vtkMatrix3x3 &in)
Definition: vtkMatrix3x3.h:173
double Element[3][3]
Definition: vtkMatrix3x3.h:199
void Identity()
Definition: vtkMatrix3x3.h:81
bool IsIdentity()
Definition: vtkMatrix3x3.h:216
static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Definition: vtkMatrix3x3.h:91
VTK_COMMON_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
void Invert()
Definition: vtkMatrix3x3.h:93
void MultiplyPoint(const float in[3], float out[3])
Definition: vtkMatrix3x3.h:115
static vtkObject * New()
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:34
void MultiplyPoint(const double in[3], double out[3])
Definition: vtkMatrix3x3.h:117