ImFusion C++ SDK 4.5.0
ImFusion::AlgorithmFactory Class Reference

#include <ImFusion/Base/AlgorithmFactory.h>

Interface for algorithm factories. More...

Inheritance diagram for ImFusion::AlgorithmFactory:

Detailed Description

Interface for algorithm factories.

Inherit from this class to create an algorithm factory for your module. You can register Algorithms with the factory (typically done in the constructor) and query or instantiate them later.

An algorithm can be registered with registerAlgorithm<T>(id, name) where T is the algorithm type. The algorithm can later be queried with algorithmDescriptor(qualifiedId) and instantiated with instantiateAlgorithm(qualifiedId, data), where qualifiedId is id prepended with the factory module name.

class VisionAlgorithmFactory : public AlgorithmFactory
{
VisionAlgorithmFactory() : AlgorithmFactory("Vision")
{
registerAlgorithm<GaussianFilterAlgorithm>("GaussianFilter", "Filters;Gaussian");
}
};
std::unique_ptr<Algorithm> alg = instantiateAlgorithm("Vision.GaussianFilter", data); // using id
AlgorithmFactory(const std::string &module)
Create algorithm factory for the given module.
void registerAlgorithm(std::string id, std::string guiName, Flags< Descriptor::AlgorithmAttributes > flags={}, std::optional< Properties > configurationOverride=std::nullopt)
Register algorithm type T with the given id and GUI name.
Definition AlgorithmFactory.h:182
std::unique_ptr< T > instantiateAlgorithm(const DataList &data) const
Create an instance of the algorithm with the type T.
Definition AlgorithmFactory.h:243

You may also query algorithms compatible with a given set of data:

std::vector<Descriptor> compatible = compatibleDescriptors(data); // non-I/O algorithms
std::vector<Descriptor> compatibleIo = compatibleIoDescriptors(data); // I/O algorithms
virtual std::vector< Descriptor > compatibleIoDescriptors(const DataList &data) const
Returns the descriptors of I/O algorithms registered with this factory which are compatible with data...
virtual std::vector< Descriptor > compatibleDescriptors(const DataList &data) const
Returns the descriptors of non-I/O algorithms registered with this factory which are compatible with ...
Examples
StreamAlgorithmFactory.cpp.

Classes

struct  Descriptor
 Struct describing an algorithm registered with a factory. More...

Public Member Functions

 AlgorithmFactory (const std::string &module)
 Create algorithm factory for the given module.
 AlgorithmFactory (const std::string &module, bool checkLicense)
std::string moduleName () const
 Returns the module name of the factory.
template<typename T>
void registerAlgorithm (std::string id, std::string guiName, Flags< Descriptor::AlgorithmAttributes > flags={}, std::optional< Properties > configurationOverride=std::nullopt)
 Register algorithm type T with the given id and GUI name.
void registerDeprecatedAlgorithmId (std::string deprecatedId, std::string canonicalId)
 Register a legacy algorithm ID that redirects to a current one, emitting a deprecation warning on use.
template<typename T>
std::unique_ptr< T > instantiateAlgorithm (const DataList &data) const
 Create an instance of the algorithm with the type T.
virtual std::unique_ptr< AlgorithminstantiateAlgorithm (const std::string &id, const DataList &data) const
 Create an instance of the algorithm with the given id.
virtual std::unique_ptr< IoAlgorithminstantiateIoAlgorithm (const std::string &id, const DataList &data) const
 Convenience function to create an instance of an IO algorithm with the given id.
virtual std::vector< DescriptorcompatibleDescriptors (const DataList &data) const
 Returns the descriptors of non-I/O algorithms registered with this factory which are compatible with data.
virtual std::vector< DescriptorcompatibleIoDescriptors (const DataList &data) const
 Returns the descriptors of I/O algorithms registered with this factory which are compatible with data.
virtual std::vector< DescriptorcompatibleIoDescriptors (const Filesystem::Path &path) const
 Returns the descriptors of algorithms registered with this factory which can load the given file path.
virtual Descriptor algorithmDescriptor (const std::string &id, bool matchGuiName=false) const
 Returns the descriptors of the algorithm with the given id.
virtual std::vector< DescriptoralgorithmDescriptors () const
 Returns all algorithm descriptors registered with this factory.
virtual std::vector< DescriptorioAlgorithmDescriptors () const
 Returns all I/O algorithm descriptors registered with this factory.
template<typename T>
Descriptor algorithmDescriptor () const
 Returns the descriptors of the algorithm type T.
template<typename T>
std::string algorithmId () const
 Returns the id of the algorithm type T.
virtual bool addAlgorithmFactoryToFront () const
 Returns whether to add this AlgorithmFactory to the front of the list during registration.
 AlgorithmFactory ()

Static Protected Member Functions

static std::string nameFromId (const std::string &name)
 Create a GUI name from the algorithm id.
static std::string idFromName (const std::string &name)
 Create a standard algorithm id from the GUI name.

Protected Attributes

std::string m_moduleName
std::vector< Descriptorm_algorithmDescriptors
std::unordered_map< std::type_index, std::stringm_algorithmIds
std::unordered_map< std::string, std::stringm_deprecatedAlgorithmIds
 Maps deprecated fully-qualified IDs to their canonical replacements.

