Namespaces | Classes | Typedefs | Functions

OpenTissue::math Namespace Reference

Namespaces

namespace  big
namespace  detail
namespace  interval
namespace  optimization
namespace  polar_decomposition

Classes

class  BasicMathTypes
class  CoordSys
class  Matrix3x3
class  Quaternion
class  Random
class  Rotation
class  ValueTraits
class  Vector3

Typedefs

typedef BasicMathTypes< double,
unsigned int > 
default_math_types

Functions

template<typename iterator_type >
void compute_contiguous_angle_interval (iterator_type const &begin, iterator_type const &end, typename iterator_type::value_type &theta_min, typename iterator_type::value_type &theta_max)
template<typename T >
CoordSys< T > prod (CoordSys< T > const &L, CoordSys< T > const &R)
template<typename T >
CoordSys< T > inverse (CoordSys< T > const &X)
template<typename T >
CoordSys< T > model_update (CoordSys< T > const &A, CoordSys< T > const &B)
template<typename T >
CoordSys< T > model_update (Vector3< T > const &TA, Quaternion< T > const &QA, Vector3< T > const &TB, Quaternion< T > const &QB)
template<typename T >
std::ostream & operator<< (std::ostream &o, CoordSys< T > const &C)
template<typename T >
std::istream & operator>> (std::istream &i, CoordSys< T > &C)
template<typename vector3_iterator , typename vector3_type , typename matrix3x3_type >
void covariance (vector3_iterator begin, vector3_iterator end, vector3_type &mean, matrix3x3_type &C)
template<typename vector3_type , typename matrix3x3_type >
void covariance_union (vector3_type const &mean1, matrix3x3_type const &C1, vector3_type const &mean2, matrix3x3_type const &C2, vector3_type &mean, matrix3x3_type &C)
template<typename matrix3x3_type , typename vector3_type >
void eigen (matrix3x3_type const &A, matrix3x3_type &V, vector3_type &diag)
template<typename matrix3x3_type , typename real_type >
bool euler_angles (matrix3x3_type const &R, real_type &rx, real_type &ry, real_type &rz)
template<typename T >
void ZYZ_euler_angles (OpenTissue::math::Quaternion< T > const &Q, T &phi, T &psi, T &theta)
template<typename T >
clamp (T const &value, T const &min_value, T const &max_value)
template<typename T >
clamp_min (T const &value, T const &min_value)
template<typename T >
clamp_max (T const &value, T const &max_value)
template<typename T >
clamp_zero_one (T const &value)
template<typename T >
fac (unsigned long n)
template<typename T >
sgn (T const &val)
template<typename T >
sinc (T &x)
template<typename T >
to_degrees (T const &radians)
template<typename T >
to_radians (T const &degrees)
template<typename real_type >
void invert4x4 (real_type M[4][4])
template<typename vector_iterator , typename vector_container , typename index_container >
void kmeans (vector_iterator const &begin, vector_iterator const &end, vector_container &centers, index_container &membership, size_t K, size_t &iteration, size_t const &max_iterations)
template<typename T >
void random (Matrix3x3< T > &m)
template<typename T >
Matrix3x3< T > operator* (Matrix3x3< T > const &m, T const &s)
template<typename T >
Matrix3x3< T > operator* (T const &s, Matrix3x3< T > const &m)
template<typename T >
Matrix3x3< T > operator/ (Matrix3x3< T > const &m, T const &s)
template<typename T >
Matrix3x3< T > operator/ (T const &s, Matrix3x3< T > const &m)
template<typename T >
Matrix3x3< T > operator* (Matrix3x3< T > const &A, Matrix3x3< T > const &B)
template<typename T >
Matrix3x3< T > Rx (T const &radians)
template<typename T >
Matrix3x3< T > Ry (T const &radians)
template<typename T >
Matrix3x3< T > Rz (T const &radians)
template<typename T >
Matrix3x3< T > Ru (T const &radians, Vector3< T > const &axis)
template<typename T >
Matrix3x3< T > z_dof (Vector3< T > const &k)
template<typename T >
bool is_orthonormal (Matrix3x3< T > const &M, T const &threshold)
template<typename T >
bool is_orthonormal (Matrix3x3< T > const &M)
template<typename T >
bool is_zero (Matrix3x3< T > M, T const &threshold)
template<typename T >
bool is_zero (Matrix3x3< T > const &M)
template<typename T >
bool is_symmetric (Matrix3x3< T > M, T const &threshold)
template<typename T >
bool is_symmetric (Matrix3x3< T > const &M)
template<typename T >
bool is_diagonal (Matrix3x3< T > M, T const &threshold)
template<typename T >
bool is_diagonal (Matrix3x3< T > const &M)
template<typename T >
bool is_identity (Matrix3x3< T > M, T const &threshold)
template<typename T >
bool is_identity (Matrix3x3< T > const &M)
template<typename T >
Matrix3x3< T > outer_prod (Vector3< T > const &v1, Vector3< T > const &v2)
template<typename T >
Matrix3x3< T > ortonormalize (Matrix3x3< T > const &A)
template<typename T >
Matrix3x3< T > trans (Matrix3x3< T > const &M)
template<typename T >
Matrix3x3< T > diag (T const &d0, T const &d1, T const &d2)
template<typename T >
Matrix3x3< T > diag (Vector3< T > const &d)
template<typename T >
Matrix3x3< T > diag (T const &d)
template<typename T >
Matrix3x3< T > inverse (Matrix3x3< T > const &A)
template<typename T >
max_value (Matrix3x3< T > const &A)
template<typename T >
min_value (Matrix3x3< T > const &A)
template<typename T >
det (Matrix3x3< T > const &A)
template<typename T >
trace (Matrix3x3< T > const &A)
template<typename T >
norm_1 (Matrix3x3< T > const &A)
template<typename T >
norm_2 (Matrix3x3< T > const &A)
template<typename T >
norm_inf (Matrix3x3< T > const &A)
template<typename T >
Matrix3x3< T > truncate (Matrix3x3< T > const &A, T const &epsilon)
template<typename T >
Matrix3x3< T > star (Vector3< T > const &v)
template<typename T >
std::ostream & operator<< (std::ostream &o, Matrix3x3< T > const &A)
template<typename T >
std::istream & operator>> (std::istream &i, Matrix3x3< T > &A)
template<typename real_type , typename real_array >
bool compute_polynomial_roots (real_type const &c0, real_type const &c1, unsigned int &count, real_array &roots)
template<typename real_type , typename real_array >
bool compute_polynomial_roots (real_type const &c0, real_type const &c1, real_type const &c2, unsigned int &count, real_array &roots)
template<typename real_type , typename real_array >
bool compute_polynomial_roots (real_type c0, real_type c1, real_type c2, real_type const &c3, unsigned int &count, real_array &roots)
template<typename real_type , typename real_array >
bool compute_polynomial_roots (real_type c0, real_type c1, real_type c2, real_type c3, real_type const &c4, unsigned int &count, real_array &roots)
template<class T >
bool is_power2 (T val)
template<class T >
upper_power2 (T val)
template<class T >
lower_power2 (T val)
template<typename T >
machine_precision ()
template<typename T >
working_precision ()
template<typename T >
working_precision (unsigned int scale_factor)
bool trial_division (int n)
int modular_exponentiation (int a, int b, int n)
bool pseudo_prime (int n)
bool miller_rabin (int n, int s)
int prime_search (int n)
int gcd_euclid_algorithm (int a, int b)
bool is_relative_prime (int a, int b)
template<typename T >
Vector3< T > rotate (Quaternion< T > const &q, Vector3< T > const &r)
template<typename T >
Quaternion< T > prod (Quaternion< T > const &a, Quaternion< T > const &b)
template<typename T >
Quaternion< T > prod (Quaternion< T > const &a, Vector3< T > const &b)
template<typename T >
Quaternion< T > prod (Vector3< T > const &a, Quaternion< T > const &b)
template<typename T >
Quaternion< T > operator% (Quaternion< T > const &a, Quaternion< T > const &b)
template<typename T >
Quaternion< T > operator% (Quaternion< T > const &a, Vector3< T > const &b)
template<typename T >
Quaternion< T > operator% (Vector3< T > const &a, Quaternion< T > const &b)
template<typename T , typename T2 >
Quaternion< T > operator* (const Quaternion< T > &q, const T2 &s_val)
template<typename T2 , typename T >
Quaternion< T > operator* (const T2 &s_val, const Quaternion< T > &q)
template<typename T , typename T2 >
Quaternion< T > operator/ (const Quaternion< T > &q, const T2 &s_val)
template<typename T2 , typename T >
Quaternion< T > operator/ (const T2 &s_val, const Quaternion< T > &q)
template<typename T >
T const length (Quaternion< T > const &q)
template<typename T >
Quaternion< T > unit (Quaternion< T > const &q)
template<typename T >
Quaternion< T > normalize (Quaternion< T > const &q)
template<typename T >
Quaternion< T > log (Quaternion< T > const &q)
template<typename T >
Quaternion< T > hat (Quaternion< T > const &q)
template<typename T >
Quaternion< T > exp (Quaternion< T > const &q)
template<typename T >
Quaternion< T > qlerp (Quaternion< T > const &A, Quaternion< T > const &B, T const &w)
template<typename T >
Quaternion< T > slerp (Quaternion< T > const &A, Quaternion< T > const &B, T const &w)
template<typename T >
Quaternion< T > squad (Quaternion< T > const &q0, Quaternion< T > const &q1, Quaternion< T > const &q2, Quaternion< T > const &q3, T const &u)
template<typename T >
Quaternion< T > conj (Quaternion< T > const &q)
template<typename T >
void get_axis_angle (Quaternion< T > const &Q, Vector3< T > &axis, T &theta)
template<typename T >
get_angle (Quaternion< T > const &Q_rel, Vector3< T > const &axis)
template<typename T >
std::ostream & operator<< (std::ostream &o, Quaternion< T > const &q)
template<typename T >
std::istream & operator>> (std::istream &i, Quaternion< T > &q)
template<typename T >
std::ostream & operator<< (std::ostream &o, Rotation< T > const &r)
template<typename T >
std::istream & operator>> (std::istream &i, Rotation< T > &r)
template<typename T , typename T2 >
trillinear (T const &d000, T const &d001, T const &d010, T const &d011, T const &d100, T const &d101, T const &d110, T const &d111, T2 const &s, T2 const &t, T2 const &u)
template<typename T >
Vector3< T > round (Vector3< T > const &v)
template<typename T >
Vector3< T >::index_type min_index (Vector3< T > const &v)
template<typename T >
Vector3< T >::index_type max_index (Vector3< T > const &v)
template<typename T >
Vector3< T >::index_type mid_index (Vector3< T > const &v)
template<typename T >
min_value (Vector3< T > const &v)
template<typename T >
max_value (Vector3< T > const &v)
template<typename T >
mid_value (Vector3< T > const &v)
template<typename T >
bool is_zero (Vector3< T > const &v, T const &threshold)
template<typename T >
bool is_zero (Vector3< T > const &v)
template<typename T1 , typename T2 , typename T3 >
void random (Vector3< T1 > &v, T2 const &lower, T3 const &upper)
template<typename T >
void random (Vector3< T > &v, Vector3< T > const &lower, Vector3< T > const &upper)
template<typename T >
void random (Vector3< T > &v)
template<typename T >
Vector3< T > cross (Vector3< T > const &a, Vector3< T > const &b)
template<typename T >
dot (Vector3< T > const &a, Vector3< T > const &b)
template<typename T >
inner_prod (Vector3< T > const &a, Vector3< T > const &b)
template<typename T >
length (Vector3< T > const &v)
template<typename T >
sqr_length (Vector3< T > const &v)
template<typename T >
norm (Vector3< T > const &v)
template<typename T >
norm_1 (Vector3< T > const &v)
template<typename T >
distance (Vector3< T > const &a, Vector3< T > const &b)
template<typename T >
sqr_distance (Vector3< T > const &a, Vector3< T > const &b)
template<typename T >
Vector3< T > sgn (Vector3< T > const &v)
template<typename T >
Vector3< T > unit (Vector3< T > const &v)
template<typename T >
Vector3< T > normalize (Vector3< T > const &v)
template<typename T >
void truncate (Vector3< T > &v, T const &precision_value)
template<typename T >
void truncate (Vector3< T > &v)
template<typename T >
Vector3< T > orthogonal (Vector3< T > const &v)
template<typename T , typename T2 >
Vector3< T > operator* (Vector3< T > const &v, T2 const &s)
template<typename T2 , typename T >
Vector3< T > operator* (T2 const &s, Vector3< T > const &v)
template<typename T , typename T2 >
Vector3< T > operator/ (Vector3< T > const &v, T2 const &s)
template<typename vector3_type >
void orthonormal_vectors (vector3_type &i, vector3_type &j, vector3_type const &k)
template<typename vector_type , typename permutation_container >
void get_increasing_order (vector_type const &v, permutation_container &pi)

