div class="twikiTopBar">

Chair for Computer Aided Medical Procedures & Augmented Reality
Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

dwarfutil.h File Reference

Go to the source code of this file.


Namespaces

namespace  DWARF
namespace  DWARF::Util

Functions

Time currentTime ()
 Get the current system time as a DWARF::Time struct.
Time getTimeToNow (Time &compareTime)
 Get the difference to the current time.
double q_x (double *q)
 Convenience method for accessing a quaternion's X component.
double q_y (double *q)
 Convenience method for accessing a quaternion's y component.
double q_z (double *q)
 Convenience method for accessing a quaternion's z component.
double q_w (double *q)
 Convenience method for accessing a quaternion's scalar component.
double * quaternionToMatrix (const double *quat, double *matrix)
 Construct rotation matrix from unit quaternion.
double * matrixToQuaternion (const double *matrix, double *quat)
 Construct a unit quaternion from a rotation matrix.
double * axisAngleToQuaternion (double *axisAngle, double *quat)
 Converts axis/angle representation (as used in VRML) to a unit quaternion.
double * quaternionToAxisAngle (double *quat, double *axisAngle)
 Converts a unit quaternion to axis/angle representation (as used in VRML).
double * invertQuaternion (double *quat)
 Inverts a quaternion.
double * conjugateQuaternion (double *quat)
 Conjugates a quaternion (i.e. negates its vector part).
double * normalizeQuaternion (double *quat)
 Normalizes a quaternion (i.e. makes a unit quaternion).
double * normalizeVector (double *vec, int length)
 Normalizes a vector.
double * multiplyQuaternion (double *quat, const double *quat1, const double *quat2)
double * rotateQuaternion (double *rotPoint, const double *quat, const double *point)
 Rotates a 3-dim point by a unit quaternion.
void transformCoordinateFrame (const double *transRot, const double *transPos, double *rot, double *pos)
 Transforms the coordinate reference frame of a 6D pose.
double * rotateMatrix (double *rotPoint, const double *matrix, const double *point)
 Rotates a 3-dim point by a orthonormal rotation matrix.
double * invertMatrix (double *matrix, int col, int row)
 (self) inverts a matrix
double * crossProduct3D (double *p, double *a, double *b)
 Compute cross product p = a x b of two 3D-vectors.
double scalarProduct3D (double *a, double *b)
 Compute scalar product p = a . b of two 3D-vectors.
double angleBetweenVectors3D (double *a, double *b)
 calculates the angle between two 3D-vectors
void poseRightInverse (double *newQuat, double *newTrans, const double *oldQuat, const double *oldTrans)
 Inverts a pose transformation.
void poseLeftInverse (double *newQuat, double *newTrans, const double *oldQuat, const double *oldTrans)
 Inverts a pose transformation.
double * colMatrixToEuler (double *colMatrix, double *angles)
 Contructs Euler rotation representation out of matrix.
double * eulerToQuaternion (double *angles, double *quat)
 Constructs quaternion from Euler representation.
double * quaternionSlerp (double *quat, const double *quat1, const double *quat2, double h)
 Interpolates quaternions using the SLERP algorithm.
double * quaternionNegateIfCloser (double *quat, const double *otherquat)
 Negates a quaternion if the result is closer to a given reference.
double * negateQuaternion (double *quat)
 Negates a quaternion.

Variables

const unsigned char QX = 0
 Use only this constant for accessing a quaternion's X component.
const unsigned char QY = 1
 Use only this constant for accessing a quaternion's Y component.
const unsigned char QZ = 2
 Use only this constant for accessing a quaternion's Z component.
const unsigned char QW = 3
 Use only this constant for accessing a quaternion's scalar component.

Detailed Description

Utility classes and functions to simplify working with the DWARF framework under C++. Mainly conversion routines between different representations of rotations (axis/angle, quaternions, rotation matrices, euler angles)

Author:
Martin Wagner

Definition in file dwarfutil.h.


Function Documentation

double angleBetweenVectors3D double *  a,
double *  b
 

calculates the angle between two 3D-vectors

Parameters:
a 3-dim vector a
b 3-dim vector b
Returns:
the angle

double* axisAngleToQuaternion double *  axisAngle,
double *  quat
 

Converts axis/angle representation (as used in VRML) to a unit quaternion.

Parameters:
axisAngle 4-dim double axis/angle rotation (x,y,z,alpha) as input
quat 4-dim unit quaternion as return value
Returns:
a pointer to quat

