open_iA 2021.08
A tool for the visual analysis and processing of volumetric datasets, with a focus on industrial computed tomography.
Typedefs | Functions
iAMathUtility.h File Reference
#include "iAbase_export.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <limits>
#include <numeric>
#include <vector>
#include <QVector>

Typedefs

typedef std::vector< double > FuncType
 

Functions

template<typename T >
clamp (T const minVal, T const maxVal, T const value)
 Make sure the given value is inside the given range. More...
 
iAbase_API double covariance (FuncType const &func1, FuncType const &func2, double mean1=std::numeric_limits< double >::infinity(), double mean2=std::numeric_limits< double >::infinity(), bool correctDF=true)
 Compute covariance between two functions. More...
 
template<typename OutContainerT = QVector<double>, typename ValueT = double, typename InContainerT >
OutContainerT createHistogram (const InContainerT &inData, typename OutContainerT::size_type binCount, ValueT &minValue, ValueT &maxValue, bool discrete=false)
 compute histogram from given values More...
 
template<typename RealType >
bool dblApproxEqual (RealType a, RealType b, RealType tolerance=std::numeric_limits< RealType >::epsilon())
 Checks whether two real values are equal, given a certain tolerance. More...
 
iAbase_API FuncType derivative (FuncType const &func)
 Calculate first derivative of a given function. More...
 
iAbase_API double gaussian (double x, double sigma)
 Compute Gaussian function for the given value x and parameter sigma (mean = 0). More...
 
iAbase_API FuncType gaussianKernel (double kernelSigma, size_t kernelSteps)
 Compute a gaussian kernel with the given sigma (mean = 0). More...
 
iAbase_API FuncType gaussianSmoothing (FuncType const &data, double kernelSigma, int kernelSteps)
 Convolutes the given function with a Gaussian kernel with the given sigma and steps. More...
 
iAbase_API FuncType getNormedRanks (FuncType const &func)
 Compute ranks for a given list of values. More...
 
template<typename T >
bool inRange (T const *range, T const value)
 Check whether a value is in a given range. More...
 
template<typename T >
invertValue (T const *range, T const value)
 Invert value in a given range. More...
 
template<typename T1 , typename T2 >
bool isApproxEqual (T1 a, T2 b, T1 tolerance=std::numeric_limits< T1 >::epsilon())
 comparison of two real type values - merge with above! More...
 
template<typename T >
linterp (const T a, const T b, const T t)
 Linear interpolation in a given range. More...
 
template<typename DstType >
DstType mapNormTo (DstType minDstVal, DstType maxDstVal, double norm)
 Map value from "norm" range [0..1] to the given range. More...
 
template<typename T >
mapToNorm (const T *range, const T value)
 Map values from a given range to the "normalized" range [0..1]. More...
 
template<typename SrcType >
double mapToNorm (SrcType const minSrcVal, SrcType const maxSrcVal, SrcType const value)
 Map value from given interval to "norm" interval [0..1]. More...
 
template<typename SrcType >
double mapToNormNoClamp (SrcType const minSrcVal, SrcType const maxSrcVal, SrcType const value)
 Map value from given interval to "norm" interval [0..1]. More...
 
template<typename SrcType , typename DstType >
DstType mapValue (SrcType minSrcVal, SrcType maxSrcVal, DstType minDstVal, DstType maxDstVal, SrcType value)
 Map value from one range to another. More...
 
template<typename T >
mapValue (T const *rangeSrc, T const *rangeDst, T const value)
 Map value from one range to another. More...
 
iAbase_API double mean (FuncType const &func)
 Compute the mean of a function. More...
 
iAbase_API double pearsonsCorrelationCoefficient (FuncType const &func1, FuncType const &func2)
 Calculate the Pearson's correlation coefficient between two functions. More...
 
template<typename T >
round (T const &number)
 Round a number to the nearest integer representation (by "round half away from zero" method). More...
 
template<typename T >
std::vector< size_t > sort_indexes (const std::vector< T > &v)
 
iAbase_API double spearmansCorrelationCoefficient (FuncType const &func1, FuncType const &func2)
 Calculate the Spearman's correlation coefficient between two functions. More...
 