Detailed Description

The following functions are defined below:


Typedef Documentation


Function Documentation

template<typename T >
T OpenTissue::math::clamp ( T const &  value,
T const &  min_value,
T const &  max_value 
) [inline]

clamp function to clamp a value to be in the interval (min_value; max_value).

Parameters:
value The value to be clamped.
min_value The minimum allowed value.
max_value The maximum allowed value (ohhh, really?).
Returns:
The clamped value. If value already is in (min_value; max_value) no clamping is performed.
template<typename T >
T OpenTissue::math::clamp_max ( T const &  value,
T const &  max_value 
) [inline]

clamp function to clamp a value never to be greater than max_value.

Parameters:
value The value to be clamped.
max_value The maximum allowed value.
Returns:
The clamped value if value is greater than max_value, otherwise the original value is returned.
template<typename T >
T OpenTissue::math::clamp_min ( T const &  value,
T const &  min_value 
) [inline]

clamp function to clamp a value never to be less than min_value.

Parameters:
value The value to be clamped.
min_value The minimum allowed value.
Returns:
The clamped value if value is less than min_value, otherwise the original value is returned.
template<typename T >
T OpenTissue::math::clamp_zero_one ( T const &  value  )  [inline]

clamp function to easily clamp a value between 0 and 1. note: this function is mostly usable for T = some real type.

