Carna  Version 3.0.1
Classes | Namespaces | Macros | Typedefs | Functions
math.h File Reference

Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI. More...

#include <Carna/Carna.h>
#include <Carna/base/CarnaException.h>
#include <algorithm>
#include <type_traits>
#include <cmath>
#include <Eigen/Dense>
+ Include dependency graph for math.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Carna::base::math::element_type_of< T >
 Retrieves element types of vectors and scalars. General case assumes a scalar type. More...
 
struct  Carna::base::math::element_type_of< Eigen::Matrix< VectorElementType, rows, cols > >
 Retrieves element types of vectors and scalars. This is the specialization for vector and matrix types. More...
 
struct  Carna::base::math::Statistics< T >
 Holds mean and variance of an characteristic. More...
 

Namespaces

 Carna::base
 Contains the core framework components.
 
 Carna::base::math
 Provides set of math-related classes and functions.
 

Macros

#define CARNA_FOR_VECTOR3UI_EX(vecName, vecLimit, vecStart)
 Loops vecName over all \(\vec x \in \mathbb Z^3_{\geq 0} : x_i < n_i \wedge x_i \geq s_i \forall i\) where \(\vec n\) is vecLimit and \(\vec s\) is vecStart. More...
 
#define CARNA_FOR_VECTOR3UI(vecName, vecLimit)   CARNA_FOR_VECTOR3UI_EX( vecName, vecLimit, Carna::base::math::Vector3ui( 0, 0, 0 ) )
 Loops vecName over all \(\vec x \in \mathbb Z^3_{\geq 0} : x_i < n_i \forall i\) where \(\vec n\) is vecLimit. More...
 

Typedefs

typedef Eigen::Matrix< float, 4, 4, Eigen::ColMajor > Carna::base::math::Matrix4f
 Defines \(\mathbb R^{4 \times 4}\) matrix.
 
typedef Eigen::Matrix< float, 3, 3, Eigen::ColMajor > Carna::base::math::Matrix3f
 Defines \(\mathbb R^{3 \times 3}\) matrix.
 
typedef Eigen::Matrix< float, 4, 1 > Carna::base::math::Vector4f
 Defines \(\mathbb R^{4 \times 1}\) vector.
 
typedef Eigen::Matrix< float, 3, 1 > Carna::base::math::Vector3f
 Defines \(\mathbb R^{3 \times 1}\) vector.
 
typedef Eigen::Matrix< float, 2, 1 > Carna::base::math::Vector2f
 Defines \(\mathbb R^{2 \times 1}\) vector.
 
typedef Eigen::Matrix< signed int, 3, 1 > Carna::base::math::Vector3i
 Defines \(\mathbb Z^{3 \times 1}\) vector.
 
typedef Eigen::Matrix< unsigned int, 3, 1 > Carna::base::math::Vector3ui
 Defines \(\mathbb Z^{3 \times 1}_{\geq 0}\) vector.
 
typedef Eigen::Matrix< unsigned int, 2, 1 > Carna::base::math::Vector2ui
 Defines \(\mathbb Z^{2 \times 1}_{\geq 0}\) vector.
 

Functions

template<typename T >
Carna::base::math::clamp (T val, T my_min, T my_max)
 Returns \( \min( \max( \) val \(, \) my_min \( ), \) my_max \( ) \). More...
 
template<typename T >
Carna::base::math::sq (T x)
 Computes and returns \( x^2 \).
 
float Carna::base::math::deg2rad (float deg)
 Converts degrees to radians.
 
float Carna::base::math::rad2deg (float rad)
 Converts radians to degrees.
 
template<typename T >
Carna::base::math::epsilon ()
 Defines the maximum difference of two objects treated as equal.
 
template<>
float Carna::base::math::epsilon< float > ()
 Defines the maximum difference of two single-precision floating point objects treated as equal.
 
template<>
double Carna::base::math::epsilon< double > ()
 Defines the maximum difference of two double-precision floating point objects treated as equal.
 
template<typename T >
Carna::base::math::length2 (const T &x)
 Retrieves the squared length of vector and scalar types. General case assumes scalar type.
 
