ImFusion SDK 4.3
ExprBaseTpl< ImplType > Class Template Reference

#include <ImFusion/ImageMath/Tpl/ExprBaseTpl.h>

Base class for compile-time optimized expressions (curiously recurring template pattern (CRTP)) More...

+ Inheritance diagram for ExprBaseTpl< ImplType >:

Detailed Description

template<typename ImplType>
class ImFusion::ImageMath::ExprBaseTpl< ImplType >

Base class for compile-time optimized expressions (curiously recurring template pattern (CRTP))

Template Parameters
ImplTypeChild class

ExprBaseTpl provides a compile-time optimized interface for arithmetic expressions on ImFusion images. Arithmetic operations are combined into a ExprBaseTpl object expressing the full expression. This expression is evaluation if assigned to a Array object. No temporary images are required and each pixel is only touched once while evaluating the full expression tree at once.

Example usage for compile-time optimized expressions:

SharedImage img1(...);
SharedImage img2(...);
SharedImage img3(...);
SharedImage img4(...);
// Expression wrapper for SharedImage
Array<SharedImage> img1Expr(img1);
// Expression wrapper for SharedImage
Array<SharedImage> img2Expr(img2);
// Expression wrapper for SharedImage
Array<SharedImage> img3Expr(img3);
// Expression wrapper for SharedImage
Array<SharedImage> img4Expr(img4);
// Expression object
auto expr1 = (img1Expr + img2Expr) * img3Expr;
// Evaluation of expr1 into img4
img4Expr = expr1;
Specialization of ExprBase for a image leaf, i.e.
Definition ForwardDeclarations.h:20
Image shared on multiple devices.
Definition SharedImage.h:86

Public Member Functions

const auto & get () const
 get a const reference to this with the actual type
 
auto & get ()
 get a reference to this with the actual type
 

Special functions

auto polyWrapper () const
 
auto uniquePolyWrapper () const
 
auto sharedPolyWrapper () const
 
template<typename Op, typename RhsT>
auto binaryOp (const ExprBaseTpl< RhsT > &rhs, const Op &func=Op()) const
 
