ImFusion SDK 4.3
FreeFormDeformation Class Reference

#include <ImFusion/GL/FreeFormDeformation.h>

The FreeFormDeformation provides deformations using a free-form deformation (FFD) based on B-splines. More...

+ Inheritance diagram for FreeFormDeformation:

Detailed Description

The FreeFormDeformation provides deformations using a free-form deformation (FFD) based on B-splines.

The FFD is represented by a regular grid of control points (green). The location of the control points is determined by the spacing, the number of subdivisions and the overall transformation of the grid. Each control point can have a displacement in mm.

200 The displacement of a point P inside the grid is determined by the sum of the displacements of the 4 nearest control points (black-rimmed) for each dimension weighted by the B-splines. If the 4 nearest control points contain control points that are outside the actual grid (yellow), these control points are always treated as control points with no displacement. More details can be found in: Rueckert et al., Nonrigid Registration Using Free-Form Deformations: Application to Breast MR Images, IEEE, 1999

The FreeFormDeformation also contains a shader include that computes the displacement for a given texture coordinate (see also

FreeFormDeformation::setIncludeArguments(GlProgram*, SharedImage*))

Public Member Functions

 FreeFormDeformation (const vec3i &subdivisions=vec3i(1, 1, 1), const vec3 &spacing=vec3(1.0, 1.0, 1.0))
 Creates a FFD grid with the given number of subdivision and spacing.
 
 FreeFormDeformation (const vec3i &subdivisions, SharedImage *img)
 Creates a FFD grid with the given number of subdivisions and uses the given image to initialize the spacing.
 
 FreeFormDeformation (SharedImage *img)
 Similar to FreeFormDeformation(const vec3&, SharedImage*) but sets the subdivisions to vec3(1,1,0) for 2D images and vec3(1,1,1) otherwise.
 
 FreeFormDeformation (const FreeFormDeformation &other)
 Copy constructor.
 
Deformationclone () const override
 Returns a copy of the deformation.
 
bool isIdentity () const override
 Returns if the current state of the deformation transformations the image or not.
 
void setIdentity () override
 Sets the displacement of all control points to zero.
 
vec3 displacement (const vec3 &pos) const override
 Returns the displacement for pos (in world coordinates).
 
vec3 displacement (const vec2 &pos) const override
 Returns the displacement at the world position pos.
 
virtual vec3 displacement (const vec3i &pos) const
 Returns the control point at the given index or vec3(0.0, 0.0, 0.0) if it is outside the grid.
 
int setIncludeArguments (GL::Program &p, const SharedImage *img=nullptr, const std::string &prefix="deform") const override
 Initializes the FFDeformation shader header to deform the given image.
 
int dimension () const override
 Dimension of the grid, either 2 or 3.
 
void setSubdivisions (const vec3i &n, bool updateSpacing=true)
 Set number of subdivisions.
 
vec3i subdivisions () const
 Get number of subdivisions.
 
void setGridSpacing (const vec3 &s)
 Set grid spacing in mm.
 
vec3 gridSpacing () const
 Get grid spacing in mm.
 
int numberOfControlPoints () const override
 Returns the number of control points.
 
std::vector< vec3 > controlPoints () const override
 Get current control point locations (including displacement)
 
vec3 controlPoint (const vec3i &d) const
 Get current location (including displacement) of a single control point.
 
vec3i gridSize () const
 Returns the size of the grid.
 
void setGridTransformation (const mat4 &T)
 Set transformation to be applied to the control points in world coordinate system.
 
mat4 gridTransformation () const
 Get control point transformation in world coordinate system.
 
void fitGridToContent (SharedImage *image)
 Fits the grid to the content of the image.
 
void setDisplacement (const std::vector< vec3f > &d) override
 Set displacement in mm for every control points.
 
void setDisplacement (const std::vector< vec2f > &d)
 Set displacement in mm for every control points. Convenience function for 2D grid.
 
bool setDisplacement (SharedImage *d)
 
bool setDisplacement (const TypedImage< float > *d)
 
void setDisplacement (const vec3i &controlPoint, const vec3f &d)
 Sets the displacement at the given control point.
 
void setDisplacement (const vec2i &controlPoint, const vec2f &d)
 Sets the displacement at the given control point.
 
std::vector< vec3f > displacements () const override
 Get displacement in mm of all control points.
 
SharedImagedisplacementsImage () const
 Get displacement in mm of all control points.
 
void configure (const Properties *p) override
 Set one or multiple properties.
 
void configuration (Properties *p) const override
 Retrieve the properties of this object.
 
std::string id () const override
 Returns a unique string identifier for this type of deformation.
 