iAbase_API double standardDeviation (FuncType const &func, double meanVal=std::numeric_limits< double >::infinity(), bool correctDF=true)
 Compute the standard deviation of a function. mean can be given (to improve speed). More...
 
iAbase_API double variance (FuncType const &func, double meanVal=std::numeric_limits< double >::infinity(), bool correctDF=true)
 Compute the variation of a function. If known, mean can be given (to improve speed). More...
 

Typedef Documentation

◆ FuncType

typedef std::vector<double> FuncType

Function Documentation

◆ clamp()

template<typename T >
T clamp ( T const  minVal,
T const  maxVal,
T const  value 
)

Make sure the given value is inside the given range.

Parameters
minValthe minimum value which should be returned
maxValthe maximum value which should be returned
valuethe value to check
Returns
min if the given value is smaller or equal to min, max if the given value is bigger or equal to max, or the value itself if it is in between min and max

◆ covariance()

iAbase_API double covariance ( FuncType const &  func1,
FuncType const &  func2,
double  mean1 = std::numeric_limits< double >::infinity(),
double  mean2 = std::numeric_limits< double >::infinity(),
bool  correctDF = true 
)

Compute covariance between two functions.

◆ createHistogram()

template<typename OutContainerT = QVector<double>, typename ValueT = double, typename InContainerT >
OutContainerT createHistogram ( const InContainerT &  inData,
typename OutContainerT::size_type  binCount,
ValueT &  minValue,
ValueT &  maxValue,
bool  discrete = false 
)

compute histogram from given values

◆ dblApproxEqual()

template<typename RealType >
bool dblApproxEqual ( RealType  a,
RealType  b,
RealType  tolerance = std::numeric_limits<RealType>::epsilon() 
)

Checks whether two real values are equal, given a certain tolerance.

inspired by great points about floating point equals at https://stackoverflow.com/a/41405501

◆ derivative()

iAbase_API FuncType derivative ( FuncType const &  func)

Calculate first derivative of a given function.

◆ gaussian()

iAbase_API double gaussian ( double  x,
double  sigma 
)

Compute Gaussian function for the given value x and parameter sigma (mean = 0).

◆ gaussianKernel()

iAbase_API FuncType gaussianKernel ( double  kernelSigma,
size_t  kernelSteps 
)

Compute a gaussian kernel with the given sigma (mean = 0).

◆ gaussianSmoothing()

iAbase_API FuncType gaussianSmoothing ( FuncType const &  data,
double  kernelSigma,
int  kernelSteps 
)

Convolutes the given function with a Gaussian kernel with the given sigma and steps.

TODO: number of steps could be calculated from sigma (cut off kernel when factor gets very small)

◆ getNormedRanks()

iAbase_API FuncType getNormedRanks ( FuncType const &  func)

Compute ranks for a given list of values.

◆ inRange()

template<typename T >
bool inRange ( T const *  range,
T const  value 
)

Check whether a value is in a given range.

Parameters
rangethe range given as minimum (stored at index 0) and maximum (stored at index 1)
valuethe value to be checked. return true if value in range (bounds included, i.e. returns true if equal to minimum or maximum), false otherwise

◆ invertValue()

template<typename T >
T invertValue ( T const *  range,
T const  value 
)

Invert value in a given range.

Example: invertValue(range=[0, 1], value=0.2) = 0.8; invertValue(range=[1,2], value=1.3) = 1.7

Parameters
rangean array of size 2 with minimum and maximum value of the range
valuethe value to be inverted.
Returns
the inverted value

◆ isApproxEqual()

template<typename T1 , typename T2 >
bool isApproxEqual ( T1  a,
T2  b,
T1  tolerance = std::numeric_limits<T1>::epsilon() 
)

comparison of two real type values - merge with above!

◆ linterp()

template<typename T >
T linterp ( const T  a,
const T  b,
const T  t 
)

Linear interpolation in a given range.

Parameters
aminimum of the interpolation range
bmaximum of the interpolation range
ta value from the range [0..1] specifying the interpolation position

◆ mapNormTo()

template<typename DstType >
DstType mapNormTo ( DstType  minDstVal,
DstType  maxDstVal,
double  norm 
)

Map value from "norm" range [0..1] to the given range.