template<typename VectorElementType , int dimension>
VectorElementType Carna::base::math::length2 (const Eigen::Matrix< VectorElementType, dimension, 1 > &x)
 Retrieves the squared length of vector and scalar types. This is the specialization for vector types.
 
template<typename InputType >
bool Carna::base::math::isEqual (const InputType &x, const InputType &y)
 Tells whether two objects are equal respectively to epsilon.
 
template<>
bool Carna::base::math::isEqual (const bool &x, const bool &y)
 Tells whether two objects are equal. This is the specialization for bool types.
 
Matrix4f Carna::base::math::identity4f ()
 Returns \(\mathbb R^{4 \times 4}\) identity matrix.
 
Matrix3f Carna::base::math::identity3f ()
 Returns \(\mathbb R^{3 \times 3}\) identity matrix.
 
template<typename MatrixType >
MatrixType Carna::base::math::zeros ()
 Returns matrix with zeros in all components.
 
Matrix4f Carna::base::math::basis4f (const Vector4f &x, const Vector4f &y, const Vector4f &z, const Vector4f &t=Vector4f(0, 0, 0, 0))
 Creates \(\mathbb R^{3 \times 3}\) basis embedded into a \(\mathbb R^{4 \times 4}\) homogenous coordinates matrix. More...
 
Matrix4f Carna::base::math::basis4f (const Vector3f &x, const Vector3f &y, const Vector3f &z, const Vector3f &t=Vector3f(0, 0, 0))
 
Matrix4f Carna::base::math::translation4f (float x, float y, float z)
 Returns matrix that translates homogeneous coordinates.
 
template<typename Vector >
Matrix4f Carna::base::math::translation4f (const Vector &v)
 
Matrix4f Carna::base::math::scaling4f (float x, float y, float z)
 Creates scaling matrix for homogeneous coordinates.
 
template<typename VectorElementType >
Matrix4f Carna::base::math::scaling4f (const Eigen::Matrix< VectorElementType, 3, 1 > &v)
 
Matrix4f Carna::base::math::scaling4f (float uniformScaleFactor)
 
Matrix4f Carna::base::math::rotation4f (float x, float y, float z, float radians)
 Creates rotation matrix for homogeneous coordinates. The rotation is performed around the axis that is specified by the vector with the components x, y and z.
 
template<typename Vector >
Matrix4f Carna::base::math::rotation4f (const Vector &v, float radians)
 
Matrix3f Carna::base::math::rotation3f (float x, float y, float z, float radians)
 Creates rotation matrix for homogeneous coordinates, but returns only the upper left \(3 \times 3\) sub-matrix.
 
Vector3f Carna::base::math::orthogonal3f (const Vector3f &in)
 Constructs \(\mathbb R^3\) vector that is orthogonal to in. The result is undefined if the squared length of in equals zero. More...
 
template<typename VectorElementType , int rows, typename WType >
Eigen::Matrix< VectorElementType, 4, 1 > Carna::base::math::vector4 (const Eigen::Matrix< VectorElementType, rows, 1 > &v, WType w)
 Creates 4-dimensional vector from 3-dimensional (or higher) with same component type, and a scalar that is appended as the fourth component.
 
template<typename VectorElementType , int rows>
Eigen::Matrix< VectorElementType, 3, 1 > Carna::base::math::vector3 (const Eigen::Matrix< VectorElementType, rows, 1 > &v)
 Creates 3-dimensional vector from 4-dimensional (or higher) with same component type by dropping the fourth component.
 
Matrix4f Carna::base::math::plane4f (const Vector3f &normal, float distance)
 Creates matrix that transforms from the tangent space of a plane with particular normal vector and origin distance to the space that normal and distance are given within.
 
Matrix4f Carna::base::math::plane4f (const Vector3f &normal, const Vector3f &support)
 
float Carna::base::math::translationDistance2 (const Matrix4f &m)
 Returns the squared length of the translation component of the homogeneous coordinates transformation matrix m.
 
template<typename Matrix >
Matrix::Scalar Carna::base::math::maxAbsElement (const Matrix &m)
 Returns \(\max_{i,j} \left|m_{i,j}\right|\) where $m$ is m.
 
