VTK  9.4.20241118
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
47#ifndef vtkMatrix3x3_h
48#define vtkMatrix3x3_h
49
50#include "vtkCommonMathModule.h" // For export macro
51#include "vtkObject.h"
52#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
53
54VTK_ABI_NAMESPACE_BEGIN
55class VTKCOMMONMATH_EXPORT VTK_MARSHALAUTO vtkMatrix3x3 : public vtkObject
56{
57 // Some of the methods in here have a corresponding static (class)
58 // method taking a pointer to 9 doubles that constitutes a user
59 // supplied matrix. This allows C++ clients to allocate double arrays
60 // on the stack and manipulate them using vtkMatrix3x3 methods.
61 // This is an alternative to allowing vtkMatrix3x3 instances to be
62 // created on the stack (which is frowned upon) or doing lots of
63 // temporary heap allocation within vtkTransform2D methods,
64 // which is inefficient.
65
66public:
70 static vtkMatrix3x3* New();
71
72 vtkTypeMacro(vtkMatrix3x3, vtkObject);
73 void PrintSelf(ostream& os, vtkIndent indent) override;
74
80 {
81 vtkMatrix3x3::DeepCopy(*this->Element, source);
82 this->Modified();
83 }
84 static void DeepCopy(double elements[9], vtkMatrix3x3* source)
85 {
86 vtkMatrix3x3::DeepCopy(elements, *source->Element);
87 }
88 static void DeepCopy(double elements[9], const double newElements[9]);
89
93 void DeepCopy(const double elements[9])
94 {
95 vtkMatrix3x3::DeepCopy(*this->Element, elements);
96 this->Modified();
97 }
98
102 void Zero()
103 {
104 vtkMatrix3x3::Zero(*this->Element);
105 this->Modified();
106 }
107 static void Zero(double elements[9]);
108
112 void Identity()
113 {
114 vtkMatrix3x3::Identity(*this->Element);
115 this->Modified();
116 }
117 static void Identity(double elements[9]);
118
123 static void Invert(vtkMatrix3x3* in, vtkMatrix3x3* out)
124 {
126 out->Modified();
127 }
128 void Invert() { vtkMatrix3x3::Invert(this, this); }
129 static void Invert(const double inElements[9], double outElements[9]);
130
134 static void Transpose(vtkMatrix3x3* in, vtkMatrix3x3* out)
135 {
137 out->Modified();
138 }
139 void Transpose() { vtkMatrix3x3::Transpose(this, this); }
140 static void Transpose(const double inElements[9], double outElements[9]);
141
146 void MultiplyPoint(const float in[3], float out[3])
147 {
148 vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
149 }
150 void MultiplyPoint(const double in[3], double out[3])
151 {
152 vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
153 }
154
155 static void MultiplyPoint(const double elements[9], const float in[3], float out[3]);
156 static void MultiplyPoint(const double elements[9], const double in[3], double out[3]);
157
162 {
164 }
165 static void Multiply3x3(const double a[9], const double b[9], double c[9]);
166
171 {
173 }
174 static void Adjoint(const double inElements[9], double outElements[9]);
175
179 double Determinant() { return vtkMatrix3x3::Determinant(*this->Element); }
180 static double Determinant(const double elements[9]);
181
185 void SetElement(int i, int j, double value);
186
190 double GetElement(int i, int j) const { return this->Element[i][j]; }
191
192 // Descption:
193 // Returns true if this matrix is equal to the identity matrix.
194 bool IsIdentity();
195
199 double* GetData() VTK_SIZEHINT(9) { return *this->Element; }
200
204 const double* GetData() const { return *this->Element; }
205
209 void SetData(const double data[9]) { vtkMatrix3x3::DeepCopy(data); }
210
211protected:
213 ~vtkMatrix3x3() override;
214
215 double Element[3][3]; // The elements of the 3x3 matrix
216
217private:
218 vtkMatrix3x3(const vtkMatrix3x3&) = delete;
219 void operator=(const vtkMatrix3x3&) = delete;
220};
221
222inline void vtkMatrix3x3::SetElement(int i, int j, double value)
223{
224 if (this->Element[i][j] != value)
225 {
226 this->Element[i][j] = value;
227 this->Modified();
228 }
229}
230
232{
233 double* M = *this->Element;
234 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 &&
235 M[5] == 0.0 && M[6] == 0.0 && M[7] == 0.0)
236 {
237 return true;
238 }
239 else
240 {
241 return false;
242 }
243}
244
245VTK_ABI_NAMESPACE_END
246#endif
a simple class to control print indentation
Definition vtkIndent.h:108
represent and manipulate 3x3 transformation matrices
static void Identity(double elements[9])
const double * GetData() const
Return a pointer to the first element of the matrix (double[9]).
double Determinant()
Compute the determinant of the matrix and return it.
static void Multiply3x3(vtkMatrix3x3 *a, vtkMatrix3x3 *b, vtkMatrix3x3 *c)
Multiplies matrices a and b and stores the result in c (c=a*b).
static void Invert(const double inElements[9], double outElements[9])
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void Transpose(const double inElements[9], double outElements[9])
~vtkMatrix3x3() override
void DeepCopy(const double elements[9])
Non-static member function.
static void Zero(double elements[9])
void MultiplyPoint(const float in[3], float out[3])
Multiply a homogeneous coordinate by this matrix, i.e.
bool IsIdentity()
static double Determinant(const double elements[9])
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
void SetData(const double data[9])
Copies data into the matrix.
double Element[3][3]
void Zero()
Set all of the elements to zero.
void MultiplyPoint(const double in[3], double out[3])
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
static void DeepCopy(double elements[9], const double newElements[9])
static void DeepCopy(double elements[9], vtkMatrix3x3 *source)
static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
static void Multiply3x3(const double a[9], const double b[9], double c[9])
static void MultiplyPoint(const double elements[9], const double in[3], double out[3])
void Identity()
Set equal to Identity matrix.
static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Transpose the matrix and put it into out.
void DeepCopy(vtkMatrix3x3 *source)
Set the elements of the matrix to the same values as the elements of the source Matrix.
static void MultiplyPoint(const double elements[9], const float in[3], float out[3])
static vtkMatrix3x3 * New()
Construct a 3x3 identity matrix.
double * GetData()
Return a pointer to the first element of the matrix (double[9]).
void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Compute adjoint of the matrix and put it into out.
static void Adjoint(const double inElements[9], double outElements[9])
abstract base class for most VTK objects
Definition vtkObject.h:162
virtual void Modified()
Update the modification time for this object.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO