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
23typedef double (*albaMatrixElements)[4];
24
25//------------------------------------------------------------------------------
26// Forward declarations
27//------------------------------------------------------------------------------
28#ifdef ALBA_USE_VTK
29class vtkMatrix4x4;
30#endif
31class albaVect3d;
32
33
43class ALBA_EXPORT albaMatrix : public albaReferenceCounted
44{
45public:
47 virtual void Print(std::ostream& os, const int indent=0) const;
48
50 virtual ~albaMatrix();
51
53
55
56 bool operator==(const albaMatrix& mat) const;
57
58 bool Equals(const albaMatrix *mat) const;
59
60 void DeepCopy(const albaMatrix* mat) {*this=*mat;}
61
62#ifdef ALBA_USE_VTK
63
65 albaMatrix(vtkMatrix4x4 *mat);
66
68 void SetVTKMatrix(vtkMatrix4x4 *mat,albaTimeStamp t=0);
69
71 void DeepCopy(vtkMatrix4x4 *mat);
72
74 vtkMatrix4x4 *GetVTKMatrix() const {return m_VTKMatrix;}
75
79 bool operator==(vtkMatrix4x4 *mat) const;
80#endif
81
84
88 void SetElement(const int i, const int j, double value) {GetElements()[i][j]=value;Modified();}
89
91 double GetElement(const int i, const int j) const {return GetElements()[i][j];}
92
94 unsigned long GetMTime() const;
95
97 void Modified();
98
100 void SetTimeStamp(albaTimeStamp t) {if (!albaEquals(m_TimeStamp,t)){m_TimeStamp=t; Modified();}};
101 albaTimeStamp GetTimeStamp() const {return m_TimeStamp;};
102
104 static void GetVersor(const int axis, const albaMatrix &matrix, double versor[3]);
106 void GetVersor(const int axis, double versor[3]) const {GetVersor(axis,(*this),versor);}
107
109 void CopyRotation(const albaMatrix &source) {CopyRotation(source,*this);}
111 static void CopyRotation(const albaMatrix &source, albaMatrix &target);
112
114 void Zero() { albaMatrix::Zero(*GetElements()); Modified(); }
116 static void Zero(double elements[16]);
117
119 void Identity() { albaMatrix::Identity(*GetElements()); Modified();}
120 static void Identity(double elements[16]);
121
124
128 static void Invert(const albaMatrix &in, albaMatrix &out) {albaMatrix::Invert(*in.GetElements(),*out.GetElements()); out.Modified();}
132 albaMatrix *Invert() { albaMatrix::Invert(*this, *this); return this; }
136 static void Invert(const double inElements[16], double outElements[16]);
137
139 static double Determinant(const double Elements[16]);
140 double Determinant() const {return Determinant(*GetElements());};
141
143 static void Adjoint(const double inElements[16], double outElements[16]);
144 void Adjoint(const albaMatrix &inMat, albaMatrix &outMat) {Adjoint(*(inMat.GetElements()),*(outMat.GetElements()));outMat.Modified();};
145 void Adjoint() {Adjoint(*GetElements(),*GetElements());Modified();}
146
148 static void Transpose(const albaMatrix &in, albaMatrix &out)
151 void Transpose() { albaMatrix::Transpose(*this,*this); }
153 static void Transpose(const double inElements[16], double outElements[16]);
154
158 void MultiplyPoint(const double in[4], double out[4]) const
159 {albaMatrix::MultiplyPoint(*GetElements(),in,out); }
160
164
165
169 static void MultiplyPoint(const double Elements[16],
170 const double in[4], double out[4]);
171
173 static void Multiply4x4(const albaMatrix &a, const albaMatrix &b, albaMatrix &c) {
176 static void Multiply4x4(const double a[16], const double b[16],
177 double c[16]);
178
180 double *operator[](const unsigned int i) {return &(GetElements()[i][0]);Modified();}
181
183 const double *operator[](unsigned int i) const { return &(GetElements()[i][0]); }
184
186 operator vtkMatrix4x4*() const {
187 return GetVTKMatrix();
188 }
189
190 //double *operator[][](const unsigned int i,const unsigned int j) {return &(GetElements()[i][j]);}
191
195 static void PointMultiply(const double Elements[16],
196 const float in[4], float out[4]);
200 static void PointMultiply(const double Elements[16],
201 const double in[4], double out[4]);
202
203 void SetFromDirectionCosines(const double orientation[6]);
204protected:
206
207#ifdef ALBA_USE_VTK
208 vtkMatrix4x4 *m_VTKMatrix;
209#else
210 double m_Elements[4][4];
212#endif
213
214};
215
216#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:57
double(* albaMatrixElements)[4]
Definition: albaMatrix.h:23
bool operator==(const albaAutoPointer< T > &l, const albaAutoPointer< T > &r)
albaMTime - record modification timestamp.
Definition: albaMTime.h:38
albaMatrix - Time stamped 4x4 Matrix.
Definition: albaMatrix.h:44
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:114
void Adjoint(const albaMatrix &inMat, albaMatrix &outMat)
Definition: albaMatrix.h:144
unsigned long GetMTime() const
return modification time for this object
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])
void CopyRotation(const albaMatrix &source)
Copy the 3x3 rotation matrix from another 4x4 matrix.
Definition: albaMatrix.h:109
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:119
double GetElement(const int i, const int j) const
Returns the element i,j from the matrix.
Definition: albaMatrix.h:91
void Transpose()
Transpose the matrix and put it into out.
Definition: albaMatrix.h:151
static void Zero(double elements[16])
Set all of the elements to zero.
albaTimeStamp m_TimeStamp
Definition: albaMatrix.h:205
void DeepCopy(const albaMatrix *mat)
Definition: albaMatrix.h:60
albaMatrix * Invert()
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: albaMatrix.h:132
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:100
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:183
double Determinant() const
Definition: albaMatrix.h:140
static void Invert(const albaMatrix &in, albaMatrix &out)
Matrix Inversion (adapted from Richard Carling in "Graphics Gems," Academic Press,...
Definition: albaMatrix.h:128
albaMTime m_MTime
Definition: albaMatrix.h:211
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:173
albaTimeStamp GetTimeStamp() const
Definition: albaMatrix.h:101
void Adjoint()
Definition: albaMatrix.h:145
void MultiplyPoint(const double in[4], double out[4]) const
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: albaMatrix.h:158
static void Transpose(const albaMatrix &in, albaMatrix &out)
Transpose the matrix and put it into out.
Definition: albaMatrix.h:148
albaMatrix(const albaMatrix &mat)
void GetVersor(const int axis, double versor[3]) const
Get the given matrix versor.
Definition: albaMatrix.h:106
void SetElement(const int i, const int j, double value)
Sets the element i,j in the matrix.
Definition: albaMatrix.h:88
double * operator[](const unsigned int i)
bracket operator to access & write single elements
Definition: albaMatrix.h:180
albaTypeMacro(albaMatrix, albaReferenceCounted)
albaReferenceCounted - abstract base class for ALBA objects with reference counting.
Class Name: albaVect3d.
Definition: albaVect3d.h:35