ImFusion C++ SDK 4.4.0
ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT > Class Template Reference

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

ImageMath class that can be used to substitute a multi-channel expression into another expression Typically, the expression being substituted is "expensive" relative to the "cheap" expression being substituted into. More...

Inheritance diagram for ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >:

Detailed Description

template<typename ExprT, typename VariableT>
class ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >

ImageMath class that can be used to substitute a multi-channel expression into another expression Typically, the expression being substituted is "expensive" relative to the "cheap" expression being substituted into.

The prototypical example is expr/length(expr). Here the map x -> x/length(x) is "cheap" to evaluate, but relies on x being evaluated multiple times, which is expensive if an expression is substituted for x. This class "stashes" the evaluation of the expensive expression for all channels, and only then evaluates the "cheap" expression on the result. The example of the map x -> x/length(x) can be realized in the following way:

auto expensiveExpr = .... // Some expensive ImageMath expression
auto var = StashVariable<double>(3);
auto cheapExpr = var/var.length();
auto normalized = StashTpl<decltype(expr),decltype(var)>(expr,var);
Helper Variable class for use with stashes.
Definition StashTpl.h:26
See also
also ExprBaseTpl::stashThenApply

Public Types

using imf_img_type = typename ExprT::imf_img_type
using var_type = typename ExprT::var_type
using expr_type = double

Public Member Functions

 StashTpl (const ExprT &expensiveExpression, const VariableT &cheapExpression)
 StashTpl (const StashTpl &other)
 Copy-constructor in order to rerun the variable substitution.
template<typename ImgT>
auto convertToMemImgExpr () const noexcept
auto convertToSharedImgExpr (std::size_t index) const
template<typename SubOperandT>
auto substituteVariable (const SubOperandT &operand) const
 Substitutes any Variable leaf.
IMFUSION_STRONG_INLINE expr_type eval (const std::size_t i, const vec4i &coord) const
GlExprInterfaceexpensiveExpression () override
const GlExprInterfaceexpensiveExpression () const override
const ExprT & expensiveExpressionRaw () const
GlExprInterfacecheapExpression () override
const GlExprInterfacecheapExpression () const override
ImageDescriptor imgDesc () const override
 Return ImageDescriptor of this expression. This reference is expected to remain the same while the class exists.
int numImgs () const override
 Return number of images of this expression.
DeviceStrategy deviceStrategy () const override
 Return DeviceStrategy of this expression.
Public Member Functions inherited from ImFusion::ImageMath::ExprBaseTpl< StashTpl< ExprT, VariableT > >
const auto & get () const
 get a const reference to this with the actual type
auto polyWrapper () const
auto uniquePolyWrapper () const
auto sharedPolyWrapper () const
auto binaryOp (const ExprBaseTpl< RhsT > &rhs, const Op &func=Op()) const
auto unaryOp (const Op &func=Op()) const
reduction_type reduce (std::vector< vec4i > *arg=nullptr) const
auto forceCPU () const
 Forces CPU execution.
auto forceGPU () const
 Forces GPU execution.
auto channelSwizzle (const std::vector< std::size_t > &indices) const
auto head ()
 ADD_SPECIAL_SWIZZLE (x, {0})
auto streamChannels (int numStreamedChannels) const
auto substituteVariableWithImg (T &img) const
auto operator- () const
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,.
auto channelReduction ()
 ADD_CHANNEL_REDUCTION_OPERATOR (channelSum, add)
auto channelMean ()
auto squaredLength () const
auto channelDistance (const ExprBaseTpl< RhsT > &other) const
auto dot (const ExprBaseTpl< RhsT > &other) const
auto stashThenApply (const ExprBaseTpl< VariableT > &varExpr) const
auto hnormalized () const
auto normalized () const
auto homogeneous () const
auto appendZero () const
auto select (const ExprBaseTpl< LhsT > &lhs, const ExprBaseTpl< RhsT > &rhs) const
 Ternary (condition.x ? if_true : if_false) operator.
 ADD_REDUCTION_OPERATOR (sum, add)
 ADD_ARG_REDUCTION_OPERATOR (min, min)
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
auto evaluateIntoImage (bool clearShiftScale=false) const
 Create an empty image and evaluate this expression into it.
