VTK  9.2.6
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 =========================================================================*/
30 #ifndef vtkMatrix3x3_h
31 #define vtkMatrix3x3_h
32 
33 #include "vtkCommonMathModule.h" // For export macro
34 #include "vtkObject.h"
35 
36 class VTKCOMMONMATH_EXPORT vtkMatrix3x3 : public vtkObject
37 {
38  // Some of the methods in here have a corresponding static (class)
39  // method taking a pointer to 9 doubles that constitutes a user
40  // supplied matrix. This allows C++ clients to allocate double arrays
41  // on the stack and manipulate them using vtkMatrix3x3 methods.
42  // This is an alternative to allowing vtkMatrix3x3 instances to be
43  // created on the stack (which is frowned upon) or doing lots of
44  // temporary heap allocation within vtkTransform2D methods,
45  // which is inefficient.
46 
47 public:
51  static vtkMatrix3x3* New();
52 
53  vtkTypeMacro(vtkMatrix3x3, vtkObject);
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
61  {
62  vtkMatrix3x3::DeepCopy(*this->Element, source);
63  this->Modified();
64  }
65  static void DeepCopy(double elements[9], vtkMatrix3x3* source)
66  {
67  vtkMatrix3x3::DeepCopy(elements, *source->Element);
68  }
69  static void DeepCopy(double elements[9], const double newElements[9]);
70 
74  void DeepCopy(const double elements[9])
75  {
76  this->DeepCopy(*this->Element, elements);
77  this->Modified();
78  }
79 
83  void Zero()
84  {
85  vtkMatrix3x3::Zero(*this->Element);
86  this->Modified();
87  }
88  static void Zero(double elements[9]);
89 
93  void Identity()
94  {
95  vtkMatrix3x3::Identity(*this->Element);
96  this->Modified();
97  }
98  static void Identity(double elements[9]);
99 
104  static void Invert(vtkMatrix3x3* in, vtkMatrix3x3* out)
105  {
106  vtkMatrix3x3::Invert(*in->Element, *out->Element);
107  out->Modified();
108  }
109  void Invert() { vtkMatrix3x3::Invert(this, this); }
110  static void Invert(const double inElements[9], double outElements[9]);
111 
115  static void Transpose(vtkMatrix3x3* in, vtkMatrix3x3* out)
116  {
118  out->Modified();
119  }
120  void Transpose() { vtkMatrix3x3::Transpose(this, this); }
121  static void Transpose(const double inElements[9], double outElements[9]);
122 
127  void MultiplyPoint(const float in[3], float out[3])
128  {
129  vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
130  }
131  void MultiplyPoint(const double in[3], double out[3])
132  {
133  vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
134  }
135 
136  static void MultiplyPoint(const double elements[9], const float in[3], float out[3]);
137  static void MultiplyPoint(const double elements[9], const double in[3], double out[3]);
138 
143  {
145  }
146  static void Multiply3x3(const double a[9], const double b[9], double c[9]);
147 
152  {
154  }
155  static void Adjoint(const double inElements[9], double outElements[9]);
156 
160  double Determinant() { return vtkMatrix3x3::Determinant(*this->Element); }
161  static double Determinant(const double elements[9]);
162 
166  void SetElement(int i, int j, double value);
167 
171  double GetElement(int i, int j) const { return this->Element[i][j]; }
172 
173  // Descption:
174  // Returns true if this matrix is equal to the identity matrix.
175  bool IsIdentity();
176 
180  double* GetData() VTK_SIZEHINT(9) { return *this->Element; }
181 
185  const double* GetData() const { return *this->Element; }
186 
187 protected:
188  vtkMatrix3x3();
189  ~vtkMatrix3x3() override;
190 
191  double Element[3][3]; // The elements of the 3x3 matrix
192 
193 private:
194  vtkMatrix3x3(const vtkMatrix3x3&) = delete;
195  void operator=(const vtkMatrix3x3&) = delete;
196 };
197 
198 inline void vtkMatrix3x3::SetElement(int i, int j, double value)
199 {
200  if (this->Element[i][j] != value)
201  {
202  this->Element[i][j] = value;
203  this->Modified();
204  }
205 }
206 
208 {
209  double* M = *this->Element;
210  if (M[0] == 1.0 && M[4] == 1.0 && M[8] == 1.0 && M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 &&
211  M[5] == 0.0 && M[6] == 0.0 && M[7] == 0.0)
212  {
213  return true;
214  }
215  else
216  {
217  return false;
218  }
219 }
220 
221 #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:60
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix3x3.h:83
void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix3x3.h:151
abstract base class for most VTK objects
Definition: vtkObject.h:62
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:160
static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix3x3.h:115
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:142
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix3x3.h:171
a simple class to control print indentation
Definition: vtkIndent.h:39
void DeepCopy(const double elements[9])
Non-static member function.
Definition: vtkMatrix3x3.h:74
void Transpose()
Definition: vtkMatrix3x3.h:120
virtual void Modified()
Update the modification time for this object.
#define VTK_SIZEHINT(...)
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix3x3.h:198
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
double * GetData()
Return a pointer to the first element of the matrix (double[9]).
Definition: vtkMatrix3x3.h:180
double Element[3][3]
Definition: vtkMatrix3x3.h:191
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix3x3.h:93
bool IsIdentity()
Definition: vtkMatrix3x3.h:207
static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press, 1990).
Definition: vtkMatrix3x3.h:104
const double * GetData() const
Return a pointer to the first element of the matrix (double[9]).
Definition: vtkMatrix3x3.h:185
static void DeepCopy(double elements[9], vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:65
void MultiplyPoint(const float in[3], float out[3])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix3x3.h:127
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:36
void MultiplyPoint(const double in[3], double out[3])
Definition: vtkMatrix3x3.h:131