ImFusion SDK 4.3
Array< T, ImgType, BlockAccessEnabled > Class Template Reference

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

Specialization of ExprBase for a image leaf, i.e. More...

+ Inheritance diagram for Array< T, ImgType, BlockAccessEnabled >:

Detailed Description

template<typename T, typename ImgType, bool BlockAccessEnabled = false>
class ImFusion::ImageMath::Array< T, ImgType, BlockAccessEnabled >

Specialization of ExprBase for a image leaf, i.e.

an TypedImage, SharedImage and SharedImageSet

Note
The overload for SharedImageSet assumes that all images in the set have the same type and size. If this is not the case you need to run the expression for each ShareImage involved individually.

This class offers an expression leaf which wraps an existing, SharedImage, SharedImageSet, or TypedImage. Such an object can be used as leaf within an expression or as l-value in order to evaluate an expression into an image. This class has two template parameters, T and ImgType. T needs to be either SharedImage, or SharedImageSet, or TypedImage. ImgType can either be void or any type that is supported by our image classes. In the case of void the type is deduced at runtime from the expression, however this requires that all leaves within the expression need to have the same type as the l-value the expression is assigned to. In any other case, i.e. mixed types, you need to hint the type by providing an ImgType. For convenience we provide a builder method which deduces the type directly in the case of TypedImage and offers one template parameter in the case of SharedImage or SharedImageSet. In addition, on construction you need to provide a unique name which will be used as variable name/prefix in e.g. GLSL shaders. The class also provides block access.

Note
The pixel value will always be considered float (GPU) or double (CPU) as due to shift and scale the image type is not sufficient. If you want to use e.g. integer type in the expression you need to use the casting operator.
TypedImage<float> typedImg(...);
SharedImage sharedImg(...);
auto typedImgExpr = makeArray(typedImg); // Will create a Array<TypedImage<float>, float>
auto sharedImgExprTyped = makeArray<float>(sharedImg); // Will create a Array<SharedImage, float>
auto sharedImgExprNonTyped = makeArray(sharedImg); // Will create a Array<SharedImage, void>
Image shared on multiple devices.
Definition SharedImage.h:86
Concrete implementation of a MemImage for a given pixel type.
Definition KinectAzureStreamPlaybackAlgorithm.h:23
auto makeArray(TypedImage< T > &img, bool ignoreShiftAndScale, MagFilter magFilter, Wrap wrap, const vec4f &borderColor)
Convenience function to create an array leaf (needed as until c++17 there is no template type deducti...
Definition Array.h:657

Public Types

using img_type = ImgType
 
using expr_type = std::conditional_t<std::is_void_v<ImgType>, void, double>
 
using imf_img_type = T
 
using var_type = void
 

Public Member Functions

 Array (T &img, bool ignoreShiftAndScale=false, MagFilter magFilter=MagFilter::Nearest, Wrap wrap=Wrap::ClampToEdge, const vec4f &borderColor=vec4f::Zero())
 Constructor.
 
 Array (const Array &other)
 
ImageDescriptor imgDesc () const override final
 Return ImageDescriptor of this expression. This reference is expected to remain the same while the class exists.
 
ImageMath::MagFilter getMagFilter ()
 
ImageMath::Wrap getWrap ()
 
int numImgs () const override
 Number of images (i.e. the number of image in the SharedImageSets and 1 for MemImage or SharedImage)
 
auto block (const vec3i &offset, const vec3i &blockSize) const
 
DeviceStrategy deviceStrategy () const override
 Return DeviceStrategy of this expression.
 
template<typename otherT, typename otherImgType>
auto cloneLeaf (otherT &img) const
 create Array with different image type but same properties
 
T & img ()
 
const T & img () const
 
void setDeviceStrategy (DeviceStrategy deviceStrategy)
 manually override the deviceStrategy
 
- Public Member Functions inherited from ExprBaseTpl< Array< T, ImgType, false > >
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
 
auto polyWrapper () const
 
auto uniquePolyWrapper () const
 
auto sharedPolyWrapper () const
 
auto binaryOp (const ExprBaseTpl< RhsT > &rhs, const Op &func=Op()) const
 
auto binaryOp (RhsT rhs, const Op &func=Op(), typename std::enable_if< std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 
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
 
auto binaryOp (const ExprBaseTpl< RhsT > &rhs, const Op &func, const StringOp &stringFunc) const
 
auto binaryOp (RhsT rhs, const Op &func, const StringOp &stringFunc, typename std::enable_if< std::is_arithmetic_v< RhsT > >::type *=nullptr) const
 
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
 
auto unaryOp (const Op &func=Op()) const
 
auto unaryOp (const Op &func, const StringOp &stringFunc) 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})
 
 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
 
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)
 
 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
 
auto channelDistance (const ExprBaseTpl< RhsT > &other) const
 
auto channelDistance (const Eigen::Matrix< T, Dim, 1 > c)
 
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.
 
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.
 
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.
 
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.
 
 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
 
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
 
auto resample (SharedImage &inputDesc, SharedImage &outputDesc, std::enable_if_t< std::is_same_v< T, SharedImage > > *=nullptr) const
 
auto resample (SharedImageSet &inputDesc, SharedImageSet &outputDesc, std::enable_if_t< std::is_same_v< T, SharedImageSet > > *=nullptr) const
 
