ALBA
albaMatrix.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaMatrix
5 Authors: Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16
17#ifndef __albaMatrix_h
18#define __albaMatrix_h
19
21#include "albaMTime.h"
22#include "vtkType.h"
23
24typedef double (*albaMatrixElements)[4];
25
26//------------------------------------------------------------------------------
27// Forward declarations
28//------------------------------------------------------------------------------
29#ifdef ALBA_USE_VTK
30class vtkMatrix4x4;
31#endif
32class albaVect3d;
33
34
44class ALBA_EXPORT albaMatrix : public albaReferenceCounted
45{
46public:
48 virtual void Print(std::ostream& os, const int indent=0) const;
49
51 virtual ~albaMatrix();
52
54
56
57 bool operator==(const albaMatrix& mat) const;
58
59 bool Equals(const albaMatrix *mat) const;
60
61 void DeepCopy(const albaMatrix* mat) {*this=*mat;}
62
63#ifdef ALBA_USE_VTK
64
66 albaMatrix(vtkMatrix4x4 *mat);
67
69 void SetVTKMatrix(vtkMatrix4x4 *mat,albaTimeStamp t=0);
70
72 void DeepCopy(vtkMatrix4x4 *mat);
73
75 vtkMatrix4x4 *GetVTKMatrix() const {return m_VTKMatrix;}
76
80 bool operator==(vtkMatrix4x4 *mat) const;
81#endif
82
85
89 void SetElement(const int i, const int j, double value) {GetElements()[i][j]=value;Modified();}
90
92 double GetElement(const int i, const int j) const {return GetElements()[i][j];}
93
95 vtkMTimeType GetMTime() const;
96
98 void Modified();
99
101 void SetTimeStamp(albaTimeStamp t) {if (!albaEquals(m_TimeStamp,t)){m_TimeStamp=t; Modified();}};
102 albaTimeStamp GetTimeStamp() const {return m_TimeStamp;};
103
105 static void GetVersor(const int axis, const albaMatrix &matrix, double versor[3]);
107 void GetVersor(const int axis, double versor[3]) const {GetVersor(axis,(*this),versor);}
108
110 void CopyRotation(const albaMatrix &source) {CopyRotation(source,*this);}
112 static void CopyRotation(const albaMatrix &source, albaMatrix &target);
113
115 void Zero() { albaMatrix::Zero(*GetElements()); Modified(); }
117 static void Zero(double elements[16]);
118
120 void Identity() { albaMatrix::Identity(*GetElements()); Modified();}
121 static void Identity(double elements[16]);
122
125
129 static void Invert(const albaMatrix &in, albaMatrix &out) {albaMatrix::Invert(*in.GetElements(),*out.GetElements()); out.Modified();}
133 albaMatrix *Invert() { albaMatrix::Invert(*this, *this); return this; }
135 albaMatrix GetInverse() { albaMatrix inv; albaMatrix::Invert(*this, inv); return inv; }
136
140 static void Invert(const double inElements[16], double outElements[16]);
141
143 static double Determinant(const double Elements[16]);
144 double Determinant() const {return Determinant(*GetElements());};
145
147 static void Adjoint(const double inElements[16], double outElements[16]);
148 void Adjoint(const albaMatrix &inMat, albaMatrix &outMat) {Adjoint(*(inMat.GetElements()),*(outMat.GetElements()));outMat.Modified();};
149 void Adjoint() {Adjoint(*GetElements(),*GetElements());Modified();}
150
152 static void Transpose(const albaMatrix &in, albaMatrix &out)
155 void Transpose() { albaMatrix::Transpose(*this,*this); }
157 static void Transpose(const double inElements[16], double outElements[16]);
158
162 void MultiplyPoint(const double in[4], double out[4]) const
163 {albaMatrix::MultiplyPoint(*GetElements(),in,out); }
164
168
169
173 static void MultiplyPoint(const double Elements[16],
174 const double in[4], double out[4]);
175
177 static void Multiply4x4(const albaMatrix &a, const albaMatrix &b, albaMatrix &c) {
180 static void Multiply4x4(const double a[16], const double b[16],
181 double c[16]);
182
184 double *operator[](const unsigned int i) {return &(GetElements()[i][0]);Modified();}
185
187 const double *operator[](unsigned int i) const { return &(GetElements()[i][0]); }
188
190 operator vtkMatrix4x4*() const {
191 return GetVTKMatrix();
192 }
193
194 //double *operator[][](const unsigned int i,const unsigned int j) {return &(GetElements()[i][j]);}
195
199 static void PointMultiply(const double Elements[16],
200 const float in[4], float out[4]);
204 static void PointMultiply(const double Elements[16],
205 const double in[4], double out[4]);
206
207 void SetFromDirectionCosines(const double orientation[6]);
208protected:
210
211#ifdef ALBA_USE_VTK
212 vtkMatrix4x4 *m_VTKMatrix;
213#else
214 double m_Elements[4][4];
216#endif
217
218};
219
220#endif
ALBA_EXPORT bool albaEquals(double x, double y)
reliable comparison test for floating point numbers.
double albaTimeStamp
type for time varying data timestamps (not for pipelines timestamps!)
Definition: albaDefines.h:60
double(* albaMatrixElements)[4]
Definition: albaMatrix.h:24
bool operator==(const albaAutoPointer< T > &l, const albaAutoPointer< T > &r)
albaMTime - record modification timestamp.
Definition: albaMTime.h:39
albaMatrix - Time stamped 4x4 Matrix.
Definition: albaMatrix.h:45
static void MultiplyPoint(const double Elements[16], const double in[4], double out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
void Zero()
Set all of the elements to zero.
Definition: albaMatrix.h:115
void Adjoint(const albaMatrix &inMat, albaMatrix &outMat)
Definition: albaMatrix.h:148
static void Adjoint(const double inElements[16], double outElements[16])
Matrix adjoint.
static void Identity(double elements[16])
bool IsIdentity()
Return true if is an Identity Matrix.
albaMatrixElements GetElements() const
return pointer to elements matrix: returned type is a double [4][4] object
static void Transpose(const double inElements[16], double outElements[16])
Transpose the matrix and put it into out.
void SetFromDirectionCosines(const double orientation[6])
vtkMTimeType GetMTime() const
return modification time for this object
void CopyRotation(const albaMatrix &source)
Copy the 3x3 rotation matrix from another 4x4 matrix.
Definition: albaMatrix.h:110
albaMatrix GetInverse()
Return the inverse matrix without modifying the original.
Definition: albaMatrix.h:135
virtual void Print(std::ostream &os, const int indent=0) const
print debug information for this object
static void Invert(const double inElements[16], double outElements[16])
Matrix Inversion, (adapted from Richard Carling in "Graphics Gems," Academic Press,...
void Identity()
Set equal to Identity matrix.
Definition: albaMatrix.h:120
double GetElement(const int i, const int j) const
Returns the element i,j from the matrix.
Definition: albaMatrix.h:92
void Transpose()
Transpose the matrix and put it into out.
Definition: albaMatrix.h:155
static void Zero(double elements[16])
Set all of the elements to zero.
albaTimeStamp m_TimeStamp
Definition: albaMatrix.h:209
void DeepCopy(const albaMatrix *mat)
Definition: albaMatrix.h:61
albaMatrix * Invert()
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: albaMatrix.h:133
static void PointMultiply(const double Elements[16], const double in[4], double out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
virtual ~albaMatrix()
void SetTimeStamp(albaTimeStamp t)
Set the TimeStamp for this matrix.
Definition: albaMatrix.h:101
static void Multiply4x4(const double a[16], const double b[16], double c[16])
Multiplies matrices a and b and stores the result in c.
static void PointMultiply(const double Elements[16], const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
albaVect3d MultiplyPoint(albaVect3d point)
Multiply an albaVect3d to this matrix, i.e.
bool operator==(const albaMatrix &mat) const
bool Equals(const albaMatrix *mat) const
albaMatrix & operator=(const albaMatrix &mat)
static double Determinant(const double Elements[16])
Matrix determinant.
void Modified()
update modification time stamp for this object
static void CopyRotation(const albaMatrix &source, albaMatrix &target)
Copy the 3x3 rotation matrix from a 4x4 matrix to another.
const double * operator[](unsigned int i) const
bracket operator to access single elements
Definition: albaMatrix.h:187
double Determinant() const
Definition: albaMatrix.h:144
static void Invert(const albaMatrix &in, albaMatrix &out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: albaMatrix.h:129
albaMTime m_MTime
Definition: albaMatrix.h:215
static void GetVersor(const int axis, const albaMatrix &matrix, double versor[3])
Get the given matrix versor.
static void Multiply4x4(const albaMatrix &a, const albaMatrix &b, albaMatrix &c)
Multiplies matrices a and b and stores the result in c.
Definition: albaMatrix.h:177
albaTimeStamp GetTimeStamp() const
Definition: albaMatrix.h:102
void Adjoint()
Definition: albaMatrix.h:149
void MultiplyPoint(const double in[4], double out[4]) const
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: albaMatrix.h:162
static void Transpose(const albaMatrix &in, albaMatrix &out)
Transpose the matrix and put it into out.
Definition: albaMatrix.h:152
albaMatrix(const albaMatrix &mat)
void GetVersor(const int axis, double versor[3]) const
Get the given matrix versor.
Definition: albaMatrix.h:107
void SetElement(const int i, const int j, double value)
Sets the element i,j in the matrix.
Definition: albaMatrix.h:89
double * operator[](const unsigned int i)
bracket operator to access & write single elements
Definition: albaMatrix.h:184
albaTypeMacro(albaMatrix, albaReferenceCounted)
albaReferenceCounted - abstract base class for ALBA objects with reference counting.
Class Name: albaVect3d.
Definition: albaVect3d.h:35