![]() |
ImFusion SDK 4.3
|
#include <ImFusion/GL/FreeFormDeformation.h>
The FreeFormDeformation provides deformations using a free-form deformation (FFD) based on B-splines. More...
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. | |
Deformation * | clone () 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. | |
SharedImage * | displacementsImage () 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. | |
![]() | |
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. | |
![]() | |
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< SharedImageSet > | supportingImages () const |
Returns the images that, together with the configuration, defines the deformation. | |
![]() | |
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::string & | defineName () const |
Returns the name of define used by this include. | |
const std::string & | includePath () 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. | |
![]() | |
std::shared_ptr< MultiIncludeType > | createMultiInclude (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). | |
![]() | |
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 | |
Configurable & | operator= (const Configurable &) |
Configurable & | operator= (Configurable &&) noexcept |
Protected Member Functions | |
double | bs (int idx, double t) const |
![]() | |
void | notifyListeners (const DeformationEvent &event) const |
convenience function to call signalChanged.emitSignal(event) . | |
![]() | |
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. | |
SharedImage * | m_disp |
Displacement of control points in mm. | |
![]() | |
bool | m_disabled |
Disabled flag for visualization. | |
![]() | |
std::vector< Param > | m_params |
List of all registered Parameter and SubProperty instances. | |
Additional Inherited Members | |
![]() | |
using | MultiIncludeType |
Alias for type of a multi-include instance of the original include. | |
![]() | |
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) | |
![]() | |
Signal< const DeformationEvent & > | signalChanged |
![]() | |
Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
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
|
overridevirtual |
Returns a copy of the deformation.
Implements Deformation.
|
overridevirtual |
Returns if the current state of the deformation transformations the image or not.
Implements Deformation.
|
overridevirtual |
Sets the displacement of all control points to zero.
Implements Deformation.
|
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.
|
overridevirtual |
Returns the displacement at the world position pos.
The base implementation just calls displacement(vec3(pos,0.0))
Reimplemented from Deformation.
|
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.
|
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.
|
overridevirtual |
Dimension of the grid, either 2 or 3.
Implements Deformation.
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.
|
overridevirtual |
Returns the number of control points.
Reimplemented from ParametricDeformation.
|
overridevirtual |
Get current control point locations (including displacement)
Reimplemented from ParametricDeformation.
mat4 gridTransformation | ( | ) | const |
Get control point transformation in world coordinate system.
The transformation is applied on the control points and the displacements
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.
|
overridevirtual |
Set displacement in mm for every control points.
For 2D images the z-coordinate of the displacement is ignored.
Reimplemented from ParametricDeformation.
|
overridevirtual |
Get displacement in mm of all control points.
Reimplemented from ParametricDeformation.
|
overridevirtual |
Set one or multiple properties.
Reimplemented from Configurable.
|
overridevirtual |
Retrieve the properties of this object.
Reimplemented from Configurable.
|
inlineoverridevirtual |
Returns a unique string identifier for this type of deformation.
Usually the name of the class.
Implements Deformation.