VTK  9.1.0
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 =========================================================================*/
56 #ifndef vtkMatrix3x3_h
57 #define vtkMatrix3x3_h
58 
59 #include "vtkCommonMathModule.h" // For export macro
60 #include "vtkObject.h"
61 
62 class VTKCOMMONMATH_EXPORT vtkMatrix3x3 : public vtkObject
63 {
64  // Some of the methods in here have a corresponding static (class)
65  // method taking a pointer to 9 doubles that constitutes a user
66  // supplied matrix. This allows C++ clients to allocate double arrays
67  // on the stack and manipulate them using vtkMatrix3x3 methods.
68  // This is an alternative to allowing vtkMatrix3x3 instances to be
69  // created on the stack (which is frowned upon) or doing lots of
70  // temporary heap allocation within vtkTransform2D methods,
71  // which is inefficient.
72 
73 public:
77  static vtkMatrix3x3* New();
78 
79  vtkTypeMacro(vtkMatrix3x3, vtkObject);
80  void PrintSelf(ostream& os, vtkIndent indent) override;
81 
87  {
88  vtkMatrix3x3::DeepCopy(*this->Element, source);
89  this->Modified();
90  }
91  static void DeepCopy(double elements[9], vtkMatrix3x3* source)
92  {
93  vtkMatrix3x3::DeepCopy(elements, *source->Element);
94  }
95  static void DeepCopy(double elements[9], const double newElements[9]);
96 
100  void DeepCopy(const double elements[9])
101  {
102  this->DeepCopy(*this->Element, elements);
103  this->Modified();
104  }
105 
109  void Zero()
110  {
111  vtkMatrix3x3::Zero(*this->Element);
112  this->Modified();
113  }
114  static void Zero(double elements[9]);
115 
119  void Identity()
120  {
121  vtkMatrix3x3::Identity(*this->Element);
122  this->Modified();
123  }
124  static void Identity(double elements[9]);
125 
130  static void Invert(vtkMatrix3x3* in, vtkMatrix3x3* out)
131  {
132  vtkMatrix3x3::Invert(*in->Element, *out->Element);
133  out->Modified();
134  }
135  void Invert() { vtkMatrix3x3::Invert(this, this); }
136  static void Invert(const double inElements[9], double outElements[9]);
137 
141  static void Transpose(vtkMatrix3x3* in, vtkMatrix3x3* out)
142  {
144  out->Modified();
145  }
146  void Transpose() { vtkMatrix3x3::Transpose(this, this); }
147  static void Transpose(const double inElements[9], double outElements[9]);
148 
153  void MultiplyPoint(const float in[3], float out[3])
154  {
155  vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
156  }
157  void MultiplyPoint(const double in[3], double out[3])
158  {
159  vtkMatrix3x3::MultiplyPoint(*this->Element, in, out);
160  }
161 
162  static void MultiplyPoint(const double elements[9], const float in[3], float out[3]);
163  static void MultiplyPoint(const double elements[9], const double in[3], double out[3]);
164 
169  {
171  }
172  static void Multiply3x3(const double a[9], const double b[9], double c[9]);
173 
178  {
180  }
181  static void Adjoint(const double inElements[9], double outElements[9]);
182 
186  double Determinant() { return vtkMatrix3x3::Determinant(*this->Element); }
187  static double Determinant(const double elements[9]);
188 
192  void SetElement(int i, int j, double value);
193 
197  double GetElement(int i, int j) const { return this->Element[i][j]; }
198 
199  // Descption:
200  // Returns true if this matrix is equal to the identity matrix.
201  bool IsIdentity();
202 
206  double* GetData() VTK_SIZEHINT(9) { return *this->Element; }
207 
211  const double* GetData() const { return *this->Element; }
212 
213 protected:
215  ~vtkMatrix3x3() override;
216 
217  double Element[3][3]; // The elements of the 3x3 matrix
218 
219 private:
220  vtkMatrix3x3(const vtkMatrix3x3&) = delete;
221  void operator=(const vtkMatrix3x3&) = delete;
222 };
223 
224 inline void vtkMatrix3x3::SetElement(int i, int j, double value)
225 {
226  if (this->Element[i][j] != value)
227  {
228  this->Element[i][j] = value;
229  this->Modified();
230  }
231 }
232 
234 {
235  double* M = *this->Element;
236  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 &&
237  M[5] == 0.0 && M[6] == 0.0 && M[7] == 0.0)
238  {
239  return true;
240  }
241  else
242  {
243  return false;
244  }
245 }
246 
247 #endif
a simple class to control print indentation
Definition: vtkIndent.h:113
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:63
static void Identity(double elements[9])
double Determinant()
Compute the determinant of the matrix and return it.
Definition: vtkMatrix3x3.h:186
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:168
static void Invert(const double inElements[9], double outElements[9])
const double * GetData() const
Return a pointer to the first element of the matrix (double[9]).
Definition: vtkMatrix3x3.h:211
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])
static vtkMatrix3x3 * New()
Construct a 3x3 identity matrix.
~vtkMatrix3x3() override
double * GetData()
Return a pointer to the first element of the matrix (double[9]).
Definition: vtkMatrix3x3.h:206
void DeepCopy(const double elements[9])
Non-static member function.
Definition: vtkMatrix3x3.h:100
static void Zero(double elements[9])
void MultiplyPoint(const float in[3], float out[3])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix3x3.h:153
bool IsIdentity()
Definition: vtkMatrix3x3.h:233
static double Determinant(const double elements[9])
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix3x3.h:197
double Element[3][3]
Definition: vtkMatrix3x3.h:217
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix3x3.h:109
void MultiplyPoint(const double in[3], double out[3])
Definition: vtkMatrix3x3.h:157
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix3x3.h:224
static void DeepCopy(double elements[9], const double newElements[9])
static void DeepCopy(double elements[9], vtkMatrix3x3 *source)
Definition: vtkMatrix3x3.h:91
static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix3x3.h:130
static void Multiply3x3(const double a[9], const double b[9], double c[9])
void Transpose()
Definition: vtkMatrix3x3.h:146
static void MultiplyPoint(const double elements[9], const double in[3], double out[3])
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix3x3.h:119
static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix3x3.h:141
void DeepCopy(vtkMatrix3x3 *source)
Set the elements of the matrix to the same values as the elements of the source Matrix.
Definition: vtkMatrix3x3.h:86
static void MultiplyPoint(const double elements[9], const float in[3], float out[3])
void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix3x3.h:177
static void Adjoint(const double inElements[9], double outElements[9])
abstract base class for most VTK objects
Definition: vtkObject.h:73
virtual void Modified()
Update the modification time for this object.
@ value
Definition: vtkX3D.h:226
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)