- Public Member Functions inherited from ParametricDeformation
 ParametricDeformation (const std::string &shaderPath)
 Initializes the parametric deformation with path to the GlInclude file.
 
 ~ParametricDeformation () override
 Destructor.
 
virtual void setParameters (const std::vector< double > &pars)
 Set the parameters of the deformation.
 
virtual void parameters (std::vector< double > &parsOut) const
 Retrieve the current parameters of the deformation.
 
virtual int numberOfParameters () const
 Returns the number of parameters e.g. for optimization.
 
- Public Member Functions inherited from Deformation
 Deformation (const std::string &shaderPath)
 Initializes the Deformation with path to the GlInclude file.
 
virtual vec3 displacePoint (const vec3 &point) const
 Returns the displaced position of the given point in world-coordinates.
 
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 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 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
 

Protected Member Functions

double bs (int idx, double t) const
 
- Protected Member Functions inherited from Deformation
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

vec3 m_spacing
 Control point spacing in mm.
 
vec3i m_gridSize
 Size of control point grid.
 
mat4 m_gridTransformation
 Control point transformation in world coordinate system.
 
SharedImagem_disp
 Displacement of control points in mm.
 
- Protected Attributes inherited from Deformation
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.
 
- Static Public Member Functions inherited from Deformation
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 inherited from Deformation
Signal< const DeformationEvent & > signalChanged
 
- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 

Constructor & Destructor Documentation

◆ FreeFormDeformation()

FreeFormDeformation ( const vec3i & subdivisions,
SharedImage * img )

Creates a FFD grid with the given number of subdivisions and uses the given image to initialize the spacing.

The spacing is set to the img extent divided by the number of subdivisions, so that the control points span over the complete image

Member Function Documentation

◆ clone()

Deformation * clone ( ) const
overridevirtual

Returns a copy of the deformation.

Implements Deformation.

◆ isIdentity()

bool isIdentity ( ) const
overridevirtual

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

Implements Deformation.

◆ setIdentity()

void setIdentity ( )
overridevirtual

Sets the displacement of all control points to zero.

Implements Deformation.

◆ displacement() [1/3]

vec3 displacement ( const vec3 & pos) const
overridevirtual

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.

Implements Deformation.

◆ displacement() [2/3]

vec3 displacement ( const vec2 & pos) const
overridevirtual

Returns the displacement at the world position pos.

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

Reimplemented from Deformation.

◆ displacement() [3/3]

virtual vec3 displacement ( const vec3i & pos) const
virtual

Returns the control point at the given index or vec3(0.0, 0.0, 0.0) if it is outside the grid.

The returned displacement is in world coordinates.

◆ setIncludeArguments()

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

Initializes the FFDeformation shader header to deform the given image.

The displacements are computed from the texture coordinates of the image and are returned in image coordinates, therefore this method should be called again when the displacement should be computed on an image with different extent.

Implements Deformation.

◆ dimension()

int dimension ( ) const
overridevirtual

Dimension of the grid, either 2 or 3.

Implements Deformation.

◆ setSubdivisions()

void setSubdivisions ( const vec3i & n,
bool updateSpacing = true )

Set number of subdivisions.

If updateSpacing is true, the spacing will be updated so that the existing control points will remain at their previous location, e.g. the grid will remain on the same world location.

◆ numberOfControlPoints()

int numberOfControlPoints ( ) const
overridevirtual

Returns the number of control points.

Reimplemented from ParametricDeformation.

◆ controlPoints()

std::vector< vec3 > controlPoints ( ) const
overridevirtual

Get current control point locations (including displacement)

Reimplemented from ParametricDeformation.

◆ gridTransformation()

mat4 gridTransformation ( ) const

Get control point transformation in world coordinate system.

The transformation is applied on the control points and the displacements

◆ fitGridToContent()

void fitGridToContent ( SharedImage * image)

Fits the grid to the content of the image.

This only modifies the grid transformation not the number of control points or the grid spacing. The content of the image is determined by the MinimumBoundingBox algorithm.

◆ setDisplacement()

void setDisplacement ( const std::vector< vec3f > & d)
overridevirtual

Set displacement in mm for every control points.

For 2D images the z-coordinate of the displacement is ignored.

Reimplemented from ParametricDeformation.

◆ displacements()

std::vector< vec3f > displacements ( ) const
overridevirtual

Get displacement in mm of all control points.

Reimplemented from ParametricDeformation.

◆ configure()

void configure ( const Properties * p)
overridevirtual

Set one or multiple properties.

Reimplemented from Configurable.

◆ configuration()

void configuration ( Properties * p) const
overridevirtual

Retrieve the properties of this object.

Reimplemented from Configurable.

◆ id()

std::string id ( ) const
inlineoverridevirtual

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

Implements Deformation.


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