- Public Member Functions inherited from ArrayGl< Array< T, ImgType, false > >
std::string evalString (bool tagAndAssign=true) const override final
 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 final
 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 final
 Collect uniform/sampler definitions.
 
void getVariableDefinitionList (std::string &definitionList, const std::vector< int > &indices, const std::string &prefix) const override final
 Collect variable definitions.
 
int setArguments (GL::Program &p, const std::vector< int > &indices, const std::string &prefix) const override final
 Set uniform/sampler arguments.
 
bool assignGl (const internal::GlExprInterface &expr)
 Evaluates expression into this ArrayGl on the GPU.
 
std::vector< internal::GlExprInterface * > children () override final
 Used for traversing the expression tree. Contains the immediate children of node.
 
std::vector< const internal::GlExprInterface * > children () const override final
 Used for traversing the expression tree. Contains the immediate children of node.
 
bool setMagFilter (ImageMath::MagFilter m) override final
 Set interpolation behaviour of the current leaf (only)
 
bool setWrap (ImageMath::Wrap w) override final
 Set interpolation behaviour of the current leaf (only)
 
- Public Member Functions inherited from GlExprInterface
ExprInterfaceexprInterface ()
 Get image descriptor of the wrapped expression.
 
const ExprInterfaceexprInterface () const
 
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 block_access_enabled = BlockAccessEnabled
 
static constexpr bool has_variable = false
 

Assignments

template<typename ExprT>
Array< T, ImgType, BlockAccessEnabled > & operator= (const ExprBaseTpl< ExprT > &operand)
 Assign and actual evaluation.
 
Array< T, ImgType, BlockAccessEnabled > & operator= (const Array< T, img_type, BlockAccessEnabled > &operand)
 copy assignment. Calls the templated assignment internally.
 
template<typename RhsT>
std::enable_if< std::is_arithmetic_v< RhsT >, Array< T, img_type, BlockAccessEnabled > & >::type operator= (RhsT rhs)
 Specialized assign for Scalar.
 
template<typename RhsT, int Dim>
Array< T, ImgType, BlockAccessEnabled > & operator= (Eigen::Matrix< RhsT, Dim, 1 > rhs)
 Specialized assign for ChannelWiseScalar.
 

MemImage implementations

IMFUSION_STRONG_INLINE expr_type eval (const std::size_t i, const vec4i &coord) const
 Evaluate the expression at position i.
 

Convert the expression to MemImage.

template<typename ImgT>
auto convertToMemImgExpr () const noexcept
 Convert the expression to MemImage.
 

Convert the expression to SharedImage.

auto convertToSharedImgExpr (std::size_t index) const
 Convert the expression to SharedImage.
 

Constructor & Destructor Documentation

◆ Array()

template<typename T, typename ImgType, bool BlockAccessEnabled = false>
Array ( T & img,
bool ignoreShiftAndScale = false,
MagFilter magFilter = MagFilter::Nearest,
Wrap wrap = Wrap::ClampToEdge,
const vec4f & borderColor = vec4f::Zero() )
inlineexplicit

Constructor.

Parameters
imgImage wrapped by this expression leaf
ignoreShiftAndScaleif false the shift and scale of the image will be considered for evaluation and assignment
magFiltermagFilter to be used in the GPU path
wrapwrapping to be used
borderColorborder color used if wrap it ClampToBorder

Member Function Documentation

◆ imgDesc()

template<typename T, typename ImgType, bool BlockAccessEnabled = false>
ImageDescriptor imgDesc ( ) const
inlinefinaloverridevirtual

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

Implements ExprInterface.

◆ operator=()

template<typename T, typename ImgType, bool BlockAccessEnabled = false>
template<typename ExprT>
Array< T, ImgType, BlockAccessEnabled > & operator= ( const ExprBaseTpl< ExprT > & operand)
inline

Assign and actual evaluation.

Parameters
operandThe expression to be evaluated.
Returns
Reference to *this.

The MemImage path uses OpenMP parallelization and iterates over m_img and for each pixel evaluated the expression at this position and stores the result in the corresponding pixel.

The SharedImage path checks if the SharedImage has a Gl representation (SharedImage::hasGl()) and if uses the GlExpr in order to evaluate the expression into *this. Otherwise it falls back to the MemImage variant.

The SharedImageSet method tries to process multiple SharedImages of the SharedImageSet at once, if possible. Otherwise falls back to the SharedImage variant and evaluates them sequentially.

◆ numImgs()

template<typename T, typename ImgType, bool BlockAccessEnabled = false>
int numImgs ( ) const
inlineoverridevirtual

Number of images (i.e. the number of image in the SharedImageSets and 1 for MemImage or SharedImage)

Implements ExprInterface.

◆ block()

template<typename T, typename ImgType, bool BlockAccessEnabled = false>
auto block ( const vec3i & offset,
const vec3i & blockSize ) const
inline
Returns
an expression which provides a block wise view of *this

If you want block access to the channels

See also
ChannelSwizzleViewTpl and
ExprBaseTpl::channelswizzle()

The block will start at the coord offset and will have size blockSize.

Note
Aliasing warning.
See also
operator=()

◆ deviceStrategy()

template<typename T, typename ImgType, bool BlockAccessEnabled = false>
DeviceStrategy deviceStrategy ( ) const
inlineoverridevirtual

Return DeviceStrategy of this expression.

Implements ExprInterface.


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