LibCarna Version 3.4.0
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Functions
math.hpp File Reference

Defines LibCarna::base::math namespace and LIBCARNA_FOR_VECTOR3UI. More...

#include <LibCarna/LibCarna.hpp>
#include <LibCarna/base/LibCarnaException.hpp>
#include <algorithm>
#include <type_traits>
#include <cmath>
#include <Eigen/Dense>
+ Include dependency graph for math.hpp:

Go to the source code of this file.

Classes

struct  LibCarna::base::math::element_type_of< T >
 Retrieves element types of vectors and scalars. General case assumes a scalar type. More...
 
struct  LibCarna::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  LibCarna::base::math::Statistics< T >
 Holds mean and variance of an characteristic. More...
 

Namespaces

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

Macros

#define LIBCARNA_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.
 
#define LIBCARNA_FOR_VECTOR3UI(vecName, vecLimit)    LIBCARNA_FOR_VECTOR3UI_EX( vecName, vecLimit, LibCarna::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.
 

Typedefs

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

Functions

template<typename T >
LibCarna::base::math::clamp (T val, T my_min, T my_max)
 Returns \( \min( \max( \) val \(, \) my_min \( ), \) my_max \( ) \).
 
template<typename T >
LibCarna::base::math::sq (T x)
 Computes and returns \( x^2 \).
 
float LibCarna::base::math::deg2rad (float deg)
 Converts degrees to radians.
 
float LibCarna::base::math::rad2deg (float rad)
 Converts radians to degrees.
 
template<typename T >
LibCarna::base::math::epsilon ()
 Defines the maximum difference of two objects treated as equal.
 
template<>
float LibCarna::base::math::epsilon< float > ()
 Defines the maximum difference of two single-precision floating point objects treated as equal.
 
template<>
double LibCarna::base::math::epsilon< double > ()
 Defines the maximum difference of two double-precision floating point objects treated as equal.
 
template<typename T >
LibCarna::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 LibCarna::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 LibCarna::base::math::isEqual (const InputType &x, const InputType &y)
 Tells whether two objects are equal respectively to epsilon.
 
template<>
bool LibCarna::base::math::isEqual (const bool &x, const bool &y)
 Tells whether two objects are equal. This is the specialization for bool types.
 
Matrix4f LibCarna::base::math::identity4f ()
 Returns \(\mathbb R^{4 \times 4}\) identity matrix.
 
Matrix3f LibCarna::base::math::identity3f ()
 Returns \(\mathbb R^{3 \times 3}\) identity matrix.
 
template<typename MatrixType >
MatrixType LibCarna::base::math::zeros ()
 Returns matrix with zeros in all components.
 
Matrix4f LibCarna::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.
 
Matrix4f LibCarna::base::math::basis4f (const Vector3f &x, const Vector3f &y, const Vector3f &z, const Vector3f &t=Vector3f(0, 0, 0))
 
Matrix4f LibCarna::base::math::translation4f (float x, float y, float z)
 Returns matrix that translates homogeneous coordinates.
 
template<typename Vector >
Matrix4f LibCarna::base::math::translation4f (const Vector &v)
 
Matrix4f LibCarna::base::math::scaling4f (float x, float y, float z)
 Creates scaling matrix for homogeneous coordinates.
 
template<typename VectorElementType >
Matrix4f LibCarna::base::math::scaling4f (const Eigen::Matrix< VectorElementType, 3, 1 > &v)
 
Matrix4f LibCarna::base::math::scaling4f (float uniformScaleFactor)
 
Matrix4f LibCarna::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 LibCarna::base::math::rotation4f (const Vector &v, float radians)
 
Matrix3f LibCarna::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 LibCarna::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.
 
template<typename VectorElementType , int rows, typename WType >
Eigen::Matrix< VectorElementType, 4, 1 > LibCarna::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 > LibCarna::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 LibCarna::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 LibCarna::base::math::plane4f (const Vector3f &normal, const Vector3f &support)
 
float LibCarna::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 LibCarna::base::math::maxAbsElement (const Matrix &m)
 Returns \(\max_{i,j} \left|m_{i,j}\right|\) where $m$ is m.
 
Matrix4f LibCarna::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.
 
Matrix4f LibCarna::base::math::frustum4f (float fovRadiansHorizontal, float heightOverWidth, float zNear, float zFar)
 
Matrix4f LibCarna::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 Sampler >
base::math::Vector3f LibCarna::base::math::computeFastGradient3f (Sampler func)
 Computes fast approximation of the gradient at the origin of the scalar field func.
 
template<typename ScalarType >
unsigned int LibCarna::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, rowsLibCarna::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 LibCarna::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, rowsLibCarna::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 LibCarna::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 LibCarna::base::math namespace and LIBCARNA_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.hpp.

Macro Definition Documentation

◆ LIBCARNA_FOR_VECTOR3UI

#define LIBCARNA_FOR_VECTOR3UI (   vecName,
  vecLimit 
)     LIBCARNA_FOR_VECTOR3UI_EX( vecName, vecLimit, LibCarna::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 LibCarna::base;
IntensityVolumeUInt16 data( math::Vector3ui( 100, 100, 30 ) );
/* Initialize all 'data' voxels with the lowest possible value.
*/
LIBCARNA_FOR_VECTOR3UI( p, data.size )
{
data.setVoxel( p, 0.f );
}
/* Verify the result.
*/
for( std::size_t i = 0; i < data.buffer().size(); ++i )
{
QCOMPARE( data.buffer()[ i ], 0 );
}
Represents an association.
#define LIBCARNA_FOR_VECTOR3UI(vecName, vecLimit)
Loops vecName over all where is vecLimit.
Definition math.hpp:745
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Definition math.hpp:203
Contains the core framework components.

Definition at line 745 of file math.hpp.

◆ LIBCARNA_FOR_VECTOR3UI_EX

#define LIBCARNA_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() )

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 731 of file math.hpp.