ImFusion SDK 4.3
ExprBase Class Referenceabstract

#include <ImFusion/ImageMath/Poly/ExprBase.h>

Base class for expressions (non-templated) (needs to be empty in order to enable empty base class optimization!) More...

+ Inheritance diagram for ExprBase:

Detailed Description

Base class for expressions (non-templated) (needs to be empty in order to enable empty base class optimization!)

ExprBase provides a (non-templated) base class for arithmetic operations on ImFusion images. This class can be used in interfaces and provides an interface in order to evaluate a arithmetic expression into a SharedImage or a SharedImageSet. If the expression is fully known at compile-time using the ExprBaseTpl is encouraged! This subclass provides a compile time optimization of expressions using the curiously recurring template pattern (CRTP).

Note
All images within an expression are assumed to have the same size and spacing and the same matrix. I.e. there is a direct correspondence between the pixels in each image.

Example usage for polymorphic 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);
// Setup a polymorphic expression
std::shared_ptr<ExprBase> expr1 = std::make_shared<BinaryExpr<add>>(img1Expr.uniquePolyWrapper(), img2Expr.uniquePolyWrapper());
// expr1 represents the same arithmetic expression as above but the evaluation will be slower due to the polymorphic overhead.
expr1 = expr1 * img1Expr.uniquePolyWrapper();
// Evaluate the expression into img4
expr1->eval(img4);
Specialization of ExprBase for a image leaf, i.e.
Definition ForwardDeclarations.h:20
T make_shared(T... args)

Public Types

enum class  ExprType { Scalar = 0 , SharedImage = 1 , SharedImageSet = 2 , Variable = 3 }
 

Public Member Functions

virtual std::unique_ptr< ExprBaseclone () const =0
 Clone the current expression. May not return nullptr.
 
virtual std::unique_ptr< ExprBaseconvertToSharedImgExpr (std::size_t index) const =0
 Convert a SharedImageSet expression to a SharedImage expression.
 
ImageDescriptor imgDesc () const
 Return ImageDescriptor of the expression (forwards to the ExprInterface)
 
int numImgs () const
 Return the number of images of the expression (forwards to the ExprInterface)
 
virtual ExprType exprType () const =0
 Return the ImFusion image type, i.e. NoImage, SharedImage, SharedImageSet.
 
template<typename T, typename ImgType = void>
auto evaluateIntoImage (bool clearShiftScale=false) const
 Evaluate expression into an image.
 

Variable substitution

virtual std::unique_ptr< ExprBasesubstituteVariableWithImg (const SharedImage &variable) const =0
 
virtual std::unique_ptr< ExprBasesubstituteVariableWithImg (const SharedImageSet &variable) const =0
 Substitute all variables with variable.
 

Evaluate an expression into an Array (polymorphic version)

void eval (Array< SharedImage, void > &img, const SharedImage *variable) const
 
void eval (Array< SharedImage, void > &img) const
 Evaluate into SharedImage.
 
void eval (Array< SharedImageSet, void > &img, const SharedImageSet *variable) const
 Evaluate into SharedImageSet. Variable leafs will be substituted with variable.
 
void eval (Array< SharedImageSet, void > &img) const
 Evaluate into SharedImageSet.
 

Convert to GlExprInterface

internal::GlExprInterfaceglExprInterface ()
 
const internal::GlExprInterfaceglExprInterface () const
 

Convert to ExprInterface

ExprInterfaceexprInterface ()
 
const ExprInterfaceexprInterface () const
 

Special functions

template<typename Op>
reduction_type reduce (std::vector< vec4i > *arg=nullptr) const
 
std::unique_ptr< ExprBaseforceCPU () const
 Forces CPU execution.
 
std::unique_ptr< ExprBaseforceGPU () const
 Forces GPU execution.
 

Channel swizzling

std::unique_ptr< ExprBasechannelSwizzle (const std::vector< std::size_t > &indices) const
 

Predefined unary operators

template<typename CastT>
std::unique_ptr< ExprBasecast () const
 

Predefined reduction operators

 ADD_REDUCTION_OP_DEF (sum, add)
 
 ADD_REDUCTION_OP_DEF (prod, mult)
 
 ADD_ARG_REDUCTION_OP_DEF (min, min)
 
 ADD_ARG_REDUCTION_OP_DEF (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
 

Implementation for eval()

virtual void evalImpl (Array< SharedImage, void > &img) const =0
 
virtual void evalImpl (Array< SharedImageSet, void > &img) const =0
 Implementation functionality used in eval()
 

Member Function Documentation

◆ clone()

virtual std::unique_ptr< ExprBase > clone ( ) const
pure virtual

Clone the current expression. May not return nullptr.

Implemented in BinaryOp< Op >, CastWrapper< CastT >, ChannelSwizzleView, DeviceStrategyWrapper, PolyWrapper< ExprT >, and UnaryOp< Op >.

◆ substituteVariableWithImg() [1/2]

virtual std::unique_ptr< ExprBase > substituteVariableWithImg ( const SharedImage & variable) const
pure virtual

Substitute all variables with variable

Implemented in BinaryOp< Op >, CastWrapper< CastT >, ChannelSwizzleView, DeviceStrategyWrapper, PolyWrapper< ExprT >, and UnaryOp< Op >.

◆ substituteVariableWithImg() [2/2]

virtual std::unique_ptr< ExprBase > substituteVariableWithImg ( const SharedImageSet & variable) const
pure virtual

Substitute all variables with variable.

Implemented in BinaryOp< Op >, CastWrapper< CastT >, ChannelSwizzleView, DeviceStrategyWrapper, PolyWrapper< ExprT >, and UnaryOp< Op >.

◆ eval()

void eval ( Array< SharedImage, void > & img,
const SharedImage * variable ) const

Evaluate into SharedImage. Variable leafs will be substituted with variable.

◆ convertToSharedImgExpr()

virtual std::unique_ptr< ExprBase > convertToSharedImgExpr ( std::size_t index) const
pure virtual

◆ exprType()

virtual ExprType exprType ( ) const
pure virtual

◆ reduce()

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

std::unique_ptr< ExprBase > channelSwizzle ( const std::vector< std::size_t > & indices) const
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].

◆ mean()

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

◆ l1Norm()

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

◆ squaredl2Norm()

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

◆ l2Norm()

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

◆ lpNorm()

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

◆ lInfNorm()

Eigen::Matrix< double, Eigen::Dynamic, 1 > lInfNorm ( ) const
Returns
the reduction using linfnorm of *this

◆ evalImpl() [1/2]

virtual void evalImpl ( Array< SharedImage, void > & img) const
protectedpure virtual

◆ evalImpl() [2/2]

virtual void evalImpl ( Array< SharedImageSet, void > & img) const
protectedpure virtual

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