VTK  9.1.0
vtkMatrix4x4.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkMatrix4x4.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=========================================================================*/
138#ifndef vtkMatrix4x4_h
139#define vtkMatrix4x4_h
140
141#include "vtkCommonMathModule.h" // For export macro
142#include "vtkObject.h"
143
144class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
145{
146public:
148 double Element[4][4];
149
153 static vtkMatrix4x4* New();
154
155 vtkTypeMacro(vtkMatrix4x4, vtkObject);
156 void PrintSelf(ostream& os, vtkIndent indent) override;
157
163 {
164 vtkMatrix4x4::DeepCopy(*this->Element, source);
165 this->Modified();
166 }
167
172 static void DeepCopy(double destination[16], const vtkMatrix4x4* source)
173 {
174 vtkMatrix4x4::DeepCopy(destination, *source->Element);
175 }
176
181 static void DeepCopy(double destination[16], const double source[16]);
182
187 void DeepCopy(const double elements[16])
188 {
189 this->DeepCopy(*this->Element, elements);
190 this->Modified();
191 }
192
196 void Zero()
197 {
198 vtkMatrix4x4::Zero(*this->Element);
199 this->Modified();
200 }
201 static void Zero(double elements[16]);
202
206 void Identity()
207 {
208 vtkMatrix4x4::Identity(*this->Element);
209 this->Modified();
210 }
211 static void Identity(double elements[16]);
212
216 bool IsIdentity();
217
222 static void Invert(const vtkMatrix4x4* in, vtkMatrix4x4* out)
223 {
225 out->Modified();
226 }
227 void Invert() { vtkMatrix4x4::Invert(this, this); }
228 static void Invert(const double inElements[16], double outElements[16]);
229
233 static void Transpose(const vtkMatrix4x4* in, vtkMatrix4x4* out)
234 {
236 out->Modified();
237 }
238 void Transpose() { vtkMatrix4x4::Transpose(this, this); }
239 static void Transpose(const double inElements[16], double outElements[16]);
240
245 void MultiplyPoint(const float in[4], float out[4])
246 {
247 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
248 }
249 void MultiplyPoint(const double in[4], double out[4])
250 {
251 vtkMatrix4x4::MultiplyPoint(*this->Element, in, out);
252 }
253
254 static void MultiplyPoint(const double elements[16], const float in[4], float out[4]);
255 static void MultiplyPoint(const double elements[16], const double in[4], double out[4]);
256
260 float* MultiplyPoint(const float in[4]) VTK_SIZEHINT(4) { return this->MultiplyFloatPoint(in); }
261 double* MultiplyPoint(const double in[4]) VTK_SIZEHINT(4)
262 {
263 return this->MultiplyDoublePoint(in);
264 }
265 float* MultiplyFloatPoint(const float in[4]) VTK_SIZEHINT(4)
266 {
267 this->MultiplyPoint(in, this->FloatPoint);
268 return this->FloatPoint;
269 }
270 double* MultiplyDoublePoint(const double in[4]) VTK_SIZEHINT(4)
271 {
272 this->MultiplyPoint(in, this->DoublePoint);
273 return this->DoublePoint;
274 }
275
277
280 static void Multiply4x4(const vtkMatrix4x4* a, const vtkMatrix4x4* b, vtkMatrix4x4* c);
281 static void Multiply4x4(const double a[16], const double b[16], double c[16]);
282 static void Multiply4x4(const double a[16], const double b[16], float c[16]);
283 static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16]);
285
289 void Adjoint(const vtkMatrix4x4* in, vtkMatrix4x4* out)
290 {
292 }
293 static void Adjoint(const double inElements[16], double outElements[16]);
294
298 double Determinant() { return vtkMatrix4x4::Determinant(*this->Element); }
299 static double Determinant(const double elements[16]);
300
304 void SetElement(int i, int j, double value);
305
309 double GetElement(int i, int j) const { return this->Element[i][j]; }
310
314 double* GetData() { return *this->Element; }
315
319 const double* GetData() const { return *this->Element; }
320
321protected:
323 ~vtkMatrix4x4() override = default;
324
325 float FloatPoint[4];
326 double DoublePoint[4];
327
328private:
329 vtkMatrix4x4(const vtkMatrix4x4&) = delete;
330 void operator=(const vtkMatrix4x4&) = delete;
331};
332
333//----------------------------------------------------------------------------
334// Multiplies matrices a and b and stores the result in c.
335inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], double c[16])
336{
337 double tmp[16];
338
339 for (int i = 0; i < 16; i += 4)
340 {
341 for (int j = 0; j < 4; j++)
342 {
343 tmp[i + j] =
344 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
345 }
346 }
347
348 for (int k = 0; k < 16; k++)
349 {
350 c[k] = tmp[k];
351 }
352}
353
354//----------------------------------------------------------------------------
355// Multiplies matrices a and b and stores the result in c.
356inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16], float c[16])
357{
358 for (int i = 0; i < 16; i += 4)
359 {
360 for (int j = 0; j < 4; j++)
361 {
362 c[i + j] =
363 a[i + 0] * b[j + 0] + a[i + 1] * b[j + 4] + a[i + 2] * b[j + 8] + a[i + 3] * b[j + 12];
364 }
365 }
366}
367
368//----------------------------------------------------------------------------
369// Multiplies matrices a and b and stores the result in c.
371 const double a[16], const double b[16], float c[16])
372{
373 for (int i = 0; i < 4; i++)
374 {
375 for (int j = 0; j < 4; j++)
376 {
377 int it4 = i * 4;
378 c[i + j * 4] = a[it4 + 0] * b[j + 0] + a[it4 + 1] * b[j + 4] + a[it4 + 2] * b[j + 8] +
379 a[it4 + 3] * b[j + 12];
380 }
381 }
382}
383
384//----------------------------------------------------------------------------
386{
388}
389
390//----------------------------------------------------------------------------
391inline void vtkMatrix4x4::SetElement(int i, int j, double value)
392{
393 if (this->Element[i][j] != value)
394 {
395 this->Element[i][j] = value;
396 this->Modified();
397 }
398}
399
400//----------------------------------------------------------------------------
402{
403 double* M = *this->Element;
404 return M[0] == 1.0 && M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[4] == 0.0 && M[5] == 1.0 &&
405 M[6] == 0.0 && M[7] == 0.0 && M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
406 M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
407}
408
409#endif
a simple class to control print indentation
Definition: vtkIndent.h:113
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
static void Transpose(const double inElements[16], double outElements[16])
static double Determinant(const double elements[16])
void DeepCopy(const vtkMatrix4x4 *source)
Set the elements of the matrix to the same values as the elements of the given source matrix.
Definition: vtkMatrix4x4.h:162
static vtkMatrix4x4 * New()
Construct a 4x4 identity matrix.
void DeepCopy(const double elements[16])
Non-static member function.
Definition: vtkMatrix4x4.h:187
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
Definition: vtkMatrix4x4.h:309
double * MultiplyDoublePoint(const double in[4])
Definition: vtkMatrix4x4.h:270
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
Multiplies matrices a and b and stores the result in c.
Definition: vtkMatrix4x4.h:385
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkMatrix4x4.h:249
static void Adjoint(const double inElements[16], double outElements[16])
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:245
void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Compute adjoint of the matrix and put it into out.
Definition: vtkMatrix4x4.h:289
void Identity()
Set equal to Identity matrix.
Definition: vtkMatrix4x4.h:206
double Determinant()
Compute the determinant of the matrix and return it.
Definition: vtkMatrix4x4.h:298
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
Definition: vtkMatrix4x4.h:391
static void DeepCopy(double destination[16], const vtkMatrix4x4 *source)
Set the elements of the given destination buffer to the same values as the elements of the given sour...
Definition: vtkMatrix4x4.h:172
void Zero()
Set all of the elements to zero.
Definition: vtkMatrix4x4.h:196
double * GetData()
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:314
void Transpose()
Definition: vtkMatrix4x4.h:238
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:148
static void MultiplyAndTranspose4x4(const double a[16], const double b[16], float c[16])
Multiplies matrices a and b and stores the result in c.
Definition: vtkMatrix4x4.h:370
static void DeepCopy(double destination[16], const double source[16])
Copies the given source buffer to the given destination buffer.
static void Invert(const double inElements[16], double outElements[16])
static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: vtkMatrix4x4.h:222
float * MultiplyPoint(const float in[4])
For use in Java or Python.
Definition: vtkMatrix4x4.h:260
double * MultiplyPoint(const double in[4])
Definition: vtkMatrix4x4.h:261
float * MultiplyFloatPoint(const float in[4])
Definition: vtkMatrix4x4.h:265
static void Identity(double elements[16])
static void MultiplyPoint(const double elements[16], const double in[4], double out[4])
static void Zero(double elements[16])
static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
Transpose the matrix and put it into out.
Definition: vtkMatrix4x4.h:233
const double * GetData() const
Returns the raw double array holding the matrix.
Definition: vtkMatrix4x4.h:319
~vtkMatrix4x4() override=default
static void MultiplyPoint(const double elements[16], const float in[4], float out[4])
bool IsIdentity()
Returns true if this matrix is equal to the identity matrix.
Definition: vtkMatrix4x4.h:401
abstract base class for most VTK objects
Definition: vtkObject.h:82
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(...)