VTK  9.7.1
vtkMatrix3x3.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
18 #ifndef vtkMatrix3x3_h
19 #define vtkMatrix3x3_h
20 
21 #include "vtkCommonMathModule.h" // For export macro
22 #include "vtkObject.h"
23 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
24 
25 VTK_ABI_NAMESPACE_BEGIN
26 class VTKCOMMONMATH_EXPORT VTK_MARSHALAUTO vtkMatrix3x3 : public vtkObject
27 {
28  // Some of the methods in here have a corresponding static (class)
29  // method taking a pointer to 9 doubles that constitutes a user
30  // supplied matrix. This allows C++ clients to allocate double arrays
31  // on the stack and manipulate them using vtkMatrix3x3 methods.
32  // This is an alternative to allowing vtkMatrix3x3 instances to be
33  // created on the stack (which is frowned upon) or doing lots of
34  // temporary heap allocation within vtkTransform2D methods,
35  // which is inefficient.
36 
37 public:
41  static vtkMatrix3x3* New();
42 
43  vtkTypeMacro(vtkMatrix3x3, vtkObject);
44  void PrintSelf(ostream& os, vtkIndent indent) override;
45 
51  {
52  vtkMatrix3x3::DeepCopy(*this->Element, source);
53  this->Modified();
54  }
55  static void DeepCopy(double elements[9], vtkMatrix3x3* source)
56  {
57  vtkMatrix3x3::DeepCopy(elements, *source->Element);
58  }
59  static void DeepCopy(double elements[9], const double newElements[9]);
60 
64  void DeepCopy(const double elements[9])
65  {
66  vtkMatrix3x3::DeepCopy(*this->Element, elements);
67  this->Modified();
68  }
69 
73  void Zero()
74  {
75  vtkMatrix3x3::Zero(*this->Element);
76  this->Modified();
77  }
78  static void Zero(double elements[9]);
79 
83  void Identity()
84  {
85  vtkMatrix3x3::Identity(*this->Element);
86  this->Modified();
87  }
88  static void Identity(double elements[9]);
89 
94  static void Invert(vtkMatrix3x3* in, vtkMatrix3x3* out)
95  {
97  out->Modified();
98  }
99  void Invert() { vtkMatrix3x3::Invert(this, this); }
100  static void Invert(const double inElements[9], double outElements[9]);
101 
105  static void Transpose(vtkMatrix3x3* in, vtkMatrix3x3* out)
106  {
108  out->Modified();
109  }
110  void Transpose() { vtkMatrix3x3::Transpose(this, this); }
111  static void Transpose(const double inElements[9], double outElements[9]);
112 
117  void MultiplyPoint(const float in[3], float out[3])
118  {
119  vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
120  }
121  void MultiplyPoint(const double in[3], double out[3])
122  {
123  vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
124  }
125 
126  static void MultiplyPoint(const double elements[9], const float in[3], float out[3]);
127  static void MultiplyPoint(const double elements[9], const double in[3], double out[3]);
128 
133  {
135  }
136  static void Multiply3x3(const double a[9], const double b[9], double c[9]);
137 
142  {
144  }
145  static void Adjoint(const double inElements[9], double outElements[9]);
146 
150  double Determinant() { return vtkMatrix3x3::Determinant(*this->Element); }
151  static double Determinant(const double elements[9]);
152 
156  void SetElement(int i, int j, double value);
157 
161  double GetElement(int i, int j) const { return this->Element[i][j]; }
162 
163  // Descption:
164  // Returns true if this matrix is equal to the identity matrix.
165  bool IsIdentity();
166 
170  double* GetData() VTK_SIZEHINT(9) { return *this->Element; }
171 
175  const double* GetData() const { return *this->Element; }
176 
180  void SetData(const double data[9]) { vtkMatrix3x3::DeepCopy(data); }
181 
182 protected:
183  vtkMatrix3x3();
184  ~vtkMatrix3x3() override;
185 
186  double Element[3][3]; // The elements of the 3x3 matrix
187 
188 private:
189  vtkMatrix3x3(const vtkMatrix3x3&) = delete;
190  void operator=(const vtkMatrix3x3&) = delete;
191 };
192 
193 inline void vtkMatrix3x3::SetElement(int i, int j, double value)
194 {
195  if (this->Element[i][j] != value)
196  {
197  this->Element[i][j] = value;
198  this->Modified();
199  }
200 }
201 
203 {
204  double* M = *this->Element;
205  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 &&
206  M[5] == 0.0 && M[6] == 0.0 && M[7] == 0.0)
207  {
208  return true;
209  }
210  else
211  {
212  return false;
213  }
214 }
215 
216 VTK_ABI_NAMESPACE_END
217 #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:50
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix3x3.h:73
void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix3x3.h:141
abstract base class for most VTK objects
Definition: vtkObject.h:52
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:150
static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix3x3.h:105
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:132
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix3x3.h:161
a simple class to control print indentation
Definition: vtkIndent.h:28
void SetData(const double data[9])
Copies data into the matrix.
Definition: vtkMatrix3x3.h:180
void DeepCopy(const double elements[9])
Non-static member function.
Definition: vtkMatrix3x3.h:64
void Transpose()
Definition: vtkMatrix3x3.h:110
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:193
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:170
double Element[3][3]
Definition: vtkMatrix3x3.h:186
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix3x3.h:83
bool IsIdentity()
Definition: vtkMatrix3x3.h:202
static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press, 1990).
Definition: vtkMatrix3x3.h:94
const double * GetData() const
Return a pointer to the first element of the matrix (double[9]).
Definition: vtkMatrix3x3.h:175
static void DeepCopy(double elements[9], vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:55
#define VTK_MARSHALAUTO
void Invert()
Definition: vtkMatrix3x3.h:99
void MultiplyPoint(const float in[3], float out[3])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix3x3.h:117
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:26
void MultiplyPoint(const double in[3], double out[3])
Definition: vtkMatrix3x3.h:121