Parameters:
value The value to be clamped.
Returns:
The clamped value. If value already is in (0; 1) no clamping is performed.
template<typename iterator_type >
void OpenTissue::math::compute_contiguous_angle_interval ( iterator_type const &  begin,
iterator_type const &  end,
typename iterator_type::value_type &  theta_min,
typename iterator_type::value_type &  theta_max 
) [inline]

Compute Contiguous Angle Interval. This function tries to find a contiguous interval of angle values. As input it takes a sequence of angle values. From this sequence the function tries to compute the starting and ending angle (in terms of counter-clock-wise rotation order) of a contiguous interval. interval containing all the angles.

One could interact with the function as follows

std::vector<double> angles;

... fill angles with values ...

double min_val, max_val; compute_contiguous_angle_interval( angles.begin(), angles.end(), min_val, max_val );

The resulting minimum and maximum values yields the starting and ending points of the contiguous interval. The periodicity of rotation angles is used to adjust the end-points of the interval to always be positive values.

The supplied angles can be given in any sort of interval as long as the width of the interval is no longer than 2 pi ( one full rotation). Typically one would supply values from either -pi..pi or 0..2pi intervals.

Parameters:
begin An iterator to the first angle value
end An iterator to one past the last angle value
theta_min Upon return this value holds the starting value of the contiguous angle interval.
theta_max Upon return this value holds the ending value of the contiguous angle interval.
template<typename real_type , typename real_array >
bool OpenTissue::math::compute_polynomial_roots ( real_type const &  c0,
real_type const &  c1,
real_type const &  c2,
unsigned int &  count,
real_array &  roots 
) [inline]

Solve roots of

c2 x^2 + c1 x + c0 = 0

Parameters:
c2 The coefficient of the second power term.
c1 The coefficient of the first power term.
c0 The coefficient of the zeroth power term.
roots Upon return this array contains the computed roots.
count Upon return this parameter contains the number of computed roots.
Returns:
If roots were computed then the return value is true otherwise it is false.
template<typename real_type , typename real_array >
bool OpenTissue::math::compute_polynomial_roots ( real_type  c0,
real_type  c1,
real_type  c2,
real_type const &  c3,
unsigned int &  count,
real_array &  roots 
) [inline]

