![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Reg/SimilarityMeasureFactory.h>
The SimilarityMeasureFactory class provides a generic interface to any kind of SimilarityMeasure. More...
The SimilarityMeasureFactory class provides a generic interface to any kind of SimilarityMeasure.
Different types of SimilarityMeasures, with one or multiple implementations, can be registered to the factory during runtime. A set of default SimilarityMeasures are always registered.
Because different SimilarityMeasure may have different parameters, SimilarityMeasureFactory offers a generic way to access this parameters with the help of the ImFusion::Properties interface. Each SimilarityMeasureFactory contains a persistent Properties instance that contains the parameters of the current mode. This way, the Properties of a SimilarityMeasure can be accessed and modified without creating an actual instance of the SimilarityMeasure. Together with the ImFusion::PropertiesWidget it is relatively simple to generate a generic user interface to configure any kind of SimilarityMeasure.
Because some SimilarityMeasures use large amounts of (V)RAM for opimizations, a SimilarityMeasure instance should only be created while needed and deleted afterwards.
Basic usage:
Exposing SimilarityMeasure properties in UI:
,
Public Types | |
enum | Mode : int { SAD = 0 , SSD = 1 , NCC = 2 , LNCC = 3 , LC2 = 4 , MI = 5 , HIST = 6 , ML = 7 , NGF = 8 , SSIM = 9 , DP = 10 , USERDEFINED = 100 } |
Enumeration of available similarity measures. | |
Public Member Functions | |
SimilarityMeasureFactory (Mode mode=Mode::NCC, Device device=Device_GL) | |
std::vector< Mode > | availableModes () const |
Returns all available modes of SimilarityMeasures in this factory. | |
std::vector< Device > | availableDevices (Mode mode) const |
Returns all available implementations for a given mode. | |
std::string | name (Mode mode) const |
Returns the full name of the SimilarityMeasure with the given mode. | |
std::string | acronym (Mode mode) const |
Returns the acronym of the SimilarityMeasure with the given mode. | |
Mode | mode () const |
Returns the current SimilarityMeasure mode that the factory will generate. | |
Device | device () const |
Returns the current device for the mode generated by the factory. | |
void | setMode (Mode mode) |
Sets the SimilarityMeasure mode the factory will generate If the current device is not available for this mode, the device will be changed to the first supported for this mode. | |
bool | setDevice (Device device) |
Sets the device for the mode generated by the factory. | |
virtual void | setWeights (const SharedImage *weights1, const SharedImage *weights2) |
Sets the images to use as weights for the similarity metric. | |
void | configure (const Properties *p) override |
Configure this object instance by de-serializing the given Properties. | |
void | configuration (Properties *p) const override |
Serialize the current object configuration into the given Properties object. | |
void | similarityMeasureConfiguration (Properties *p, bool filterUnrelated=true) const |
Retrieves the configuration for a SimilarityMeasure of the current mode. | |
void | configureSimilarityMeasure (const Properties *p) |
Sets the configuration for the current SimilarityMeasure mode. | |
template<typename T> | |
void | setSimilarityMeasureParam (const std::string &name, const T &value) |
Convenient method to directly set a parameter of the SimilarityMeasure. | |
template<typename T> | |
bool | similarityMeasureParam (const std::string &name, T &value) |
Convenient method to directly retrieve a parameter of the SimilarityMeasure. | |
SimilarityMeasureImpl * | generate (SharedImage *img1, SharedImage *img2) |
Generates a new SimilarityMeasure instance. | |
![]() | |
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. | |
![]() | |
virtual void | configureDefaults () |
Retrieve the properties of this object, replaces values with their defaults and sets it again. | |
void | registerParameter (ParameterBase *param) |
Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration(). | |
void | unregisterParameter (const ParameterBase *param) |
Remove the given Parameter or SubProperty from the list of registered parameters. | |
Configurable (const Configurable &rhs) | |
Configurable (Configurable &&rhs) noexcept | |
Configurable & | operator= (const Configurable &) |
Configurable & | operator= (Configurable &&) noexcept |
Static Public Member Functions | |
template<class T> | |
static bool | registerSimilarityMeasure (Mode mode, Device device, const std::string &name, const std::string &acronym, std::function< SimilarityMeasureImpl *(SharedImage *, SharedImage *)> createFunc=nullptr) |
Registers a new SimilarityMeasure to the factory. | |
static void | unregisterSimilarityMeasure (Mode mode, Device device) |
Removes a previous registered similarity measure. | |
Additional Inherited Members | |
![]() | |
Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
![]() | |
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 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 . | |
![]() | |
std::string | m_factoryModule |
bool | m_checkLicense |
![]() | |
std::vector< Param > | m_params |
List of all registered Parameter and SubProperty instances. | |
|
inlinestatic |
Registers a new SimilarityMeasure to the factory.
The template parameter must derive from ImFusion::SimilarityMeasureImpl. When registering multiple implementations for the same mode, the same name and acronym can be used. Example:
bool setDevice | ( | Device | device | ) |
Sets the device for the mode generated by the factory.
If the given device is not supported by the current mode, the current device remains unchanged and false is returned.
|
virtual |
Sets the images to use as weights for the similarity metric.
Setting weights only has effect if the similarity measure supports weights.
|
overridevirtual |
Configure this object instance by de-serializing the given Properties.
The default implementation will do so automatically for all registered Parameter and SubProperty instances.
Reimplemented from Configurable.
|
overridevirtual |
Serialize the current object configuration into the given Properties object.
The default implementation will do so automatically for all registered Parameter and SubProperty instances.
Reimplemented from Configurable.
void similarityMeasureConfiguration | ( | Properties * | p, |
bool | filterUnrelated = true ) const |
Retrieves the configuration for a SimilarityMeasure of the current mode.
If filterUnrelated is true, p will only contain parameters of the current SimilarityMeasure mode. Otherwise it may also contain parameters previous selected modes (which won't affect the SimilarityMeasure).
void configureSimilarityMeasure | ( | const Properties * | p | ) |
Sets the configuration for the current SimilarityMeasure mode.
The parameters are copied to the Properties instance of the factory, i.e. existing parameters will be overridden, all others stay unmodified.
void setSimilarityMeasureParam | ( | const std::string & | name, |
const T & | value ) |
Convenient method to directly set a parameter of the SimilarityMeasure.
E.g. to set the 'patchSize' parameter of the LC2 SimilarityMeasure to 5:
bool similarityMeasureParam | ( | const std::string & | name, |
T & | value ) |
Convenient method to directly retrieve a parameter of the SimilarityMeasure.
Returns true if the parameter exists.
SimilarityMeasureImpl * generate | ( | SharedImage * | img1, |
SharedImage * | img2 ) |
Generates a new SimilarityMeasure instance.
The actual instance created depends on the current mode and device of the factory. The instance is automatically configured with the current SimilarityMeasure properties of the factory. Once generated the SimilarityMeasure instance will be completely independent of the factory, e.g. any changes to the factory's mode, device or properties will NOT affect the instance. The caller is responsible for deleting the instance.