ImFusion SDK 4.3
Deformation Class Referenceabstract

#include <ImFusion/GL/Deformation.h>

Base class for different kinds of non-linear image transformations. More...

+ Inheritance diagram for Deformation:

Detailed Description

Base class for different kinds of non-linear image transformations.

The transformations are defined inversely, i.e. they do not describe how a point has to be displaced, but where a point originates from. If x is a point in world coordinates and g(x) the same point after applying the deformation, the displacement disp describes:

x = g(x) + disp(g(x))

and NOT:

g(x) = x + disp(x)

This means, for each point in world coordinates (g(x)) one can directly determine where this point originates from (x). However, one can not directly tell where a point x will be displaced to because non-linear deformations are not always reversible.. While this may seem is very useless to transform individual points, it is very helpful when deforming images. * When deforming an image, one can iterate the pixels of the resulting deformed image and look-up the values in the original, undeformed image. To get the deformed position of an individual point, use the displacePoint method.

Derived classes should provide a CPU and OpenGL implementation. A generic OpenGL interface is provided by a GlAbstractInclude. Similar as with GlMask, you can use several different deformation fields in the same shader by using the helper class DeformationMultiInclude.

In order to work with DeformationMultiInclude, derived classes need to comply with the following requirements:

  • The GlAbstractInclude define name is "IMAGE_DEFORM"
  • Every uniform and every function needs to be prefixed with "deform"
  • The GLSL header needs to provide at least the following function:
    vec3 deformDisplacement(vec3 tc);
    This method should take image texture coordinates as input and return the displacement again in texture coordinates.
  • When implementing Deformation::setIncludeArguments(), make sure to use the given prefix when accessing the shader uniforms, i.e.
    setArgument((prefix + "OutsideValue").c_str, ...)
    instead of
    setArgument("deformOutsideValue", ...)
See also
DeformationMultiInclude

Public Member Functions

 Deformation (const std::string &shaderPath)
 Initializes the Deformation with path to the GlInclude file.
 
virtual Deformationclone () const =0
 Returns a copy of the deformation.
 
virtual vec3 displacement (const vec3 &pos) const =0
 Returns the displacement for pos (in world coordinates).
 
virtual vec3 displacement (const vec2 &pos) const
 Returns the displacement at the world position pos.
 
virtual vec3 displacePoint (const vec3 &point) const
 Returns the displaced position of the given point in world-coordinates.
 
virtual bool isIdentity () const =0
 Returns if the current state of the deformation transformations the image or not.
 
virtual void setIdentity ()=0
 Sets all displacements to 0.
 
int setIncludeArguments (GL::Program &p, const SharedImage *img=nullptr, const std::string &prefix="deform") const override=0
 Override default arguments for GlMask includes.
 
void setDisabled (bool flag)
 Set a disabled flag in order to hide the visualization of this deformation.
 
bool disabled () const
 Return whether the deformation was set to disabled.
 
virtual int dimension () const =0
 Returns the dimension of the deformation.
 
virtual std::string id () const =0
 Returns a unique string identifier for this type of deformation.
 
virtual std::unique_ptr< SharedImageSetsupportingImages () const
 Returns the images that, together with the configuration, defines the deformation.
 
- Public Member Functions inherited from AbstractInclude
 AbstractInclude (const std::string &defineName, const std::string &includePath)
 Creates a AbstractInclude for the given define and with the corresponding GLSL file at includePath.
 
const std::stringdefineName () const
 Returns the name of define used by this include.
 
const std::stringincludePath () const
 Returns the path to the included shader file.
 
virtual std::function< std::string(const std::string &)> includeCodeSubstitution () const
 Optionally the abstract include can provide a function to change the shader code.
 
virtual std::vector< AbstractInclude * > dependentIncludes () const
 Returns a list of dependent abstract includes that need to be included as well.
 
virtual Fingerprint fingerprint () const
 Provides a finger print of the include.
 
- Public Member Functions inherited from MultiIncludable< Deformation, const SharedImage * >
std::shared_ptr< MultiIncludeTypecreateMultiInclude (const std::string &replacementToken)
 Instantiates a new AbstractInclude instance where all occurrences of baseToken provided during construction are replaces with replacementToken according to the specified replacementScheme.
 
virtual int setIncludeArguments (Program &prog, IncludeArgumentsTypes... includeArgs, const std::string &token) const=0
 Interface that multi includes should use to configure the shader include (such as setting uniforms, binding textures, etc).
 
