ImFusion SDK 4.3
GlGeometricTransform Class Referenceabstract

#include <ImFusion/US/GlGeometricTransform.h>

Base interface for implementing polymorphic geometric transforms from and to image coordinates using OpenGL. More...

+ Inheritance diagram for GlGeometricTransform:

Detailed Description

Base interface for implementing polymorphic geometric transforms from and to image coordinates using OpenGL.

The defineName is IMAGE_TRANSFORM and the include file is expected to define functions with the following signatures:

vec3 transformToAlternate(vec3 imageCoord, bool alternateNormalized);
vec3 transformFromAlternate(vec3 alternateCoord, bool alternateNormalized);

Where imageCoord and alternateCoord are the image coordinates and coordinates in the alternate space respectively. The alternateNormalized flag indicates whether the given or returned alternate coordinates are normalized to the range [0, 1], i.e. texture coordinates. For resulting points that do not lie within the image or alternate space, the functions should return vec3(NaN) if NaNs are supported or vec3(-Inf) otherwise.

A possible implementation of a class defining a trivial translation transform could be:

GlTranslationTransform.h

class GlTranslation : public GlGeometricTransform
{
public:
GlGeometricTransform(vec3 translation);
~GlGeometricTransform() override = default;
int setIncludeArguments(GL::Program& p, const std::string& prefix) const override;
private:
vec3 m_translation;
}
OpenGL GLSL program with a fragment and optional vertex and geometry shader.
Definition Program.h:99
GlGeometricTransform(const std::string &includePath)
Instantiates a new GL::AbstractInclude using IMAGE_TRANSFORM as defineName and the given path the to ...
int setIncludeArguments(GL::Program &p, const std::string &prefix="transform") const override=0
Called by users of GlGeometricTransform in order to correctly set up the transform shader.

GlTranslationTransform.cpp

GlTranslation::GlTranslation(vec3 translation) : GlGeometricTransform("TranslationTransform.glh"), m_translation(translation) {}
int GlTranslation::setIncludeArguments(GL::Program& p, const std::string& prefix) const
{
p.setArgument("u_" + prefix + "translation", m_translation);
return 0;
}
void setArgument(const char *name, const T &val)
Sets a shader argument (i.e., uniform), including images, matrices, vectors.

TranslationTransform.glh

uniform vec3 u_translation;
vec3 transformToAlternate(vec3 imageCoord, bool alternateNormalized) {
return imageCoord + u_translation;
}
vec3 transformFromAlternate(vec3 alternateCoord, bool alternateNormalized) {
return alternateCoord - u_translation;
}

The class can be used now:

GL::ImageProgram dummyFragmentShader{"dummy.frag"};
auto glTranslation = std::make_unique<GlTranslation>(vec3(10.0,-2.0, 4.0));
glTranslation->setIncludeArguments(dummyFragmentShader,"example");
SharedImage normalizedPrescanToImage{/* some data */};
dummyFragmentShader.compute(normalizedPrescanToImage);
Convenience class to execute a GLSL fragment shader on an image or volume.
Definition ImageProgram.h:49
Image shared on multiple devices.
Definition SharedImage.h:86
T make_unique(T... args)

On this case, dummy.frag implements transformToAlternate and transformFromAlternate inside a ifndef IMAGE_TRANSFORM with a in vec3 textCoords, we override them with the contents of our glTranslation, set the u_exampletranslation to the given one, and execute.

Public Member Functions

 GlGeometricTransform (const std::string &includePath)
 Instantiates a new GL::AbstractInclude using IMAGE_TRANSFORM as defineName and the given path the to retrieve the GLSL source code from.
 
int setIncludeArguments (GL::Program &p, const std::string &prefix="transform") const override=0
 Called by users of GlGeometricTransform in order to correctly set up the transform shader.
 
- 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< GlGeometricTransform >
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).
 

Static Public Member Functions

static std::string defineName ()
 Returns "IMAGE_TRANSFORM".
 
static std::string defineSuffix ()
 Returns "TRANSFORM".
 
static std::string multiIncludeDefine (const std::string &replacementToken)
 Returns "IMAGE_" + toUpper(replacementToken)
 

Additional Inherited Members

- Public Types inherited from MultiIncludable< GlGeometricTransform >
using MultiIncludeType
 Alias for type of a multi-include instance of the original include.
 
- Protected Member Functions inherited from MultiIncludable< GlGeometricTransform >
 MultiIncludable (GlGeometricTransform *crtpInstance, const std::string &baseToken, Flags< ShaderTextReplacement > replacementScheme)
 Instantiate and configure the MultiIncludable interface.
 

Member Function Documentation

◆ setIncludeArguments()

int setIncludeArguments ( GL::Program & p,
const std::string & prefix = "transform" ) const
overridepure virtual

Called by users of GlGeometricTransform in order to correctly set up the transform shader.

Subclasses should implement this function so that it correctly sets all needed uniforms and input textures to be used by the OpenGL shader instance. Make sure to use the given prefix argument instead of a hardcoded "transform" when defining uniform names to support multi-includes where the prefixes have been replaced with unique alternatives. Example:

p.setArgument(prefix + "UseRange", m_useRange);

Implemented in GlScanConversionConvexGeometricTransform, GlScanConversionLinearGeometricTransform, and GlScanConversionSectorGeometricTransform.


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