open_iA  2020.04
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 "open_iA_Core_export.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <limits>
#include <numeric>
#include <vector>
Include dependency graph for iAMathUtility.h:
This graph shows which files directly or indirectly include this file:

Typedefs

typedef std::vector< double > FuncType
 

Functions

template<typename T >
clamp (T const min, T const max, T const value)
 Make sure the given value is inside the given range. More...
 
open_iA_Core_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 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...
 
open_iA_Core_API FuncType derivative (FuncType const &func)
 Calculate first derivative of a given function. More...
 
open_iA_Core_API double gaussian (double x, double sigma)
 Compute Gaussian function for the given value x and parameter sigma (mean = 0). More...
 
open_iA_Core_API FuncType gaussianKernel (double kernelSigma, size_t kernelSteps)
 Compute a gaussian kernel with the given sigma (mean = 0). More...
 
open_iA_Core_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...
 
open_iA_Core_API FuncType getNormedRanks (FuncType const &func)
 Compute ranks for a given list of values. More...
 
template<typename T >
invertValue (T const *range, T const value)
 Invert value in a given range. 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] if min is bigger than max, a reverse mapping is applied 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...
 
open_iA_Core_API double mean (FuncType const &func)
 Compute the mean of a function. More...
 
template<typename SrcType >
double minMaxNormalize (SrcType const minSrcVal, SrcType const maxSrcVal, SrcType const value)
 apply minmax normalization if min is bigger than max, a reverse mapping is applied More...
 
template<typename SrcType >
double normalizedToMinMax (SrcType const minSrcVal, SrcType const maxSrcVal, SrcType const value)
 
open_iA_Core_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)
 
open_iA_Core_API double spearmansCorrelationCoefficient (FuncType const &func1, FuncType const &func2)
 Calculate the Spearman's correlation coefficient between two functions. More...
 
open_iA_Core_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...
 
open_iA_Core_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  min,
T const  max,
T const  value 
)

Make sure the given value is inside the given range.

Parameters
minthe minimum value which should be returned
maxthe 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()

open_iA_Core_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.

◆ 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 https://stackoverflow.com/a/41405501/671366

◆ derivative()

open_iA_Core_API FuncType derivative ( FuncType const &  func)

Calculate first derivative of a given function.

◆ gaussian()

open_iA_Core_API double gaussian ( double  x,
double  sigma 
)

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

◆ gaussianKernel()

open_iA_Core_API FuncType gaussianKernel ( double  kernelSigma,
size_t  kernelSteps 
)

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

◆ gaussianSmoothing()

open_iA_Core_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()

open_iA_Core_API FuncType getNormedRanks ( FuncType const &  func)

Compute ranks for a given list of values.

◆ 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

◆ linterp()

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

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
if norm was in interval [minSrcVal..maxSrcVal], the corresponding mapped value in interval [0..1]

◆ 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()

open_iA_Core_API double mean ( FuncType const &  func)

Compute the mean of a function.

◆ minMaxNormalize()

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

apply minmax normalization 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)

◆ normalizedToMinMax()

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

◆ pearsonsCorrelationCoefficient()

open_iA_Core_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()

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

Calculate the Spearman's correlation coefficient between two functions.

◆ standardDeviation()

open_iA_Core_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()

open_iA_Core_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).