ALBA
albaTransform.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaTransform
5 Authors: Marco Petrone, Stefano Perticoni,Stefania Paperini
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 __albaTransform_h
18#define __albaTransform_h
19
20#include "albaTransformBase.h"
22
23#include "albaUtility.h"
24
25//------------------------------------------------------------------------------
26// Forward declarations
27//------------------------------------------------------------------------------
28class vtkMatrix4x4;
29
30//----------------------------------------------------------------------------
31// Constants:
32//----------------------------------------------------------------------------
34{
36 PRE_MULTIPLY
37};
38//#define ALBA_FLT_MAX 3.40282346638528860e38F
39
52class ALBA_EXPORT albaTransform : public albaTransformBase
53{
54 public:
55 //------------------------------------------------------------------------------
56 // Events
57 //------------------------------------------------------------------------------
58 //ALBA_ID_DEC(UpdateEvent); // Event rised by updates of the internal matrix
59
62
63 //----------------------------------------------------------------------------
64 // Ref Sys Type:
65 //----------------------------------------------------------------------------
66 enum
67 {
68 CUSTOM = 0,
72 VIEW
73 };
74
77
80
84 virtual void SetMatrix(const albaMatrix &input) {*m_Matrix=input;SetTimeStamp(input.GetTimeStamp());Modified();}
85
88
91 static double PolarDecomp(const albaMatrix &M, albaMatrix &Q, albaMatrix &S, double translation[3]);
92 double PolarDecomp(albaMatrix &Q, albaMatrix &S, double translation[3]) {return PolarDecomp(GetMatrix(),Q,S,translation);}
93
95 void Identity();
96
98 void Invert();
99
103 static void GetOrientation(const albaMatrix &in_matrix,double orientation[3]);
104 static void GetOrientation(const albaMatrix &in_matrix,float orientation[3]);
105 void GetOrientation(double orientation[3]) { this->GetOrientation(GetMatrix(),orientation);}
106 void GetOrientation(float orient[3]) {
107 double temp[3]; this->GetOrientation(temp);
108 orient[0] = static_cast<float>(temp[0]);
109 orient[1] = static_cast<float>(temp[1]);
110 orient[2] = static_cast<float>(temp[2]); };
111
115 static void GetOrientationWXYZ(const albaMatrix &in_matrix, double wxyz[4]);
116 void GetOrientationWXYZ(double wxyz[4]) \
117 { GetOrientationWXYZ(GetMatrix(),wxyz);}
118 void GetOrientationWXYZ(float wxyz[3]) {
119 double temp[4]; GetOrientationWXYZ(temp);
120 wxyz[0]=static_cast<float>(temp[0]);
121 wxyz[1]=static_cast<float>(temp[1]);
122 wxyz[2]=static_cast<float>(temp[2]);
123 wxyz[3]=static_cast<float>(temp[3]);};
124
129 static void GetPosition(const albaMatrix &matrix,double position[3]);
130 static void GetPosition(const albaMatrix &matrix,float position[3]);
131 void GetPosition(double position[3]) {this->GetPosition(GetMatrix(),position);}
132 void GetPosition(float position[3]) {
133 double temp[3]; this->GetPosition(temp);
134 position[0] = static_cast<float>(temp[0]);
135 position[1] = static_cast<float>(temp[1]);
136 position[2] = static_cast<float>(temp[2]); };
137
142 static void SetPosition(albaMatrix &matrix,double position[3]);
143 void SetPosition(double position[3]) {this->SetPosition(*m_Matrix,position);}
144 void SetPosition(double x,double y,double z) {this->SetPosition(*m_Matrix,x,y,z);}
145 static void SetPosition(albaMatrix &matrix, double x,double y,double z) {
146 double temp[3];
147 temp[0]=x;temp[1]=y;temp[2]=z;
148 SetPosition(matrix,temp);}
149
155 static void Translate(albaMatrix &matrix,double translation[3],int premultiply);
156 void Translate(double translation[3],int premultiply) {this->Translate(*m_Matrix,translation,premultiply);}
157 void Translate(double x,double y,double z,int premultiply) {this->Translate(*m_Matrix,x,y,z,premultiply);}
158 static void Translate(albaMatrix &matrix, double x,double y,double z,int premultiply) {
159 double temp[3];
160 temp[0]=x;temp[1]=y;temp[2]=z;
161 Translate(matrix,temp,premultiply);}
162
167 static void RotateWXYZ(const albaMatrix &source,albaMatrix &target,double angle,double x, double y, double z,int premultiply);
168 void RotateWXYZ(double angle,double x, double y, double z,int premultiply) {this->RotateWXYZ(*m_Matrix,*m_Matrix,angle,x,y,z,premultiply);}
169 void RotateWXYZ(double angle,double rot[3],int premultiply) {this->RotateWXYZ(*m_Matrix,*m_Matrix,angle, rot[0], rot[1], rot[2],premultiply);}
170
171
176 static void RotateX(albaMatrix &matrix,double angle,int premultiply) { albaTransform::RotateWXYZ(matrix,matrix,angle, 1, 0, 0,premultiply); };
177 static void RotateY(albaMatrix &matrix,double angle,int premultiply) { albaTransform::RotateWXYZ(matrix,matrix,angle, 0, 1, 0,premultiply); };
178 static void RotateZ(albaMatrix &matrix,double angle,int premultiply) { albaTransform::RotateWXYZ(matrix,matrix,angle, 0, 0, 1,premultiply); };
179 void RotateX(double angle,int premultiply) { this->RotateX(*m_Matrix,angle,premultiply); };
180 void RotateY(double angle,int premultiply) { this->RotateY(*m_Matrix,angle,premultiply); };
181 void RotateZ(double angle,int premultiply) { this->RotateZ(*m_Matrix,angle,premultiply); };
182
184 void Concatenate(const albaMatrix &matrix, int premultiply);
185
187 void Concatenate(albaTransformBase *trans, int premultiply) {Concatenate(trans->GetMatrix(),premultiply);}
188
193 static void SetOrientation(albaMatrix &matrix,double orientation[3]);
194 void SetOrientation(double orientation[3]) {this->SetOrientation(*m_Matrix,orientation);}
195 void SetOrientation(double rx,double ry,double rz) {this->SetOrientation(*m_Matrix,rx,ry,rz);}
196 static void SetOrientation(albaMatrix &matrix,double rx,double ry,double rz) {
197 double temp[3];
198 temp[0]=rx;temp[1]=ry;temp[2]=rz;
199 SetOrientation(matrix,temp);}
200
206 static void GetScale(const albaMatrix &matrix,double scale[3]);
207 void GetScale(double scale[3]) {this->GetScale(*m_Matrix,scale);}
208 void GetScale(float scale[3]) {
209 double temp[3]; this->GetScale(temp);
210 scale[0] = static_cast<float>(temp[0]);
211 scale[1] = static_cast<float>(temp[1]);
212 scale[2] = static_cast<float>(temp[2]); };
213
215 static void Scale(albaMatrix &matrix,double scalex,double scaley,double scalez,int premultiply);
216 void Scale(double scalex,double scaley,double scalez,int premultiply) \
217 { Scale(*m_Matrix,scalex,scaley,scalez,premultiply);}
218
220 static void SetVersor(int axis, double versor[3], albaMatrix &matrix);
221
222 static void GetVersor(int axis, const albaMatrix &matrix, double versor[3]) {albaMatrix::GetVersor(axis,matrix,versor);}
223 static void GetVersor(int axis, const albaMatrix &matrix, float versor[3]) \
224 { \
225 double temp[3]; GetVersor(axis, matrix, temp); \
226 versor[0] = static_cast<float>(temp[0]); \
227 versor[1] = static_cast<float>(temp[1]); \
228 versor[2] = static_cast<float>(temp[2]); };
229
230 void GetVersor(int axis, double versor[3]) {GetVersor(axis,GetMatrix(),versor);}
231 void GetVersor(int axis, float versor[3]) {GetVersor(axis,GetMatrix(),versor);}
232
235 static void CopyRotation(const albaMatrix &source, albaMatrix &target);
236 void CopyRotation(const albaMatrix &source) {this->CopyRotation(source,*m_Matrix);}
237
239 static void CopyTranslation(const albaMatrix &source, albaMatrix &target);
240 void CopyTranslation(const albaMatrix &source) {this->CopyTranslation(source,*m_Matrix);}
241
243 static void AddVectors( double inV0[3],double inV1[3],double outSum[3] );
244
246 static void BuildVector(double *p1, double *p2, double *out_vector);
247
249 static void BuildVector(double coeff, const double *inVector, double *outVector, int refSysType = LOCAL, int localAxis = albaInteractorConstraint::X);
250
253 static double ProjectVectorOnAxis(const double *in_vector, const double *in_axis, double *out_projection = NULL);
254
258 static double ProjectVectorOnPlane(const double *in_vector, const double *in_plane_normal, double *out_projection = NULL);
259
261 static void FindPerpendicularVersors(double inVersorN[3], double outVersorP[3], double outVersorQ[3]);
262
264 static void MultiplyVectorByScalar(double s, double *vin, double *vout);
265
268 double attitude_vector[3]);
269
272 int i,int j,int k,
273 double euler_cardan[3],
274 double tentative_euler_cardan_first,
275 double tentative_euler_cardan_second,
276 double tentative_euler_cardan_third);
277
279 int MatrixTommuQuaternion(const albaMatrix &matrix, double quaternion[4]);
280
282 int QuaternionToMatrix(double quaternion[4], albaMatrix &matrix);
283
285 int HelicalAxisToMatrix(double helical_axis[3],double angle, albaMatrix &matrix);
286
288 int AttitudeVectorToMatrix(double attitude_vector[3], albaMatrix &matrix);
289
291 int EulerCardanicAngleToMatrix(double euler_cardan[3],
292 int i,int j,int k,
293 albaMatrix &matrix);
294
297 double helical_axis[3],double point[3],
298 double& phi,double& t, int intersect);
299
300
301 //----------------------------------------------------------------------------
302 // declarations for polar_decomp algorithm from Graphics Gems IV,
303 // by Ken Shoemake <shoemake@graphics.cis.upenn.edu>
304 //----------------------------------------------------------------------------
305 enum mmuQuatPart {X, Y, Z, W};
306
307 typedef struct {double x, y, z, w;} mmuQuat;
308 typedef mmuQuat HVect;
309
310 typedef struct {
315 double f;
317
318 typedef double HMatrix[4][4]; /* Right-handed, for column vectors */
319 static double PolarDecomp(HMatrix M, HMatrix Q, HMatrix S);
320 static void DecompAffine(HMatrix A, mmuAffineParts *parts);
321 static HVect SpectDecomp(HMatrix S, HMatrix U);
322 static mmuQuat QuaternionFromMatrix(HMatrix mat);
323 static void InvertAffine(mmuAffineParts *parts, mmuAffineParts *inverse);
325 //----------------------------------------------------------------------------
326protected:
330 virtual void InternalUpdate() {m_Matrix->SetTimeStamp(m_TimeStamp);}
331private:
332};
333
334#endif
335
POST_MULTIPLY
Definition: albaTransform.h:35
enum ALBA_EXPORT MATRIX_MULTIPLICATION_ID
Definition: albaTransform.h:34
albaMatrix - Time stamped 4x4 Matrix.
Definition: albaMatrix.h:44
static void GetVersor(const int axis, const albaMatrix &matrix, double versor[3])
Get the given matrix versor.
albaTimeStamp GetTimeStamp() const
Definition: albaMatrix.h:101
Superclass for Homogeneous transformations.
void SetTimeStamp(albaTimeStamp t)
set the timestamp for the output matrix
virtual const albaMatrix & GetMatrix()
update and return internal transform matrix
void Modified()
update modification time stamp for this object
albaTransform - class for homogeneous transformations.
Definition: albaTransform.h:53
static void GetOrientationWXYZ(const albaMatrix &in_matrix, double wxyz[4])
Return the wxyz angle+axis representing the current orientation.
static void Translate(albaMatrix &matrix, double x, double y, double z, int premultiply)
static mmuQuat QuaternionFromMatrix(HMatrix mat)
void GetOrientation(double orientation[3])
static void GetPosition(const albaMatrix &matrix, float position[3])
void SetMatrixPointer(albaMatrix *matrix)
set the internal matrix pointer to the given matrix.
int MatrixToHelicalAxis(const albaMatrix &matrix, double helical_axis[3], double point[3], double &phi, double &t, int intersect)
rotation + translation representation conversion
void GetOrientation(float orient[3])
static void FindPerpendicularVersors(double inVersorN[3], double outVersorP[3], double outVersorQ[3])
Find perpendicular versors to input versor N.
void GetVersor(int axis, float versor[3])
@ LOCAL
the local ref sys of the VME
Definition: albaTransform.h:71
albaTransform(const albaTransform &)
copy constructor
void SetPosition(double x, double y, double z)
static double ProjectVectorOnPlane(const double *in_vector, const double *in_plane_normal, double *out_projection=NULL)
Project in_vector on the plane identified by the normal vector in_plane_normal; in_plane_normal does ...
static void GetOrientation(const albaMatrix &in_matrix, float orientation[3])
void GetScale(double scale[3])
static void SetVersor(int axis, double versor[3], albaMatrix &matrix)
Set/Get internal matrix versor.
int HelicalAxisToMatrix(double helical_axis[3], double angle, albaMatrix &matrix)
rotation + translation representation conversion
void Identity()
set internal matrix to Identity
static void GetOrientation(const albaMatrix &in_matrix, double orientation[3])
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
void GetPosition(float position[3])
int QuaternionToMatrix(double quaternion[4], albaMatrix &matrix)
rotation representation conversion
static void RotateY(albaMatrix &matrix, double angle, int premultiply)
static void GetVersor(int axis, const albaMatrix &matrix, double versor[3])
static void GetVersor(int axis, const albaMatrix &matrix, float versor[3])
virtual void SetMatrix(const albaMatrix &input)
Directly set the internal Matrix.
Definition: albaTransform.h:84
static void DecompAffine(HMatrix A, mmuAffineParts *parts)
static void SetPosition(albaMatrix &matrix, double x, double y, double z)
static void InvertAffine(mmuAffineParts *parts, mmuAffineParts *inverse)
static mmuQuat Snuggle(mmuQuat q, HVect *k)
static void GetScale(const albaMatrix &matrix, double scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
static void MultiplyVectorByScalar(double s, double *vin, double *vout)
Multiply vector by scalar.
static void RotateX(albaMatrix &matrix, double angle, int premultiply)
This functions rotate the internal matrix around the specified axis.
static void BuildVector(double *p1, double *p2, double *out_vector)
Build vector with origin in p1 pointing to p2.
static HVect SpectDecomp(HMatrix S, HMatrix U)
void RotateX(double angle, int premultiply)
mmuQuat HVect
Homogeneous 3D vector.
void Translate(double translation[3], int premultiply)
void GetScale(float scale[3])
double PolarDecomp(albaMatrix &Q, albaMatrix &S, double translation[3])
Definition: albaTransform.h:92
void Scale(double scalex, double scaley, double scalez, int premultiply)
int MatrixTommuQuaternion(const albaMatrix &matrix, double quaternion[4])
rotation representation conversion
static void SetPosition(albaMatrix &matrix, double position[3])
This function set the position column of the matrix.
virtual void InternalUpdate()
This only sets the timestamp for the output matrix: output matrix is not computed inside InternalUpda...
void Invert()
Invert internal matrix.
void RotateWXYZ(double angle, double rot[3], int premultiply)
int AttitudeVectorToMatrix(double attitude_vector[3], albaMatrix &matrix)
rotation representation conversion
static double PolarDecomp(HMatrix M, HMatrix Q, HMatrix S)
static void AddVectors(double inV0[3], double inV1[3], double outSum[3])
Add two vectors.
void GetPosition(double position[3])
void Concatenate(const albaMatrix &matrix, int premultiply)
Pre or Post multiply the internal matrix for given matrix and store result in the internal matrix.
static void BuildVector(double coeff, const double *inVector, double *outVector, int refSysType=LOCAL, int localAxis=albaInteractorConstraint::X)
Build vector [coeff * inVector].
void RotateWXYZ(double angle, double x, double y, double z, int premultiply)
void RotateY(double angle, int premultiply)
void GetVersor(int axis, double versor[3])
void RotateZ(double angle, int premultiply)
static void SetOrientation(albaMatrix &matrix, double rx, double ry, double rz)
static void RotateZ(albaMatrix &matrix, double angle, int premultiply)
void CopyTranslation(const albaMatrix &source)
static double PolarDecomp(const albaMatrix &M, albaMatrix &Q, albaMatrix &S, double translation[3])
Polar Decomposition of matrix M in Q * S.
void SetOrientation(double rx, double ry, double rz)
void GetOrientationWXYZ(double wxyz[4])
void SetPosition(double position[3])
void CopyRotation(const albaMatrix &source)
void GetOrientationWXYZ(float wxyz[3])
void SetOrientation(double orientation[3])
static double ProjectVectorOnAxis(const double *in_vector, const double *in_axis, double *out_projection=NULL)
Project in_vector on in_axis direction; in_axis does not need to be normalised.
static void CopyTranslation(const albaMatrix &source, albaMatrix &target)
Copy the translation vector.
static void GetPosition(const albaMatrix &matrix, double position[3])
Return the position from the current transformation matrix as an array of three floating point number...
void Concatenate(albaTransformBase *trans, int premultiply)
Pre or Post multiply the internal matrix for given transform and store result in the internal matrix.
void Translate(double x, double y, double z, int premultiply)
static void CopyRotation(const albaMatrix &source, albaMatrix &target)
Copy the 3x3 rotation matrix from another 4x4 matrix into the specified matrix, or in the internal ma...
static void SetOrientation(albaMatrix &matrix, double orientation[3])
This function set the orientation (acc.
int MatrixToEulerCardanicAngle(const albaMatrix &matrix, int i, int j, int k, double euler_cardan[3], double tentative_euler_cardan_first, double tentative_euler_cardan_second, double tentative_euler_cardan_third)
rotation representation conversion
static void Translate(albaMatrix &matrix, double translation[3], int premultiply)
This function set the translation column of the matrix by adding the transaltion provided as argument...
int EulerCardanicAngleToMatrix(double euler_cardan[3], int i, int j, int k, albaMatrix &matrix)
rotation representation conversion
albaTypeMacro(albaTransform, albaTransformBase)
RTTI stuff.
static void Scale(albaMatrix &matrix, double scalex, double scaley, double scalez, int premultiply)
Apply a scale transform.
int MatrixToAttitudeVector(const albaMatrix &matrix, double attitude_vector[3])
rotation representation conversion
static void RotateWXYZ(const albaMatrix &source, albaMatrix &target, double angle, double x, double y, double z, int premultiply)
This function rotate the matrix around the specified axis.
mmuQuat q
Essential rotation.
HVect t
Translation components.
mmuQuat u
Stretch rotation.
double f
Sign of determinant.
HVect k
Stretch factors.