Constructor & Destructor Documentation

◆ AlgorithmFactory() [1/3]

ImFusion::AlgorithmFactory::AlgorithmFactory ( const std::string & module)
explicit

Create algorithm factory for the given module.

Parameters
moduleThe name of the factory. This name is prepended to the algorithm IDs registered with this factory (e.g. "Vision" → "Vision.GaussianFilter"). The name must be unique as it is also used to identify the factory.
Note
This name is independent of Plugin names and license feature codes, but it's good practice to use the same string for all three.

◆ AlgorithmFactory() [2/3]

ImFusion::AlgorithmFactory::AlgorithmFactory ( const std::string & module,
bool checkLicense )
explicit
Deprecated
The checkLicense parameter is no longer used.
Deprecated
"checkLicense parameter is deprecated and ignored. Use single-parameter constructor."

◆ AlgorithmFactory() [3/3]

ImFusion::AlgorithmFactory::AlgorithmFactory ( )
Deprecated
"AlgorithmFactory must have a module name."

Member Function Documentation

◆ registerAlgorithm()

template<typename T>
void ImFusion::AlgorithmFactory::registerAlgorithm ( std::string id,
std::string guiName,
Flags< Descriptor::AlgorithmAttributes > flags = {},
std::optional< Properties > configurationOverride = std::nullopt )

Register algorithm type T with the given id and GUI name.

Parameters
idThe unique algorithm ID. The id will be automatically prepended by the factory module name (e.g. "GaussianFilter" -> "Vision.GaussianFilter"). As a convention, the ID should be the same as the algorithm's class name excluding the "Algorithm" suffix (e.g. GaussianFilterAlgorithm -> "GaussianFilter").
guiNameThe name used by the GUI to represent this algorithm. Can contain semicolon delimited categories (e.g. Filters;Gaussian). As a convention, IoAlgorithms should always be in the IO top-level category (e.g. IO;MyPlugin;MyIoAlgorithm).
flagsOptional AlgorithmAttributes to set for this algorithm.
configurationOverrideOptional properties applied when the algorithm is created.

◆ registerDeprecatedAlgorithmId()

void ImFusion::AlgorithmFactory::registerDeprecatedAlgorithmId ( std::string deprecatedId,
std::string canonicalId )

Register a legacy algorithm ID that redirects to a current one, emitting a deprecation warning on use.

Parameters
deprecatedIdFull legacy ID (e.g. "OldModule.OldAlgorithm").
canonicalIdFull current ID the deprecated one should resolve to (e.g. "NewModule.NewAlgorithm"). Both IDs must be fully qualified (including module prefix).

◆ instantiateAlgorithm() [1/2]

template<typename T>
std::unique_ptr< T > ImFusion::AlgorithmFactory::instantiateAlgorithm ( const DataList & data) const

Create an instance of the algorithm with the type T.

Will return nullptr if no such algorithm is registered, or if the algorithm creation fails.

◆ instantiateAlgorithm() [2/2]

virtual std::unique_ptr< Algorithm > ImFusion::AlgorithmFactory::instantiateAlgorithm ( const std::string & id,
const DataList & data ) const
virtual

Create an instance of the algorithm with the given id.

Will return nullptr if no such algorithm is registered, or if the algorithm creation fails.

◆ instantiateIoAlgorithm()

virtual std::unique_ptr< IoAlgorithm > ImFusion::AlgorithmFactory::instantiateIoAlgorithm ( const std::string & id,
const DataList & data ) const
virtual

Convenience function to create an instance of an IO algorithm with the given id.

Will return nullptr if no such algorithm is registered, or if the algorithm is not an IoAlgorithm, or the algorithm creation fails.

◆ algorithmDescriptor()

virtual Descriptor ImFusion::AlgorithmFactory::algorithmDescriptor ( const std::string & id,
bool matchGuiName = false ) const
virtual

Returns the descriptors of the algorithm with the given id.

Parameters
matchGuiNameIf true, tries to find algorithms with matching GUI names if no algorithm with the given id is found. Returns a default constructed Descriptor if no matching algorithm is found.

◆ addAlgorithmFactoryToFront()

virtual bool ImFusion::AlgorithmFactory::addAlgorithmFactoryToFront ( ) const
virtual

Returns whether to add this AlgorithmFactory to the front of the list during registration.

Per default return false. You may override this method to change the behavior.

Reimplemented in ImFusion::DicomAlgorithmFactory, and ImFusion::DicomGuiAlgorithmFactory.

◆ nameFromId()

std::string ImFusion::AlgorithmFactory::nameFromId ( const std::string & name)
staticprotected

Create a GUI name from the algorithm id.

Used as a convenience fallback if no name is specified.

◆ idFromName()

std::string ImFusion::AlgorithmFactory::idFromName ( const std::string & name)
staticprotected

Create a standard algorithm id from the GUI name.

Used as a deprecation fallback if no id is specified.


The documentation for this class was generated from the following file:
  • ImFusion/Base/AlgorithmFactory.h
Search Tab / S to search, Esc to close