ImFusion SDK 4.3
AlgorithmFactory Class Reference

#include <ImFusion/Base/AlgorithmFactory.h>

Interface for algorithm factories. More...

+ Inheritance diagram for 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
std::unique_ptr< T > instantiateAlgorithm(const DataList &data) const
Create an instance of the algorithm with the type T.
Definition AlgorithmFactory.h:232
AlgorithmFactory(const std::string &module, bool checkLicense=true)
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:169

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 > compatibleDescriptors(const DataList &data) const
Returns the descriptors of non-I/O algorithms registered with this factory which are compatible with ...
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...
Examples
StreamAlgorithmFactory.cpp.

Classes

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

Public Member Functions

 AlgorithmFactory (const std::string &module, bool checkLicense=true)
 Create algorithm factory for the given module.
 
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.
 
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 ()
 
- Public Member Functions inherited from FactoryBase
 FactoryBase ()
 No license check is performed for the module instantiated with this constructor.
 
 FactoryBase (std::string module, bool checkLicense=true)
 
std::string moduleName () const
 Returns the module name of the factory.
 

Protected Member Functions

bool registerAlgorithmIfLicensed (const Descriptor &descriptor)
 Register algorithm with descriptor if license allows it.
 
- Protected Member Functions inherited from FactoryBase
virtual ~FactoryBase ()
 Virtual destructor.
 
std::string getComponentPath (const std::string &componentName) const
 Returns the path to the component referred to by name.
 
bool isLicensed (const std::string &name)
 Return true if the license allows the use of the component referred to by name.
 

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.
 
- Static Protected Member Functions inherited from FactoryBase
static std::string getComponentPath (const std::string &moduleName, const std::string &componentName)
 Returns the path to the component referred to by name.
 
static bool isLicensed (const std::string &moduleName, const std::string &name)
 Return true if the license allows the use of the component referred to by name.
 

Protected Attributes

std::vector< Descriptorm_algorithmDescriptors
 
std::unordered_map< std::type_index, std::stringm_algorithmIds
 
- Protected Attributes inherited from FactoryBase
std::string m_factoryModule
 
bool m_checkLicense
 

Constructor & Destructor Documentation

◆ AlgorithmFactory() [1/2]

AlgorithmFactory ( const std::string & module,
bool checkLicense = true )
explicit

Create algorithm factory for the given module.

The algorithms registered with this factory will have their names qualified with the module name.

Parameters
checkLicenseIf true, the license is checked for the module.

◆ AlgorithmFactory() [2/2]

Deprecated
"AlgorithmFactory must have a module name."

Member Function Documentation

◆ registerAlgorithm()

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.

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.
configurationOverrideFlags to set for this algorithm.

◆ instantiateAlgorithm() [1/2]

template<typename T>
std::unique_ptr< T > 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 > 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 > 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 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 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 DicomAlgorithmFactory, and DicomGuiAlgorithmFactory.

◆ nameFromId()

static std::string 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()

static std::string 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.

◆ registerAlgorithmIfLicensed()

bool registerAlgorithmIfLicensed ( const Descriptor & descriptor)
protected

Register algorithm with descriptor if license allows it.

Return true if successful.


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