- Public Member Functions inherited from Configurable
virtual void configure (const Properties *p)
 Configure this object instance by de-serializing the given Properties.
 
virtual void configuration (Properties *p) const
 Serialize the current object configuration into the given Properties object.
 
virtual void configureDefaults ()
 Retrieve the properties of this object, replaces values with their defaults and sets it again.
 
void registerParameter (ParameterBase *param)
 Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration().
 
void unregisterParameter (const ParameterBase *param)
 Remove the given Parameter or SubProperty from the list of registered parameters.
 
 Configurable (const Configurable &rhs)
 
 Configurable (Configurable &&rhs) noexcept
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Static Public Member Functions

static std::string defineName ()
 Returns the define name of GlAbstractInclude for all deformations.
 
static std::string defineSuffix ()
 Returns "DEFORM".
 
static std::string multiIncludeDefine (const std::string &replacementToken)
 Returns "IMAGE_" + toUpper(replacementToken)
 

Public Attributes

Signal< const DeformationEvent & > signalChanged
 
- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 

Protected Member Functions

void notifyListeners (const DeformationEvent &event) const
 convenience function to call signalChanged.emitSignal(event).
 
- Protected Member Functions inherited from MultiIncludable< Deformation, const SharedImage * >
 MultiIncludable (Deformation *crtpInstance, const std::string &baseToken, Flags< ShaderTextReplacement > replacementScheme)
 Instantiate and configure the MultiIncludable interface.
 

Protected Attributes

bool m_disabled
 Disabled flag for visualization.
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Additional Inherited Members

- Public Types inherited from MultiIncludable< Deformation, const SharedImage * >
using MultiIncludeType
 Alias for type of a multi-include instance of the original include.
 

Member Function Documentation

◆ clone()

◆ defineName()

static std::string defineName ( )
static

Returns the define name of GlAbstractInclude for all deformations.

Always returns IMAGE_DEFORM

◆ displacement() [1/2]

virtual vec3 displacement ( const vec3 & pos) const
pure virtual

Returns the displacement for pos (in world coordinates).

The returned displacement is also in world coordinates. The displacement indicates where pos originated from before applying the deformation.

Implemented in FreeFormDeformation, GlDenseDeformation, GlFlattenTrackingDeformation, GlPolyRigidDeformation, GlTPSDeformation, OperandDeformation< T >, GlProbeDeformation, and GlSweepStretchDeformation.

◆ displacement() [2/2]

virtual vec3 displacement ( const vec2 & pos) const
virtual

Returns the displacement at the world position pos.

The base implementation just calls displacement(vec3(pos,0.0))

Reimplemented in FreeFormDeformation, and GlDenseDeformation.

◆ displacePoint()

virtual vec3 displacePoint ( const vec3 & point) const
virtual

Returns the displaced position of the given point in world-coordinates.

This method will estimate the inverse displacement.

Reimplemented in GlFlattenTrackingDeformation, and GlPolyRigidDeformation.

◆ isIdentity()

virtual bool isIdentity ( ) const
pure virtual

Returns if the current state of the deformation transformations the image or not.

Implemented in FreeFormDeformation, GlDenseDeformation, GlFlattenTrackingDeformation, GlPolyRigidDeformation, GlTPSDeformation, OperandDeformation< T >, GlProbeDeformation, and GlSweepStretchDeformation.

◆ setIdentity()

◆ setIncludeArguments()

int setIncludeArguments ( GL::Program & p,
const SharedImage * img = nullptr,
const std::string & prefix = "deform" ) const
overridepure virtual

◆ dimension()

virtual int dimension ( ) const
pure virtual

◆ id()

virtual std::string id ( ) const
pure virtual

Returns a unique string identifier for this type of deformation.

Usually the name of the class.

Note
To avoid conflicts make sure to include potential plugin names into this ID. Due to the modular architecture of the ImFusion library, uniqueness of IDs cannot be checked at compile time. However, DeformationFactory will check the uniqueness of the ID during registration.
See also
DeformationFactory

Implemented in FreeFormDeformation, GlDenseDeformation, GlFlattenTrackingDeformation, GlPolyRigidDeformation, GlTPSDeformation, OperandDeformation< T >, GlProbeDeformation, and GlSweepStretchDeformation.

◆ supportingImages()

virtual std::unique_ptr< SharedImageSet > supportingImages ( ) const
inlinevirtual

Returns the images that, together with the configuration, defines the deformation.

See also
DeformationFactory

Reimplemented in GlDenseDeformation.


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