double* colMatrixToEuler double *  colMatrix,
double *  angles
 

Contructs Euler rotation representation out of matrix.

This code was partially taken from OpenTracker, TU Vienna http://studierstube.org/opentracker/ originally, it seems to be from Gary Bishop

FIXME: This code is supposed to take a column matrix. Ask Gerhard Reitmayr whether that is the same as the representation below or not. Adjust comment if necessary. DO NOT change the code in here, it is for the ARTkPoseReconstruction service.

Parameters:
colMatrix: 4x4-dim double homogeneous matrix (row x column) as input, organized as follows
( 0 1 2 3 )
( 4 5 6 7 )
( 8 9 10 11 )
(12 13 14 15 )
angles 3-dim angles (roll, pitch, yaw) as return value
Returns:
pointer to angles

double* conjugateQuaternion double *  quat  ) 
 

Conjugates a quaternion (i.e. negates its vector part).

Note: Conjugating a unit quaternion results in its inverse.

Parameters:
quat 4-dim quaternion as input and return value
Returns:
a pointer to quat

double* crossProduct3D double *  p,
double *  a,
double *  b
 

Compute cross product p = a x b of two 3D-vectors.

Parameters:
p 3-dim pointer to return value memory
p 3-dim vector a
p 3-dim vector b
Returns:
a pointer to p = a x b

Time currentTime  ) 
 

Get the current system time as a DWARF::Time struct.

Returns:
: the current system time

double* eulerToQuaternion double *  angles,
double *  quat
 

Constructs quaternion from Euler representation.

This code was partially taken from OpenTracker, TU Vienna http://studierstube.org/opentracker/

Parameters:
angles 3-dim angles (roll, pitch, yaw)
quat 4-dim normalized quaternion as return value
Returns:
pointer to quat

Time getTimeToNow Time &  compareTime  ) 
 

Get the difference to the current time.

Parameters:
compareTime the time to be be compared

double* invertMatrix double *  matrix,
int  col,
int  row
 

(self) inverts a matrix

Calculates matrix = matrix^-1

Parameters:
matrix the matix that should be inverted
col count of the colums in the matix
row count of the rows in the matix
Returns:
a pointer to the inverted matix

double* invertQuaternion double *  quat  ) 
 

Inverts a quaternion.

The resulting quaternion is the inverse of the given quaternion. This corresponds to translating an orthonormal rotation matrix. Note: To invert a unit quaternion, conjugating it suffices.

Parameters:
quat 4-dim quaternion as input and return value
Returns:
a pointer to quat

double* matrixToQuaternion const double *  matrix,
double *  quat
 

Construct a unit quaternion from a rotation matrix.

Assumes matrix is used to multiply column vector on the left: vnew = mat vold. Works correctly for right-handed coordinate system and right-handed rotations. Translation components are ignored. Matrix is assumed to be orthonormal.

Parameters:
matrix 4x4-dim double homogeneous matrix as input, organized as follows (row major)
NOTE: OpenGL has another order, column major!
( 0 1 2 3 )
( 4 5 6 7 )
( 8 9 10 11 )
(12 13 14 15 )
quat 4-dim normalized quaternion as return value
Returns:
pointer to quat

double* multiplyQuaternion double *  quat,
const double *  quat1,
const double *  quat2
 

multiplyQuaternion Calculates quat := quat1 * quat2

Parameters:
quat 4-dim Quaternion as return value
quat1 4-dim Quaternion as input
quat2 4-dim Quaternion as input
Returns:
a pointer to quat

double* negateQuaternion double *  quat  ) 
 

Negates a quaternion.

Sets x = -x; y=-y; z=-z; w=-w The resulting quaternion still represents the same rotation.

Parameters:
quat Quaternion to be negated
Returns:
pointer to quat

double* normalizeQuaternion double *  quat  ) 
 

Normalizes a quaternion (i.e. makes a unit quaternion).

Parameters:
quat 4-dim quaternion as input and return value
Returns:
a pointer to quat

double* normalizeVector double *  vec,
int  length
 

Normalizes a vector.

Parameters:
vec n-dim vector as input and return value
length dimension of vector
Returns:
a pointer to vec

void poseLeftInverse double *  newQuat,
double *  newTrans,
const double *  oldQuat,
const double *  oldTrans
 

Inverts a pose transformation.

Identical to inverting a homogeneous 4x4 matrix, computes rot_new = rot_old^-1; t_new = - rot_old * t_old

