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 =========================================================================*/
27 #ifndef vtkMatrix3x3_h
28 #define vtkMatrix3x3_h
29 
30 #include "vtkCommonMathModule.h" // For export macro
31 #include "vtkObject.h"
32 
33 class VTKCOMMONMATH_EXPORT vtkMatrix3x3 : public vtkObject
34 {
35  // Some of the methods in here have a corresponding static (class)
36  // method taking a pointer to 9 doubles that constitutes a user
37  // supplied matrix. This allows C++ clients to allocate double arrays
38  // on the stack and manipulate them using vtkMatrix3x3 methods.
39  // This is an alternative to allowing vtkMatrix3x3 instances to be
40  // created on the stack (which is frowned upon) or doing lots of
41  // temporary heap allocation within vtkTransform2D methods,
42  // which is inefficient.
43 
44 public:
48  static vtkMatrix3x3 *New();
49 
50  vtkTypeMacro(vtkMatrix3x3,vtkObject);
51  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
52 
58  {vtkMatrix3x3::DeepCopy(*this->Element,source); this->Modified(); }
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 
66  void DeepCopy(const double elements[9])
67  { this->DeepCopy(*this->Element,elements); this->Modified(); }
68 
72  void Zero()
73  { vtkMatrix3x3::Zero(*this->Element); this->Modified(); }
74  static void Zero(double elements[9]);
75 
79  void Identity()
80  { vtkMatrix3x3::Identity(*this->Element); this->Modified();}
81  static void Identity(double elements[9]);
82 
87  static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
88  {vtkMatrix3x3::Invert(*in->Element,*out->Element); out->Modified(); }
89  void Invert()
90  { vtkMatrix3x3::Invert(this,this); }
91  static void Invert(const double inElements[9], double outElements[9]);
92 
96  static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
97  {vtkMatrix3x3::Transpose(*in->Element,*out->Element); out->Modified(); }
98  void Transpose()
99  { vtkMatrix3x3::Transpose(this,this); }
100  static void Transpose(const double inElements[9], double outElements[9]);
101 
106  void MultiplyPoint(const float in[3], float out[3])
107  {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
108  void MultiplyPoint(const double in[3], double out[3])
109  {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
110 
111  static void MultiplyPoint(const double elements[9],
112  const float in[3], float out[3]);
113  static void MultiplyPoint(const double elements[9],
114  const double in[3], double out[3]);
115 
121  static void Multiply3x3(const double a[9], const double b[9],
122  double c[9]);
123 
128  {vtkMatrix3x3::Adjoint(*in->Element,*out->Element);}
129  static void Adjoint(const double inElements[9], double outElements[9]);
130 
134  double Determinant() {return vtkMatrix3x3::Determinant(*this->Element);}
135  static double Determinant(const double elements[9]);
136 
140  void SetElement(int i, int j, double value);
141 
145  double GetElement(int i, int j) const
146  {return this->Element[i][j];}
147 
149 
152  VTK_LEGACY(double *operator[](const unsigned int i));
153  VTK_LEGACY(const double *operator[](unsigned int i) const);
154  VTK_LEGACY(bool operator==(const vtkMatrix3x3&));
155  VTK_LEGACY(bool operator!=(const vtkMatrix3x3&));
156  VTK_LEGACY(void Adjoint(vtkMatrix3x3 &in,vtkMatrix3x3 &out));
157  VTK_LEGACY(double Determinant(vtkMatrix3x3 &in));
158  VTK_LEGACY(double Determinant(vtkMatrix3x3 *));
159  VTK_LEGACY(void Invert(vtkMatrix3x3 &in,vtkMatrix3x3 &out));
160  VTK_LEGACY(void Transpose(vtkMatrix3x3 &in,vtkMatrix3x3 &out));
161  VTK_LEGACY(static void PointMultiply(const double [9],
162  const float [3], float [3]));
163  VTK_LEGACY(static void PointMultiply(const double [9],
164  const double [3], double [3]));
166 
167  // Descption:
168  // Returns true if this matrix is equal to the identity matrix.
169  bool IsIdentity();
170 
174  double * GetData() { return *this->Element; }
175 
176 protected:
177  vtkMatrix3x3();
178  ~vtkMatrix3x3() VTK_OVERRIDE;
179 
180  double Element[3][3]; // The elements of the 3x3 matrix
181 
182 private:
183  vtkMatrix3x3(const vtkMatrix3x3&) VTK_DELETE_FUNCTION;
184  void operator=(const vtkMatrix3x3&) VTK_DELETE_FUNCTION;
185 };
186 
187 inline void vtkMatrix3x3::SetElement(int i, int j, double value)
188 {
189  if (this->Element[i][j] != value)
190  {
191  this->Element[i][j] = value;
192  this->Modified();
193  }
194 }
195 
197 {
198  double *M = *this->Element;
199  if (M[0] == 1.0 && M[4] == 1.0 && M[8] == 1.0 &&
200  M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[5] == 0.0 &&
201  M[6] == 0.0 && M[7] == 0.0)
202  {
203  return true;
204  }
205  else
206  {
207  return false;
208  }
209 }
210 
211 #endif
void DeepCopy(vtkMatrix3x3 *source)
Set the elements of the matrix to the same values as the elements of the source Matrix.
Definition: vtkMatrix3x3.h:57
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix3x3.h:72
void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix3x3.h:127
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
double Determinant()
Compute the determinant of the matrix and return it.
Definition: vtkMatrix3x3.h:134
static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix3x3.h:96
static void Multiply3x3(vtkMatrix3x3 *a, vtkMatrix3x3 *b, vtkMatrix3x3 *c)
Multiplies matrices a and b and stores the result in c (c=a*b).
Definition: vtkMatrix3x3.h:119
a simple class to control print indentation
Definition: vtkIndent.h:33
void DeepCopy(const double elements[9])
Non-static member function.
Definition: vtkMatrix3x3.h:66
void Transpose()
Definition: vtkMatrix3x3.h:98
virtual void Modified()
Update the modification time for this object.
double * GetData()
Return a pointer to the first element of the matrix (double[9]).
Definition: vtkMatrix3x3.h:174
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix3x3.h:145
boost::graph_traits< vtkGraph *>::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
double Element[3][3]
Definition: vtkMatrix3x3.h:180
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix3x3.h:79
#define M(row, col)
bool IsIdentity()
Definition: vtkMatrix3x3.h:196
static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press, 1990).
Definition: vtkMatrix3x3.h:87
static void DeepCopy(double elements[9], vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:59
void Invert()
Definition: vtkMatrix3x3.h:89
void MultiplyPoint(const float in[3], float out[3])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix3x3.h:106
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:33
void MultiplyPoint(const double in[3], double out[3])
Definition: vtkMatrix3x3.h:108