Parameters
minDstValminimum value of destination range
maxDstValmaximum value of destination range
norma value in range [0..1]
Returns
if norm was in [0..1], the corresponding mapped value in range [minDstVal..maxDstVal]

◆ mapToNorm() [1/2]

template<typename T >
T mapToNorm ( const T *  range,
const T  value 
)
inline

Map values from a given range to the "normalized" range [0..1].

if min is bigger than max, a reverse mapping is applied

Parameters
rangean array of size 2 with minimum and maximum value of the source range
valuethe value to be mapped from the source range to the destination range
Returns
the mapped value; in case the given value is outside given min/max, the value will still be clamped to the range [0..1]

◆ mapToNorm() [2/2]

template<typename SrcType >
double mapToNorm ( SrcType const  minSrcVal,
SrcType const  maxSrcVal,
SrcType const  value 
)

Map value from given interval to "norm" interval [0..1].

if min is bigger than max, a reverse mapping is applied

Parameters
minSrcValminimum value of source interval
maxSrcValmaximum value of source interval
valuea value in source interval
Returns
the corresponding mapped value in interval [0..1] (0 if input value < minSrcVal, 1 if input value > maxSrcVal)

◆ mapToNormNoClamp()

template<typename SrcType >
double mapToNormNoClamp ( SrcType const  minSrcVal,
SrcType const  maxSrcVal,
SrcType const  value 
)

Map value from given interval to "norm" interval [0..1].

if min is bigger than max, a reverse mapping is applied

Parameters
minSrcValminimum value of source interval
maxSrcValmaximum value of source interval
valuea value in source interval
Returns
the corresponding mapped value = (value - minSrcVal) / (maxSrcVal - minSrcVal) Note that if the input value is not between minSrcVal and maxSrcVal, the return value is NOT guaranteed to be in the interval 0..1. If you require the return value to be in that interval, use mapToNorm instead!

◆ mapValue() [1/2]

template<typename SrcType , typename DstType >
DstType mapValue ( SrcType  minSrcVal,
SrcType  maxSrcVal,
DstType  minDstVal,
DstType  maxDstVal,
SrcType  value 
)

Map value from one range to another.

Parameters
minSrcValminimum value of source range
maxSrcValmaximum value of source range
minDstValminimum value of destination range
maxDstValmaximum value of destination range
valuethe value to be mapped from the source range to the destination range
Returns
if value was in range [minSrcVal..maxSrcVal], the corresponding mapped value in range [minDstVal..maxDstVal]

◆ mapValue() [2/2]

template<typename T >
T mapValue ( T const *  rangeSrc,
T const *  rangeDst,
T const  value 
)
inline

Map value from one range to another.

Parameters
rangeSrcan array of size 2 with minimum and maximum value of the source range
rangeDstan array of size 2 with minimum and maximum value of the destination range
valuethe value to be mapped from the source range to the destination range
Returns
if value was in range [minSrcVal..maxSrcVal], the corresponding mapped value in range [minDstVal..maxDstVal]

◆ mean()

iAbase_API double mean ( FuncType const &  func)

Compute the mean of a function.

◆ pearsonsCorrelationCoefficient()

iAbase_API double pearsonsCorrelationCoefficient ( FuncType const &  func1,
FuncType const &  func2 
)

Calculate the Pearson's correlation coefficient between two functions.

◆ round()

template<typename T >
T round ( T const &  number)

Round a number to the nearest integer representation (by "round half away from zero" method).

Parameters
numberthe number to round
Returns
the rounded number

◆ sort_indexes()

template<typename T >
std::vector< size_t > sort_indexes ( const std::vector< T > &  v)

◆ spearmansCorrelationCoefficient()

iAbase_API double spearmansCorrelationCoefficient ( FuncType const &  func1,
FuncType const &  func2 
)

Calculate the Spearman's correlation coefficient between two functions.

◆ standardDeviation()

iAbase_API double standardDeviation ( FuncType const &  func,
double  meanVal = std::numeric_limits< double >::infinity(),
bool  correctDF = true 
)

Compute the standard deviation of a function. mean can be given (to improve speed).

◆ variance()

iAbase_API double variance ( FuncType const &  func,
double  meanVal = std::numeric_limits< double >::infinity(),
bool  correctDF = true 
)

Compute the variation of a function. If known, mean can be given (to improve speed).