Solve roots of

c3 x^3 + c2 x^2 + c1 x + c0 = 0

Parameters:
c3 The coefficient of the third power term.
c2 The coefficient of the second power term.
c1 The coefficient of the first power term.
c0 The coefficient of the zeroth power term.
roots Upon return this array contains the computed roots.
count Upon return this parameter contains the number of computed roots.
Returns:
If roots were computed then the return value is true otherwise it is false.
template<typename real_type , typename real_array >
bool OpenTissue::math::compute_polynomial_roots ( real_type  c0,
real_type  c1,
real_type  c2,
real_type  c3,
real_type const &  c4,
unsigned int &  count,
real_array &  roots 
) [inline]

Solve roots of

c4 x^4 + c3 x^3 + c2 x^2 + c1 x + c0 = 0

Parameters:
c4 The coefficient of the fourth power term.
c3 The coefficient of the third power term.
c2 The coefficient of the second power term.
c1 The coefficient of the first power term.
c0 The coefficient of the zeroth power term.
roots Upon return this array contains the computed roots.
count Upon return this parameter contains the number of computed roots.
Returns:
If roots were computed then the return value is true otherwise it is false.
template<typename real_type , typename real_array >
bool OpenTissue::math::compute_polynomial_roots ( real_type const &  c0,
real_type const &  c1,
unsigned int &  count,
real_array &  roots 
) [inline]

Solve roots of

c1 x + c0 = 0

Parameters:
c1 The coefficient of the first power term.
c0 The coefficient of the zeroth power term.
roots Upon return this array contains the computed roots.
count Upon return this parameter contains the number of computed roots.
Returns:
If roots were computed then the return value is true otherwise it is false.
template<typename T >
Quaternion<T> OpenTissue::math::conj ( Quaternion< T > const &  q  )  [inline]

Quaternion Conjugate.