This function computes the left inverse, i.e. H^-1 such that H^-1 * H = I

Parameters:
newQuat 4-dim unit quaternion, new rotation (return value)
newTrans 3-dim pont, new translation (return value)
oldQuat 4-dim unit quaternion, old rotation
oldTrans 3-dim point, old translation

void poseRightInverse double *  newQuat,
double *  newTrans,
const double *  oldQuat,
const double *  oldTrans
 

Inverts a pose transformation.

Identical to inverting a homogeneous 4x4 matrix, computes rot_new = rot_old^-1; t_new = - rot_old^-1 * t_old

This function computes the right inverse, i.e. H^-1 such that H* H^-1 = I

Parameters:
newQuat 4-dim unit quaternion, new rotation (return value)
newTrans 3-dim pont, new translation (return value)
oldQuat 4-dim unit quaternion, old rotation
oldTrans 3-dim point, old translation

double* quaternionNegateIfCloser double *  quat,
const double *  otherquat
 

Negates a quaternion if the result is closer to a given reference.

Every rotation can be represented by two different quaternions, which can cause great trouble when analyzing rotation sequences. One can switch between the two representation by negating all four quaternion entries. This routine negates the quaternion if the result is closer to a given reference quaternion, e.g. a preceding quaternion in a sequence.

Parameters:
quat Quaternion to be negated
otherquat Reference quaternion
Returns:
pointer to quat

double* quaternionSlerp double *  quat,
const double *  quat1,
const double *  quat2,
double  h
 

Interpolates quaternions using the SLERP algorithm.

Parameters:
quat destination quaternion
quat1 first source quaternion
quat2 second source quaternion
h interpolation factor. 0.0=quat1, 1.0=quat2. May exceed [0,1] for extrapolation.
Returns:
pointer to quat

double* quaternionToAxisAngle double *  quat,
double *  axisAngle
 

Converts a unit quaternion to axis/angle representation (as used in VRML).

Parameters:
quat 4-dim unit quaternion as input
axisAngle 4-dim double axis/angle rotation (x,y,z,alpha) as return value
Returns:
a pointer to axisAngle

double* quaternionToMatrix const double *  quat,
double *  matrix
 

Construct rotation matrix from unit quaternion.

Assumes matrix is used to multiply column vector on the left: vnew = mat vold. Works correctly for right-handed coordinate system and right-handed rotations.

Parameters:
quat 4-dim unit quaternion as input
matrix 4x4-dim double homogeneous rotation matrix as return value, organized as follows (row major)
NOTE: OpenGL has another order, column major!
( 0 1 2 3 )
( 4 5 6 7 )
( 8 9 10 11 )
(12 13 14 15 )
Returns:
pointer to matrix

double* rotateMatrix double *  rotPoint,
const double *  matrix,
const double *  point
 

Rotates a 3-dim point by a orthonormal rotation matrix.

Calculates rotPoint = matrix * (point,1)

Parameters:
quat 3x4-dim row major orthonormal matrix representing the rotation, will not be changed
point 3-dim point to be rotated as input
rotPoint memory for return value (at least 3*double)
Returns:
a pointer to rotPoint

double* rotateQuaternion double *  rotPoint,
const double *  quat,
const double *  point
 

Rotates a 3-dim point by a unit quaternion.

Calculates rotPoint = quat * (point,0) * quat^-1

Parameters:
quat 4-dim unit quaternion representing the rotation
point 3-dim point to be rotated as input
rotPoint memory for return value (at least 3*double)
Returns:
a pointer to rotPoint

double scalarProduct3D double *  a,
double *  b
 

Compute scalar product p = a . b of two 3D-vectors.

Parameters:
a 3-dim vector a
b 3-dim vector b
Returns:
the scalar value p = a . b

void transformCoordinateFrame const double *  transRot,
const double *  transPos,
double *  rot,
double *  pos
 

Transforms the coordinate reference frame of a 6D pose.

Use this method to transform the reference frame of a 6DOF pose. If given the transformation pose P' and an input pose P, it computes P'^-1 * P * P'

Parameters:
transRot rotational part of transformation P', 4-double unit quaternion
transPos positional part of transformation P', 3-double position
rot rotational part of input pose P, is modified, 4-double unit quaternion
pos positional part of input pose P, is modified, 3-double position

dwarfutil.h File Reference | generated on Sun Apr 29 02:01:07 2007 by Doxygen 1.4.1 for DWARF