template<typename Op, typename RhsT>
auto binaryOp (RhsT rhs, const Op &func=Op(), typename std::enable_if< std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 
template<typename Op, typename RhsT, int Dim, int Options, int MaxRows, int MaxCols>
auto binaryOp (Eigen::Matrix< RhsT, Dim, 1, Options, MaxRows, MaxCols > rhs, const Op &func=Op(), typename std::enable_if< std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 
template<typename Op, typename StringOp, typename RhsT>
auto binaryOp (const ExprBaseTpl< RhsT > &rhs, const Op &func, const StringOp &stringFunc) const
 
template<typename Op, typename StringOp, typename RhsT>
auto binaryOp (RhsT rhs, const Op &func, const StringOp &stringFunc, typename std::enable_if< std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 
template<typename Op, typename StringOp, typename RhsT, int Dim, int Options, int MaxRows, int MaxCols>
auto binaryOp (Eigen::Matrix< RhsT, Dim, 1, Options, MaxRows, MaxCols > rhs, const Op &func, const StringOp &stringFunc, typename std::enable_if< std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 
template<typename Op>
auto unaryOp (const Op &func=Op()) const
 
template<typename Op, typename StringOp>
auto unaryOp (const Op &func, const StringOp &stringFunc) const
 
template<typename Op>
reduction_type reduce (std::vector< vec4i > *arg=nullptr) const
 
auto forceCPU () const
 Forces CPU execution.
 
auto forceGPU () const
 Forces GPU execution.
 

Channel swizzling

auto channelSwizzle (const std::vector< std::size_t > &indices) const
 
template<size_t i>
auto head ()
 
 ADD_SPECIAL_SWIZZLE (x, {0})
 
 ADD_SPECIAL_SWIZZLE (y, {1})
 
 ADD_SPECIAL_SWIZZLE (z, {2})
 
 ADD_SPECIAL_SWIZZLE (w, {3})
 
 ADD_SPECIAL_SWIZZLE (r, {0})
 
 ADD_SPECIAL_SWIZZLE (g, {1})
 
 ADD_SPECIAL_SWIZZLE (b, {2})
 
 ADD_SPECIAL_SWIZZLE (a, {3})
 
 ADD_SPECIAL_SWIZZLE (xy, std::vector< size_t >({0, 1}))
 
 ADD_SPECIAL_SWIZZLE (rg, std::vector< size_t >({0, 1}))
 
 ADD_SPECIAL_SWIZZLE (xyz, std::vector< size_t >({0, 1, 2}))
 
 ADD_SPECIAL_SWIZZLE (xyzw, std::vector< size_t >({0, 1, 2, 3}))
 
 ADD_SPECIAL_SWIZZLE (rgb, std::vector< size_t >({0, 1, 2}))
 
 ADD_SPECIAL_SWIZZLE (rgba, std::vector< size_t >({0, 1, 2, 3}))
 
auto streamChannels (int numStreamedChannels) const
 
template<typename T>
auto substituteVariableWithImg (T &img) const
 

Arithmetic operators

auto operator- () const
 

Predefined unary operators

template<typename CastT>
auto cast () const
 
auto storageToOriginal (const ImageDescriptor &desc)
 Apply shift/scale to the operand,.
 
auto originalToStorage (const ImageDescriptor &desc)
 Apply shift/scale to the operand,.
 
template<typename Op>
auto channelReduction ()
 
 ADD_CHANNEL_REDUCTION_OPERATOR (channelSum, add)
 
 ADD_CHANNEL_REDUCTION_OPERATOR (channelProd, mult)
 
 ADD_CHANNEL_REDUCTION_OPERATOR (channelMax, max)
 
 ADD_CHANNEL_REDUCTION_OPERATOR (channelMin, min)
 
 ADD_CHANNEL_REDUCTION_OPERATOR (length, length)
 
auto channelMean ()
 
auto squaredLength () const
 
template<typename RhsT>
auto channelDistance (const ExprBaseTpl< RhsT > &other) const
 
template<typename T, int Dim>
auto channelDistance (const Eigen::Matrix< T, Dim, 1 > c)
 
template<typename RhsT>
auto dot (const ExprBaseTpl< RhsT > &other) const
 
template<typename VariableT>
auto stashThenApply (const ExprBaseTpl< VariableT > &varExpr) const
 
template<typename VarT = double>
auto hnormalized () const
 
template<typename VarT = double>
auto normalized () const
 
auto homogeneous () const
 
auto appendZero () const
 

Predefined tenary operators

template<typename LhsT, typename RhsT>
auto select (const ExprBaseTpl< LhsT > &lhs, const ExprBaseTpl< RhsT > &rhs) const
 Ternary (condition.x ? if_true : if_false) operator.
 
template<typename LhsT, typename RhsT>
auto select (LhsT lhs, RhsT rhs, typename std::enable_if< std::is_arithmetic_v< LhsT > &&std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 Ternary (condition.x ? if_true : if_false) operator.
 
template<typename LhsT, typename RhsT>
auto select (LhsT lhs, const ExprBaseTpl< RhsT > &rhs, typename std::enable_if< std::is_arithmetic_v< LhsT > >::type *=nullptr) const
 Ternary (condition.x ? if_true : if_false) operator.
 
template<typename LhsT, typename RhsT>
auto select (const ExprBaseTpl< LhsT > &lhs, RhsT rhs, typename std::enable_if< std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 Ternary (condition.x ? if_true : if_false) operator.
 

Predefined reduction operators

 ADD_REDUCTION_OPERATOR (sum, add)
 
 ADD_REDUCTION_OPERATOR (prod, mult)
 
 ADD_ARG_REDUCTION_OPERATOR (min, min)
 
 ADD_ARG_REDUCTION_OPERATOR (max, max)
 
Eigen::Matrix< double, Eigen::Dynamic, 1 > mean () const
 
Eigen::Matrix< double, Eigen::Dynamic, 1 > l1Norm () const
 
Eigen::Matrix< double, Eigen::Dynamic, 1 > squaredl2Norm () const
 
Eigen::Matrix< double, Eigen::Dynamic, 1 > l2Norm () const
 
Eigen::Matrix< double, Eigen::Dynamic, 1 > lpNorm (double p) const
 
Eigen::Matrix< double, Eigen::Dynamic, 1 > lInfNorm () const
 

Operations that create new images

template<typename ImgType = void>
auto evaluateIntoImage (bool clearShiftScale=false) const
 Create an empty image and evaluate this expression into it.
 

Special operations

auto toMask () const
 
auto toDeformation (const ImageDescriptorWorld imgDesc) const
 
template<bool includeDeformation = false>
auto resample (const ImageDescriptorWorld &inputDesc, const ImageDescriptorWorld &outputDesc) const
 
template<bool includeDeformation = false, typename T = SharedImage>
auto resample (SharedImage &inputDesc, SharedImage &outputDesc, std::enable_if_t< std::is_same_v< T, SharedImage > > *=nullptr) const
 
template<bool includeDeformation = false, typename T = SharedImageSet>
auto resample (SharedImageSet &inputDesc, SharedImageSet &outputDesc, std::enable_if_t< std::is_same_v< T, SharedImageSet > > *=nullptr) const
 

Member Function Documentation

◆ polyWrapper()

template<typename ImplType>
auto polyWrapper ( ) const
inline
Returns
a polymorphic expression which wraps *this

◆ uniquePolyWrapper()

template<typename ImplType>
auto uniquePolyWrapper ( ) const
inline
Returns
a unique pointer to a polymorphic expression which wraps *this

◆ sharedPolyWrapper()

template<typename ImplType>
auto sharedPolyWrapper ( ) const
inline
Returns
a shared pointer to a polymorphic expression which wraps *this

◆ binaryOp() [1/2]

template<typename ImplType>
template<typename Op, typename RhsT>
auto binaryOp ( const ExprBaseTpl< RhsT > & rhs,
const Op & func = Op() ) const
inline
Returns
an expression which represents the binary expression Op with *this as left-hand argument and rhs as right-hand argument, respectively

Op must provide a binary functor interface, e.g.:

struct Op
{
template <typename LhsT, typename RhsT>
IMFUSION_STRONG_INLINE auto operator()(LhsT lhs, RhsT rhs) const
{
...
}
std::string evalString(const std::string& lhsStr, const std::string& rhsStr) const
{
...
}
};

◆ binaryOp() [2/2]

template<typename ImplType>
template<typename Op, typename StringOp, typename RhsT>
auto binaryOp ( const ExprBaseTpl< RhsT > & rhs,
const Op & func,
const StringOp & stringFunc ) const
inline
Returns
an expression which represents the binary expression given as the functions of type Op StringOp with *this as left-hand argument and rhs as right-hand argument, respectively

Should provide lambdas for CPU as well as GPU evaluation. E.g.:

expr.binaryOp([](LhsT lhs, RhsT rhs) { return lhs + rhs; }, [](const std::string& lhsStr, const std::string& rhsStr) { return "(" + lhsStr
")+(" + rhsStr + ")"; };

◆ unaryOp() [1/2]

template<typename ImplType>
template<typename Op>
auto unaryOp ( const Op & func = Op()) const
inline
Returns
an expression which represents the binary expression Op with *this as argument

Op must provide a unary functor interface, e.g.:

struct Op
{
template <typename OperandT>
IMFUSION_STRONG_INLINE OperandT operator()(OperandT operand) const
{
...
}
std::string evalString(const std::string& operandStr) const
{
...
}
};

◆ unaryOp() [2/2]

template<typename ImplType>
template<typename Op, typename StringOp>
auto unaryOp ( const Op & func,
const StringOp & stringFunc ) const
inline
Returns
an expression which represents the binary expression given as the functions of type Op StringOp with *this as left-hand argument and rhs as right-hand argument, respectively

Should provide lambdas for CPU as well as GPU evaluation. E.g.:

expr.unaryOp([](OperandT operand) { return std::abs(operand); }, [](const std::string& operandStr) { return "abs(" + operandStr ")"; };

◆ reduce()

template<typename ImplType>
template<typename Op>
reduction_type reduce ( std::vector< vec4i > * arg = nullptr) const
inline
Returns
an expression which represents a reduction of *this using the operator Op

◆ channelSwizzle()

template<typename ImplType>
auto channelSwizzle ( const std::vector< std::size_t > & indices) const
inline
Returns
an expression which swizzles the channel indices of *this according to indices, i.e. the channel 0 gets mapped to the channel indices[0].

◆ streamChannels()

template<typename ImplType>
auto streamChannels ( int numStreamedChannels) const
inline
Returns
an expression which streams *this over numStreamedChannels channels

◆ substituteVariableWithImg()

template<typename ImplType>
template<typename T>
auto substituteVariableWithImg ( T & img) const
inline
Returns
an expression which replaces each Variable in the expression *this by img

◆ operator-()

template<typename ImplType>
auto operator- ( ) const
inline
Returns
an expression of the opposite of *this

◆ storageToOriginal()

template<typename ImplType>
auto storageToOriginal ( const ImageDescriptor & desc)
inline

Apply shift/scale to the operand,.

See also
ImageDescriptor::storageToOriginal

◆ originalToStorage()

template<typename ImplType>
auto originalToStorage ( const ImageDescriptor & desc)
inline

Apply shift/scale to the operand,.

See also
ImageDescriptor::originalToStorage

◆ mean()

template<typename ImplType>
Eigen::Matrix< double, Eigen::Dynamic, 1 > mean ( ) const
inline
Returns
the reduction using mean of *this

◆ l1Norm()

template<typename ImplType>
Eigen::Matrix< double, Eigen::Dynamic, 1 > l1Norm ( ) const
inline
Returns
the reduction using l1norm of *this

◆ squaredl2Norm()

template<typename ImplType>
Eigen::Matrix< double, Eigen::Dynamic, 1 > squaredl2Norm ( ) const
inline
Returns
the reduction using the squared l2-norm of *this

◆ l2Norm()

template<typename ImplType>
Eigen::Matrix< double, Eigen::Dynamic, 1 > l2Norm ( ) const
inline
Returns
the reduction using l2norm of *this

◆ lpNorm()

template<typename ImplType>
Eigen::Matrix< double, Eigen::Dynamic, 1 > lpNorm ( double p) const
inline
Returns
the reduction using lpnorm of *this

◆ lInfNorm()

template<typename ImplType>
Eigen::Matrix< double, Eigen::Dynamic, 1 > lInfNorm ( ) const
inline
Returns
the reduction using lpnorm of *this

The documentation for this class was generated from the following files:
Search Tab / S to search, Esc to close