template<typename vector3_iterator , typename vector3_type , typename matrix3x3_type >
void OpenTissue::math::covariance ( vector3_iterator  begin,
vector3_iterator  end,
vector3_type mean,
matrix3x3_type &  C 
) [inline]
Parameters:
mean Resulting mean point.
C Resulting covariance matrix.
template<typename vector3_type , typename matrix3x3_type >
void OpenTissue::math::covariance_union ( vector3_type const &  mean1,
matrix3x3_type const &  C1,
vector3_type const &  mean2,
matrix3x3_type const &  C2,
vector3_type mean,
matrix3x3_type &  C 
) [inline]
Parameters:
mean Resulting mean point.
C Resulting covariance matrix.
template<typename T >
Vector3<T> OpenTissue::math::cross ( Vector3< T > const &  a,
Vector3< T > const &  b 
) [inline]
template<typename T >
T OpenTissue::math::det ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::diag ( Vector3< T > const &  d  )  [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::diag ( T const &  d  )  [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::diag ( T const &  d0,
T const &  d1,
T const &  d2 
) [inline]
template<typename T >
T OpenTissue::math::distance ( Vector3< T > const &  a,
Vector3< T > const &  b 
) [inline]
template<typename T >
T OpenTissue::math::dot ( Vector3< T > const &  a,
Vector3< T > const &  b 
) [inline]
template<typename matrix3x3_type , typename vector3_type >
void OpenTissue::math::eigen ( matrix3x3_type const &  A,
matrix3x3_type &  V,
vector3_type diag 
) [inline]

Eigen System Decomposition.

Parameters:
A Matrix to find eigenvectors and eigenvalues of.
V Upon return the columns of this matrix contains the eigenvectors. IMPORTANT: V may not form a right-handed coordinate system (ie. V might not be a rotation matrix). If a rotation matrix is needed one should compute the determinant of V and flip the sign of one of V's columns in case the determinant is negative. That is:

if(det(V)<0) { V(0,0) =- V(0,0); V(1,0) =- V(1,0); V(2,0) =- V(2,0); }

Parameters:
diag Upon return this vector contains the eigenvalues, such that entry 0 correpsonds to eigenvector 0 and so on.
template<typename matrix3x3_type , typename real_type >
bool OpenTissue::math::euler_angles ( matrix3x3_type const &  R,
real_type rx,
real_type ry,
real_type rz 
) [inline]

Computes Euler Angles. The resulting order is: xyz, i.e. first x, then y and finally z

Parameters:
R A rotation matrix
rx Upon return holds the rotation around x-axis in radians.
ry Upon return holds the rotation around y-axis in radians.
rz Upon return holds the rotation around z-axis in radians.
Returns:
If return value is true then we have computed unique euler angle values otherwise our solution might not be unique
template<typename T >
Quaternion<T> OpenTissue::math::exp ( Quaternion< T > const &  q  )  [inline]

Expoent Sets the Quaternion equal to the expoent of the specified Quaternion.

Parameters:
q A reference to a pure Quaternion (zero T part).
template<typename T >
T OpenTissue::math::fac ( unsigned long  n  )  [inline]
int OpenTissue::math::gcd_euclid_algorithm ( int  a,
int  b 
) [inline]

Greatest Common Divisor. Computes greatest common divisor with euclids algorithm.

Parameters:
a 
b 
Returns:
Greatest common divisor between a and b.
template<typename T >
T OpenTissue::math::get_angle ( Quaternion< T > const &  Q_rel,
Vector3< T > const &  axis 
) [inline]

Get Rotation Angle wrt. an Axis. Think of it as if you have a fixated body A so only body B is allowd to move.

Let BF_B' indicate the initial orientation of body B's body frame and BF_B the current orientation, now BF_A should be thought of as being immoveable ie. constant.

Q_initial : BF_A -> BF_B' Q_cur : BF_A -> BF_B

Now we must have the relation

Q_rel Q_initial = Q_cur

From which we deduce

Q_rel = Q_cur conj(Q_initial)

And we see that

Q_rel : BF_B' -> BF_B

That is how much the body frame of body B have rotated (measured with respect to the fixed body frame A).

Parameters:
Q_rel Rotation from initial orientation of B to current orientation of B.
axis The rotation axis in the body frame of body B.
Returns:
The angle in radians.
template<typename T >
void OpenTissue::math::get_axis_angle ( Quaternion< T > const &  Q,
Vector3< T > &  axis,
T &  theta 
) [inline]

Get Axis Angle Representation. This function converts a unit-quaternion into the equivalent angle-axis representation.

Parameters:
Q The quaternion
axis Upon return this argument holds value of the equivalent rotation axis.
theta Upon return this argument holds value of the equivalent rotation angle.
template<typename vector_type , typename permutation_container >
void OpenTissue::math::get_increasing_order ( vector_type const &  v,
permutation_container &  pi 
) [inline]

Get increasing order of vector elements as a permutation array.

Note this template function generalizes to any size of vectors (not just 3-dimensional ones).

Parameters:
v The vector to be examined.
pi Upon return this container contains the permuation order, v(pi[0]) is smallest element of v, v(pi[1]) the next smallest and so on.
template<typename T >
Quaternion<T> OpenTissue::math::hat ( Quaternion< T > const &  q  )  [inline]

Orthogonal Quaternion. This method sets this Quaternion to an orthogonal Quaternion of the specififed Quaternion. In otherwords the resulting angle between the specified Quaternion and this Quaternion is pi/2.

template<typename T >
T OpenTissue::math::inner_prod ( Vector3< T > const &  a,
Vector3< T > const &  b 
) [inline]
template<typename T >
CoordSys<T> OpenTissue::math::inverse ( CoordSys< T > const &  X  )  [inline]

Inverse Transform.

If we have

BF -> WCS

Then we want to find

WCS -> BF

template<typename T >
Matrix3x3<T> OpenTissue::math::inverse ( Matrix3x3< T > const &  A  )  [inline]
template<typename real_type >
void OpenTissue::math::invert4x4 ( real_type  M[4][4]  )  [inline]
template<typename T >
bool OpenTissue::math::is_diagonal ( Matrix3x3< T >  M,
T const &  threshold 
) [inline]
template<typename T >
bool OpenTissue::math::is_diagonal ( Matrix3x3< T > const &  M  )  [inline]
template<typename T >
bool OpenTissue::math::is_identity ( Matrix3x3< T >  M,
T const &  threshold 
) [inline]
template<typename T >
bool OpenTissue::math::is_identity ( Matrix3x3< T > const &  M  )  [inline]
template<typename T >
bool OpenTissue::math::is_orthonormal ( Matrix3x3< T > const &  M,
T const &  threshold 
) [inline]
template<typename T >
bool OpenTissue::math::is_orthonormal ( Matrix3x3< T > const &  M  )  [inline]
template<class T >
bool OpenTissue::math::is_power2 ( val  )  [inline]

This method test whether there exist some positive integer, n, such that

2^n == val

In which case it returns true otherwise it returns false.

bool OpenTissue::math::is_relative_prime ( int  a,
int  b 
) [inline]

Tests if two numbers are relative prime.

Returns:
If a and b are relative prime then the return value is true otherwise it is false.
template<typename T >
bool OpenTissue::math::is_symmetric ( Matrix3x3< T >  M,
T const &  threshold 
) [inline]
template<typename T >
bool OpenTissue::math::is_symmetric ( Matrix3x3< T > const &  M  )  [inline]
template<typename T >
bool OpenTissue::math::is_zero ( Matrix3x3< T >  M,
T const &  threshold 
) [inline]
template<typename T >
bool OpenTissue::math::is_zero ( Matrix3x3< T > const &  M  )  [inline]
template<typename T >
bool OpenTissue::math::is_zero ( Vector3< T > const &  v,
T const &  threshold 
) [inline]
template<typename T >
bool OpenTissue::math::is_zero ( Vector3< T > const &  v  )  [inline]
template<typename vector_iterator , typename vector_container , typename index_container >
void OpenTissue::math::kmeans ( vector_iterator const &  begin,
vector_iterator const &  end,
vector_container &  centers,
index_container &  membership,
size_t  K,
size_t &  iteration,
size_t const &  max_iterations 
) [inline]

K-Means Algorithm.

Parameters:
begin An iterator to the first feature point.
end An iterator to the position one past the last feature point.
centers Upon return this container holds the cluster centers that have been found.
membership Upon return this container holds cluster membership information of the feature points. That is the i'th feature points p[i] belongs to cluster c[m[i]].

p[i] c[m[i]]

Parameters:
K The number of clusters
iteration Upon return this argument holds the number of iterations that was done.
max_iterations The maximum number of iterations to perform the KMeans algorithm. Usually a value of 50 works okay.
template<typename T >
T const OpenTissue::math::length ( Quaternion< T > const &  q  )  [inline]
template<typename T >
T OpenTissue::math::length ( Vector3< T > const &  v  )  [inline]
template<typename T >
Quaternion<T> OpenTissue::math::log ( Quaternion< T > const &  q  )  [inline]

Natural Logarithm Returns the Quaternion equal to the natural logarithm of the specified Quaternion.

Parameters:
q A reference to an unit quaterion.
Returns:
template<class T >
T OpenTissue::math::lower_power2 ( val  )  [inline]

This function finds the largest positive integer, n, such that

2^n <= val

and returns the value 2^n.

template<typename T >
T OpenTissue::math::machine_precision (  )  [inline]
template<typename T >
Vector3<T>::index_type OpenTissue::math::max_index ( Vector3< T > const &  v  )  [inline]
template<typename T >
T OpenTissue::math::max_value ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
T OpenTissue::math::max_value ( Vector3< T > const &  v  )  [inline]
template<typename T >
Vector3<T>::index_type OpenTissue::math::mid_index ( Vector3< T > const &  v  )  [inline]
template<typename T >
T OpenTissue::math::mid_value ( Vector3< T > const &  v  )  [inline]
bool OpenTissue::math::miller_rabin ( int  n,
int  s 
) [inline]

Prime Test. This method tests if the specified integer is a prime.

The algorithm requires O(s*beta) arithmetic operations and O(s*beta*beta*beta) bit operations, where beta is the number of bits in n.

Parameters:
n The number to test.
s The number of random tests.
Returns:
If n was prime then the return value is true otherwise it is false.
template<typename T >
Vector3<T>::index_type OpenTissue::math::min_index ( Vector3< T > const &  v  )  [inline]
template<typename T >
T OpenTissue::math::min_value ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
T OpenTissue::math::min_value ( Vector3< T > const &  v  )  [inline]
template<typename T >
CoordSys<T> OpenTissue::math::model_update ( CoordSys< T > const &  A,
CoordSys< T > const &  B 
) [inline]

Model Update Transform. This method computes the necessary transform needed in order to transform coordinates from one local frame into another local frame. This utility is useful when one wants to do model updates instead of world updates.

In mathematical terms we have two transforms:

C1 : H -> G C2 : F -> G

And we want to find

C3 : H -> F

This transform is computed and assigned to this coordinate system.

template<typename T >
CoordSys<T> OpenTissue::math::model_update ( Vector3< T > const &  TA,
Quaternion< T > const &  QA,
Vector3< T > const &  TB,
Quaternion< T > const &  QB 
) [inline]

Model Update Transform. This method computes the necessary transform needed in order to transform coordinates from one local frame into another local frame. This utility is useful when one wants to do model updates instead of world updates.

In mathematical terms we have two transforms:

C1 : H -> G C2 : F -> G

And we want to find

C3 : H -> F

This transform is computed and assigned to this coordinate system.

Very important: Note that this method finds the transform A -> B.

int OpenTissue::math::modular_exponentiation ( int  a,
int  b,
int  n 
) [inline]

Modular Exponentiation. Computes a raised to the power of b modular n

template<typename T >
T OpenTissue::math::norm ( Vector3< T > const &  v  )  [inline]
template<typename T >
T OpenTissue::math::norm_1 ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
T OpenTissue::math::norm_1 ( Vector3< T > const &  v  )  [inline]
template<typename T >
T OpenTissue::math::norm_2 ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
T OpenTissue::math::norm_inf ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
Vector3<T> OpenTissue::math::normalize ( Vector3< T > const &  v  )  [inline]
template<typename T >
Quaternion<T> OpenTissue::math::normalize ( Quaternion< T > const &  q  )  [inline]
template<typename T >
Quaternion<T> OpenTissue::math::operator% ( Quaternion< T > const &  a,
Quaternion< T > const &  b 
) [inline]
template<typename T >
Quaternion<T> OpenTissue::math::operator% ( Quaternion< T > const &  a,
Vector3< T > const &  b 
) [inline]
template<typename T >
Quaternion<T> OpenTissue::math::operator% ( Vector3< T > const &  a,
Quaternion< T > const &  b 
) [inline]
template<typename T , typename T2 >
Vector3<T> OpenTissue::math::operator* ( Vector3< T > const &  v,
T2 const &  s 
) [inline]
template<typename T2 , typename T >
Vector3<T> OpenTissue::math::operator* ( T2 const &  s,
Vector3< T > const &  v 
) [inline]
template<typename T2 , typename T >
Quaternion<T> OpenTissue::math::operator* ( const T2 &  s_val,
const Quaternion< T > &  q 
) [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::operator* ( Matrix3x3< T > const &  A,
Matrix3x3< T > const &  B 
) [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::operator* ( Matrix3x3< T > const &  m,
T const &  s 
) [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::operator* ( T const &  s,
Matrix3x3< T > const &  m 
) [inline]
template<typename T , typename T2 >
Quaternion<T> OpenTissue::math::operator* ( const Quaternion< T > &  q,
const T2 &  s_val 
) [inline]
template<typename T , typename T2 >
Vector3<T> OpenTissue::math::operator/ ( Vector3< T > const &  v,
T2 const &  s 
) [inline]
template<typename T2 , typename T >
Quaternion<T> OpenTissue::math::operator/ ( const T2 &  s_val,
const Quaternion< T > &  q 
) [inline]
template<typename T , typename T2 >
Quaternion<T> OpenTissue::math::operator/ ( const Quaternion< T > &  q,
const T2 &  s_val 
) [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::operator/ ( T const &  s,
Matrix3x3< T > const &  m 
) [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::operator/ ( Matrix3x3< T > const &  m,
T const &  s 
) [inline]
template<typename T >
std::ostream& OpenTissue::math::operator<< ( std::ostream &  o,
Rotation< T > const &  r 
) [inline]
template<typename T >
std::ostream& OpenTissue::math::operator<< ( std::ostream &  o,
Quaternion< T > const &  q 
) [inline]
template<typename T >
std::ostream& OpenTissue::math::operator<< ( std::ostream &  o,
CoordSys< T > const &  C 
) [inline]
template<typename T >
std::ostream& OpenTissue::math::operator<< ( std::ostream &  o,
Matrix3x3< T > const &  A 
) [inline]
template<typename T >
std::istream& OpenTissue::math::operator>> ( std::istream &  i,
Quaternion< T > &  q 
) [inline]
template<typename T >
std::istream& OpenTissue::math::operator>> ( std::istream &  i,
Rotation< T > &  r 
) [inline]
template<typename T >
std::istream& OpenTissue::math::operator>> ( std::istream &  i,
CoordSys< T > &  C 
) [inline]
template<typename T >
std::istream& OpenTissue::math::operator>> ( std::istream &  i,
Matrix3x3< T > &  A 
) [inline]
template<typename T >
Vector3<T> OpenTissue::math::orthogonal ( Vector3< T > const &  v  )  [inline]

Get Orthogonal Vector.

Parameters:
v Any vector
Returns:
A vector orthogonal to v.
template<typename vector3_type >
void OpenTissue::math::orthonormal_vectors ( vector3_type i,
vector3_type j,
vector3_type const &  k 
) [inline]

Compute Orthonormal Vectors. Compute unit vectors of a right handed coordinate frame, given initial z-axis (k-vector).

Parameters:
i Upon return contains a orthogonal vector to j and k
j Upon return contains a orthogonal vector to i and k
k A given direction for the last vector, assumed to be a unit-vector.
template<typename T >
Matrix3x3<T> OpenTissue::math::ortonormalize ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::outer_prod ( Vector3< T > const &  v1,
Vector3< T > const &  v2 
) [inline]
int OpenTissue::math::prime_search ( int  n  )  [inline]

Closest Prime Search. This method tries to find the closest prime number to n.

Parameters:
n The seed number from where the search should be done from.
Returns:
The closest prime number to n.
template<typename T >
Quaternion<T> OpenTissue::math::prod ( Vector3< T > const &  a,
Quaternion< T > const &  b 
) [inline]
template<typename T >
Quaternion<T> OpenTissue::math::prod ( Quaternion< T > const &  a,
Quaternion< T > const &  b 
) [inline]
template<typename T >
Quaternion<T> OpenTissue::math::prod ( Quaternion< T > const &  a,
Vector3< T > const &  b 
) [inline]
template<typename T >
CoordSys<T> OpenTissue::math::prod ( CoordSys< T > const &  L,
CoordSys< T > const &  R 
) [inline]

Coordinate Transformation Product. This function should be used to concatenate coordinate transformations. In terms of homogeneous coordinates L and R corresponds to the matrices.

L = | R_l T_l | | 0 1 |

R = | R_r T_r | | 0 1 |

This function computes the equivalent of the product

X = L R

= | R_l T_l | | R_r T_r | | 0 1 | | 0 1 |

= | R_l R_r R_l T_r + T_l | | 0 1 |

Parameters:
L The left coordinate transformation
R The right coordinate transformation
Returns:
The coordinate transformation corresponding to the product L*R.
bool OpenTissue::math::pseudo_prime ( int  n  )  [inline]

Prime Test. This method tests if the specified integer is a prime.

Extremely fast, does not allways find a correct solution. However it fails rarely and it only makes error of one type.

Some base-2 pseudo primes are 341, 561,645 and 1105.

Parameters:
n The number to test.
Returns:
If n was prime then the return value is true otherwise it is false.
template<typename T >
Quaternion<T> OpenTissue::math::qlerp ( Quaternion< T > const &  A,
Quaternion< T > const &  B,
T const &  w 
) [inline]

QLERP - Linear Interpolation of Quaterions.

Parameters:
A Quaternion A
B Quaternion B
w The weight
Returns:
The resulting Quaternion, (1-w)A+w B. Note the resulting Quaternion may not be a unit quaterion eventhough A and B are unit quaterions. If a unit Quaternion is needed write unit(qlerp(A,B,w)).

-Added by spreak for the SBS algorithm, see OpenTissue/kinematics/skinning/SBS

template<typename T1 , typename T2 , typename T3 >
void OpenTissue::math::random ( Vector3< T1 > &  v,
T2 const &  lower,
T3 const &  upper 
) [inline]
template<typename T >
void OpenTissue::math::random ( Vector3< T > &  v  )  [inline]
template<typename T >
void OpenTissue::math::random ( Matrix3x3< T > &  m  )  [inline]
template<typename T >
void OpenTissue::math::random ( Vector3< T > &  v,
Vector3< T > const &  lower,
Vector3< T > const &  upper 
) [inline]
template<typename T >
Vector3<T> OpenTissue::math::rotate ( Quaternion< T > const &  q,
Vector3< T > const &  r 
) [inline]
template<typename T >
Vector3<T> OpenTissue::math::round ( Vector3< T > const &  v  )  [inline]

Declaration of vector3 non-member functions

template<typename T >
Matrix3x3<T> OpenTissue::math::Ru ( T const &  radians,
Vector3< T > const &  axis 
) [inline]

Creates a rotation matrix. This method returns a general rotation matrix around a specified axe. It assumes that post-multiplication by colum vectors is used.

Parameters:
radians The rotation angle in radians.
axe A vector. This is the rotation axe.
template<typename T >
Matrix3x3<T> OpenTissue::math::Rx ( T const &  radians  )  [inline]

Creates a rotation matrix. This method returns a rotation matrix around the x-axe. It assumes that post-multiplication by colum vectors is used.

Parameters:
radians The rotation angle in radians.
template<typename T >
Matrix3x3<T> OpenTissue::math::Ry ( T const &  radians  )  [inline]

Creates a rotation matrix. This method returns a rotation matrix around the y-axe. It assumes that post-multiplication by colum vectors is used.

Parameters:
radians The rotation angle in radians.
template<typename T >
Matrix3x3<T> OpenTissue::math::Rz ( T const &  radians  )  [inline]

Creates a rotation matrix. This method returns a rotation matrix around the z-axe. It assumes that post-multiplication by colum vectors is used.

Parameters:
radians The rotation angle in radians.
template<typename T >
T OpenTissue::math::sgn ( T const &  val  )  [inline]
template<typename T >
Vector3<T> OpenTissue::math::sgn ( Vector3< T > const &  v  )  [inline]
template<typename T >
T OpenTissue::math::sinc ( T &  x  )  [inline]

Compute Sinc Function. The implementation of this method was greatly inspired by the one in Open Dynamics Engine v. 0.039

This method returns sin(x)/x. this has a singularity at 0 so special handling is needed for small arguments.

Parameters:
x 
Returns:
The value of sin(x)/x
template<typename T >
Quaternion<T> OpenTissue::math::slerp ( Quaternion< T > const &  A,
Quaternion< T > const &  B,
T const &  w 
) [inline]

Spherical Linear Interpolation of Quaterions.

Parameters:
A 
B 
w The weight
Returns:
The resulting Quaternion.
template<typename T >
T OpenTissue::math::sqr_distance ( Vector3< T > const &  a,
Vector3< T > const &  b 
) [inline]
template<typename T >
T OpenTissue::math::sqr_length ( Vector3< T > const &  v  )  [inline]
template<typename T >
Quaternion<T> OpenTissue::math::squad ( Quaternion< T > const &  q0,
Quaternion< T > const &  q1,
Quaternion< T > const &  q2,
Quaternion< T > const &  q3,
T const &  u 
) [inline]

"Cubical" Sphereical Interpolation. In popular terms this correpons to a cubic spline in ordinary 3D space. However it is really a serie of spherical linear interpolations, which defines a cubic on the unit Quaternion sphere.

Parameters:
q0 
q1 
q2 
q3 
u 
Returns:
template<typename T >
Matrix3x3<T> OpenTissue::math::star ( Vector3< T > const &  v  )  [inline]

Sets up the cross product matrix. This method is usefull for expression the cross product as a matrix multiplication.

Parameters:
v A reference to a vector. This is first argument of the cross product.
template<typename T >
T OpenTissue::math::to_degrees ( T const &  radians  )  [inline]
template<typename T >
T OpenTissue::math::to_radians ( T const &  degrees  )  [inline]
template<typename T >
T OpenTissue::math::trace ( Matrix3x3< T > const &  A  )  [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::trans ( Matrix3x3< T > const &  M  )  [inline]
bool OpenTissue::math::trial_division ( int  n  )  [inline]

Prime Test. This method tests if the specified integer is a prime.

Do Always find a correct solution, but is very slow for large numbers.

Runs in time 2^(beta/2) where beta is the number of bits of n.

Parameters:
n The number to test.
Returns:
If n was prime then the return value is true otherwise it is false.
template<typename T , typename T2 >
T OpenTissue::math::trillinear ( T const &  d000,
T const &  d001,
T const &  d010,
T const &  d011,
T const &  d100,
T const &  d101,
T const &  d110,
T const &  d111,
T2 const &  s,
T2 const &  t,
T2 const &  u 
) [inline]

Trillinear Interpolation. Interpolation of values in a cubic grid.

template<typename T >
void OpenTissue::math::truncate ( Vector3< T > &  v,
T const &  precision_value 
) [inline]
template<typename T >
void OpenTissue::math::truncate ( Vector3< T > &  v  )  [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::truncate ( Matrix3x3< T > const &  A,
T const &  epsilon 
) [inline]
template<typename T >
Vector3<T> OpenTissue::math::unit ( Vector3< T > const &  v  )  [inline]
template<typename T >
Quaternion<T> OpenTissue::math::unit ( Quaternion< T > const &  q  )  [inline]
template<class T >
T OpenTissue::math::upper_power2 ( val  )  [inline]

This function finds the smallest positive integer, n, such that

val <= 2^n

and returns the value 2^n.

template<typename T >
T OpenTissue::math::working_precision (  )  [inline]
template<typename T >
T OpenTissue::math::working_precision ( unsigned int  scale_factor  )  [inline]
template<typename T >
Matrix3x3<T> OpenTissue::math::z_dof ( Vector3< T > const &  k  )  [inline]

Direction of Flight (DoF)

Parameters:
k The desired direction of flight.
template<typename T >
void OpenTissue::math::ZYZ_euler_angles ( OpenTissue::math::Quaternion< T > const &  Q,
T &  phi,
T &  psi,
T &  theta 
) [inline]