![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Base/AlgorithmFactory.h>
Interface for algorithm factories. More...
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.
You may also query algorithms compatible with a given set of data:
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< Algorithm > | instantiateAlgorithm (const std::string &id, const DataList &data) const |
Create an instance of the algorithm with the given id. | |
virtual std::unique_ptr< IoAlgorithm > | instantiateIoAlgorithm (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< Descriptor > | compatibleDescriptors (const DataList &data) const |
Returns the descriptors of non-I/O algorithms registered with this factory which are compatible with data. | |
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 > | compatibleIoDescriptors (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< Descriptor > | algorithmDescriptors () const |
Returns all algorithm descriptors registered with this factory. | |
virtual std::vector< Descriptor > | ioAlgorithmDescriptors () 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 () | |
![]() | |
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. | |
![]() | |
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 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< Descriptor > | m_algorithmDescriptors |
std::unordered_map< std::type_index, std::string > | m_algorithmIds |
![]() | |
std::string | m_factoryModule |
bool | m_checkLicense |
|
explicit |
Create algorithm factory for the given module.
The algorithms registered with this factory will have their names qualified with the module name.
checkLicense | If true, the license is checked for the module. |
AlgorithmFactory | ( | ) |
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.
id | The 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"). |
guiName | The 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). |
flags | Optional AlgorithmAttributes to set for this algorithm. |
configurationOverride | Flags to set for this algorithm. |
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.
|
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.
|
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.
|
virtual |
Returns the descriptors of the algorithm with the given id.
matchGuiName | If 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. |
|
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.
|
staticprotected |
Create a GUI name from the algorithm id.
Used as a convenience fallback if no name is specified.
|
staticprotected |
Create a standard algorithm id from the GUI name.
Used as a deprecation fallback if no id is specified.
|
protected |
Register algorithm with descriptor if license allows it.
Return true if successful.