![]() |
ImFusion C++ SDK 4.5.0
|
#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) | |
| 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< 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 () | |
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< Descriptor > | m_algorithmDescriptors |
| std::unordered_map< std::type_index, std::string > | m_algorithmIds |
| std::unordered_map< std::string, std::string > | m_deprecatedAlgorithmIds |
| Maps deprecated fully-qualified IDs to their canonical replacements. | |
|
explicit |
Create algorithm factory for the given module.
| module | The 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. |
|
explicit |
| ImFusion::AlgorithmFactory::AlgorithmFactory | ( | ) |
| 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.
| 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 | Optional properties applied when the algorithm is created. |
| 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.
| deprecatedId | Full legacy ID (e.g. "OldModule.OldAlgorithm"). |
| canonicalId | Full current ID the deprecated one should resolve to (e.g. "NewModule.NewAlgorithm"). Both IDs must be fully qualified (including module prefix). |
| 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.
|
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 ImFusion::DicomAlgorithmFactory, and ImFusion::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.