Matrix4f Carna::base::math::frustum4f (float left, float right, float bottom, float top, float zNear, float zFar)
 Returns the projection matrix that is described by the specified frustum. More...
 
Matrix4f Carna::base::math::frustum4f (float fovRadiansHorizontal, float heightOverWidth, float zNear, float zFar)
 
Matrix4f Carna::base::math::ortho4f (float left, float right, float bottom, float top, float zNear, float zFar)
 Returns the projection matrix that is described by the specified box.
 
template<typename ScalarType >
unsigned int Carna::base::math::round_ui (ScalarType x)
 Rounds x to the closest \(x' \in \mathbb Z_{\geq 0}\). Either the data type of \(x\) must be unsigned or \(x \geq 0\).
 
template<typename MatrixElementType , int cols, int rows>
Eigen::Matrix< unsigned int, cols, rows > Carna::base::math::round_ui (const Eigen::Matrix< MatrixElementType, cols, rows > &m)
 Rounds matrix m to such \(m'\) that every element in \(m'\) is close-most to its corresponding element in \(m\). Either the element data type of \(m\) must be unsigned or \(m_{i,j} \geq 0 \forall i,j\).
 
template<typename ScalarType >
ScalarType Carna::base::math::makeEven (ScalarType x, int s)
 Returns \(x\) if \(x\) is even and \(x + s\) if \(x\) is odd, where \(s \in \left\{-1, +1\right\}\). The data type of \(x\) must be integral.
 
template<typename MatrixElementType , int cols, int rows>
Eigen::Matrix< MatrixElementType, cols, rows > Carna::base::math::makeEven (const Eigen::Matrix< MatrixElementType, cols, rows > &m, int s)
 Returns matrix \(m'\) of the same size like \(m\) where \(m'_{i,j} = m_{i,j}\) if \(m_{i,j}\) is even and \(m'_{i,j} = m_{i,j} + s\) if \(m_{i,j}\) is odd, where \(s \in \left\{-1, +1\right\}\). The element data type of \(m\) must be integral.
 
template<typename ResultType , typename SupportType >
ResultType Carna::base::math::mix (const SupportType &a, const SupportType &b, float t)
 Interpolates between and by t \(\in\left[0, 1\right]\) linearly.
 

Detailed Description

Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.

Attention
If you include windows.h before including this file, make sure you have NOMINMAX defined before including the windows.h header file.

Definition in file math.h.

Macro Definition Documentation

#define CARNA_FOR_VECTOR3UI (   vecName,
  vecLimit 
)    CARNA_FOR_VECTOR3UI_EX( vecName, vecLimit, Carna::base::math::Vector3ui( 0, 0, 0 ) )

Loops vecName over all \(\vec x \in \mathbb Z^3_{\geq 0} : x_i < n_i \forall i\) where \(\vec n\) is vecLimit.

Example:

using namespace Carna::base;
HUVolumeUInt16 data( math::Vector3ui( 100, 100, 30 ) );
/* Initialize all 'data' voxels with '-1024'.
*/
const HUV expected = -1024;
CARNA_FOR_VECTOR3UI( p, data.size )
{
data.setVoxel( p, expected );
}
/* Verify the result.
*/
for( std::size_t i = 0; i < data.buffer().size(); ++i )
{
QCOMPARE( data.buffer()[ i ], HUVolumeUInt16::HUVToBufferValue( expected ) );
}

Definition at line 728 of file math.h.

#define CARNA_FOR_VECTOR3UI_EX (   vecName,
  vecLimit,
  vecStart 
)
Value:
for( vecName.z() = vecStart.x(); vecName.z() < vecLimit.z(); ++vecName.z() ) \
for( vecName.y() = vecStart.y(); vecName.y() < vecLimit.y(); ++vecName.y() ) \
for( vecName.x() = vecStart.z(); vecName.x() < vecLimit.x(); ++vecName.x() )
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Definition: math.h:199

Loops vecName over all \(\vec x \in \mathbb Z^3_{\geq 0} : x_i < n_i \wedge x_i \geq s_i \forall i\) where \(\vec n\) is vecLimit and \(\vec s\) is vecStart.

Definition at line 714 of file math.h.