auto toMask () const
auto toDeformation (const ImageDescriptorWorld imgDesc) const
auto resample (const ImageDescriptorWorld &inputDesc, const ImageDescriptorWorld &outputDesc) const
Public Member Functions inherited from ImFusion::ImageMath::internal::StashGl
std::string evalString (bool tagAndAssign=true) const override
 Print expression.
void tagAndAssignNames (std::unordered_map< internal::TaggingIndex, const void * > &taggedLeaves, std::unordered_map< std::type_index, int > &countPerLeafType, const std::string &prefix) const override
 We need to tag leaves and tell unique leaves that they are responsible to define the uniforms and set the shader arguments.
void getUniformDefinitionList (std::string &definitionList, const std::vector< int > &indices, const std::string &prefix) const override
 Collect uniform/sampler definitions.
void getVariableDefinitionList (std::string &definitionList, const std::vector< int > &indices, const std::string &prefix) const override
 Collect variable definitions.
int setArguments (GL::Program &p, const std::vector< int > &indices, const std::string &prefix) const override
 Set uniform/sampler arguments.
std::vector< GlExprInterface * > children () override
 Used for traversing the expression tree. Contains the immediate children of node.
std::vector< const GlExprInterface * > children () const override
 Used for traversing the expression tree. Contains the immediate children of node.
Public Member Functions inherited from ImFusion::ImageMath::internal::GlExprInterface
ExprInterfaceexprInterface ()
 Get image descriptor of the wrapped expression.
const ExprInterfaceexprInterface () const
virtual bool setMagFilter (ImageMath::MagFilter mag)
 Set interpolation behaviour of the current leaf (only).
virtual bool setWrap (ImageMath::Wrap wrap)
 Set interpolation behaviour of the current leaf (only).
bool setMagFilterRecursive (ImageMath::MagFilter mag)
 Set interpolation behaviour of the current leaf and all of its children.
bool setWrapRecursive (ImageMath::Wrap wrap)
 Set wrap behaviour of the current leaf and all of its children.

Static Public Attributes

static constexpr bool has_variable = ExprT::has_variable

Member Function Documentation

◆ expensiveExpression() [1/2]

template<typename ExprT, typename VariableT>
GlExprInterface & ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >::expensiveExpression ( )
inlineoverridevirtual

◆ expensiveExpression() [2/2]

template<typename ExprT, typename VariableT>
const GlExprInterface & ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >::expensiveExpression ( ) const
inlineoverridevirtual

◆ cheapExpression() [1/2]

template<typename ExprT, typename VariableT>
GlExprInterface & ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >::cheapExpression ( )
inlineoverridevirtual

◆ cheapExpression() [2/2]

template<typename ExprT, typename VariableT>
const GlExprInterface & ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >::cheapExpression ( ) const
inlineoverridevirtual

◆ imgDesc()

template<typename ExprT, typename VariableT>
ImageDescriptor ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >::imgDesc ( ) const
inlineoverridevirtual

Return ImageDescriptor of this expression. This reference is expected to remain the same while the class exists.

Implements ImFusion::ImageMath::ExprInterface.

◆ numImgs()

template<typename ExprT, typename VariableT>
int ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >::numImgs ( ) const
inlineoverridevirtual

Return number of images of this expression.

Implements ImFusion::ImageMath::ExprInterface.

◆ deviceStrategy()

template<typename ExprT, typename VariableT>
DeviceStrategy ImFusion::ImageMath::internal::StashTpl< ExprT, VariableT >::deviceStrategy ( ) const
inlineoverridevirtual

Return DeviceStrategy of this expression.

Implements ImFusion::ImageMath::ExprInterface.


The documentation for this class was generated from the following file:
  • ImFusion/ImageMath/Tpl/StashTpl.h
Search Tab / S to search, Esc to close