ImFusion SDK 4.3
InverseOperation Class Reference

#include <ImFusion/ML/Operations/InverseOperation.h>

Operation that inverts a specific operation by using the InversionComponent. More...

+ Inheritance diagram for InverseOperation:

Detailed Description

Operation that inverts a specific operation by using the InversionComponent.

This operation provides a way to invert a specific operation by its record identifier. It retrieves the inverse operation specifications from the InversionComponent of the processed elements, creates an appropriate inverse operation, and then after successful processing, removes the inversion information.

The process works as follows:

  1. The InverseOperation searches for elements with an InversionComponent
  2. It retrieves the inverse specifications stored for the given record identifier
  3. It creates and configures an operation based on these specifications
  4. It applies this inverse operation to the input
  5. After successful processing, it removes the inversion information from all processed elements

Note: This inverts only operations that explicitly support inversion and that have recorded themselves with the specified record identifier. Operations must derive from InvertibleOperation and implement inverseSpecs() to provide the parameters needed for inversion.

Important: The inversion info is popped from the InversionComponent of the processed elements after processing, which guarantees LIFO order when operations with the same identifier are applied multiple times.

Usage example:

// Apply a padding operation with a specific record identifier which enables recording of information needed for the inversion.
auto padOp = std::make_unique<PadOperation>(vec2i(10, 10), vec2i(10, 10), vec2i(0, 0));
Properties props;
props.setParam("record_identifier", "MyPadding");
padOp->configure(props);
auto paddedImage = padOp->process(input);
// Create an inverse operation to undo the padding,
// using the record identifier as target identifier for the inversion.
auto invOp = std::make_unique<InverseOperation>("MyPadding");
auto unpadded = invOp->process(paddedImage);
Storage container for serialization of arbitrary types, internally backed by strings.
Definition Properties.h:50
void setParam(const std::string &name, const T &value, const T &defaultValue)
Set a parameter with arbitrary type and a default value.
Definition Properties.h:424
T make_unique(T... args)

Performance: The InverseOperation reuses the created inverse operation when possible, only creating a new one when the type changes, and only reconfiguring when the properties change. If element-specific properties are needed, they should be set by the Operation that is to be inverted in process() via data components and used in process() of the InverseOperation.

Public Member Functions

 InverseOperation (const std::string &targetIdentifier="")
 Constructor that takes an Operation record identifier as target for inversion.
 
void process (DataItem &input) override
 Process the input by finding and applying the inverse operation.
 
std::shared_ptr< SharedImageSetprocess (std::shared_ptr< SharedImageSet > input) override
 Utility method to process a SharedImageSet directly.
 
bool configure (const Properties &properties) override
 Configure the operation from properties.
 
Properties configuration () const override
 Get the current configuration.
 
bool doesNotModifyInput () const override
 This operation does not modify its input directly.
 
void setComputingDevice (ML::ComputingDevice device) override
 Set the computing device selection strategy.
 
- Public Member Functions inherited from Operation
 Operation (std::string name, ProcessingPolicy processingPolicy)
 Derived classes must specify a name and whether, by default, the operation should also be applied to label maps.
 
virtual std::shared_ptr< KeypointSetprocess (std::shared_ptr< KeypointSet > input)
 Utility function to directly apply an operation on a set of KeypointSet irrespective of active fields and processing policy.
 
virtual std::shared_ptr< BoundingBoxSetprocess (std::shared_ptr< BoundingBoxSet > input)
 Utility function to directly apply an operation on a set of BoundingBoxSet irrespective of active fields and processing policy.
 
virtual std::unique_ptr< SharedImageSetprocess (std::unique_ptr< SharedImageSet > input) final
 Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden)
 
void addTemporaryPreProcessHook (PreProcessHook hook)
 Add a temporary hook that will only be active for the next process call and then automatically removed after the DataItem is processed.
 
void addTemporaryPostProcessHook (PostProcessHook hook)
 Add a temporary hook that will only be active for the next process call and then automatically removed after the DataItem is processed.
 
virtual bool checkRequiredItemsTypes (const DataItem &item) const
 Checks if the data item holds fields with types required by the operation.
 
const std::stringname () const
 Returns the name of the operation.
 
void setActiveFields (std::optional< std::unordered_set< std::string > > activeFields)
 
std::optional< std::unordered_set< std::string > > activeFields () const
 
virtual void setProcessingPolicy (ProcessingPolicy policy)
 
ProcessingPolicy processingPolicy () const
 
std::optional< uint32_t > seed () const
 Return the current seed (if there is one)
 
virtual void seedRandomEngine (uint32_t seed)
 Set a seed for the random generator.
 
ML::ComputingDevice computingDevice () const
 Get the computing device.
 
void configFailed (const std::string &missingParam) const
 Helper function to show an error message due to a bad configuration.
 
void logDeprecatedParam (const std::string &oldName, const std::string &newName) const
 Helper function to print a warning because of a deprecated parameter has been specified.
 
bool errorOnUnexpectedBehaviour () const
 Get the policy whether to treat unexpected behavior warnings as errors.
 
virtual void setErrorOnUnexpectedBehaviour (bool error)
 Treat unexpected behavior warnings as errors.
 
void registerParameter (ParameterBase *param)
 Register a parameter so that the operation knows about it, and can automatically configure it (unless it has been marked as manually configured parameter via the Operation::setManuallyConfiguredParameters method).
 
std::vector< ParameterBase * > parameters () const
 Return the list of registered parameters.
 
virtual bool supportsInversion () const
 Whether the operation supports inversion. Returns False unless the operation derives from InvertibleOperation.
 
const std::stringrecordIdentifier () const
 Get the operation's record identifier.
 
virtual void setRecordIdentifier (const std::string &recordIdentifier)
 Set the operation's record identifier.
 
const std::stringlogDomain () const
 Log domain for AdvancedParameter.
 
std::optional< std::unordered_set< std::string > > selectedFields (const DataItem &item)
 Get the fields on which the operation will be applied.
 

Public Attributes

OpParam< std::stringp_targetIdentifier = {"target_identifier", "", this, ParamRequired::Yes}
 The record identifier to find the inverse operation for.
 

Protected Member Functions

bool setupInverseOperationByIdentifier (DataItem &input, const std::string &recordIdentifier)
 Set up the inverse operation based on the record identifier.
 
- Protected Member Functions inherited from Operation
virtual std::shared_ptr< SharedImageSetprocessImages (std::shared_ptr< SharedImageSet > input) const
 Virtual function that every subclass should override.
 
virtual std::shared_ptr< BoundingBoxSetprocessBoxes (std::shared_ptr< BoundingBoxSet > input) const
 Virtual function that every subclass should override.
 
virtual std::shared_ptr< KeypointSetprocessPoints (std::shared_ptr< KeypointSet > input) const
 Virtual function that every subclass should override.
 
virtual std::shared_ptr< SharedImageSetprocessVectors (std::shared_ptr< SharedImageSet > input) const
 Virtual function that every subclass should override.
 
virtual std::shared_ptr< TensorSetprocessTensors (std::shared_ptr< TensorSet > input) const
 
void throwOperationError (const std::string &msg) const
 Helper function to throw an exception due to a runtime error.
 
void warnOperationUnexpectedBehaviour (const std::string &msg) const
 Helper function to warn about a behavior different than asked.
 
bool inputIsEmptyOrNull (const SharedImageSet *input) const
 Helper function to check if the input is empty or null and print a warning if so.
 
virtual bool useGPU (const SharedImageSet *input) const
 Helper function that returns which device the operation should choose based on its configuration and a given input.
 
void prepareInputForDevice (SharedImageSet &input) const
 Make sure the input is on the correct device for the current device strategy.
 
virtual bool allowChannelBatchOnGPU () const
 Whether the operation implements channel-batching so that it can still be run on input with more than 4 channels.
 
bool configureOnly (const Properties &properties, const std::vector< ParameterBase * > &paramSelection) noexcept
 Helper method to configure only a subset of parameters.
 
void setManuallyConfiguredParameters (const std::vector< ParameterBase * > &manuallyConfiguredParams)
 Disable the auto-configuration of some of the parameters so that they can be parsed manually (in the configure function of the derived class).
 
void applyPreProcessHooks (DataElement *element)
 Apply the current pre-process hooks to an element.
 
void applyPostProcessHooks (DataElement *element)
 Apply the current post-process hooks to an element.
 

Protected Attributes

std::shared_ptr< Operationm_inverseOperation
 The inverse operation that will be applied.
 
std::vector< InversionComponent * > m_inversionComponents
 Collection of InversionComponents from all elements that match the target identifier.
 
- Protected Attributes inherited from Operation
std::string m_name
 
ProcessingPolicy m_processingFieldsPolicy
 Flag specifying whether labels should be processed by default (when no active field has been specified)
 
std::optional< std::unordered_set< std::string > > m_activeFields
 Run the Operation only on those fields (if empty, will select suitable fields based on the current processing policy) when calling process()
 
std::unordered_set< std::stringm_alreadyWarned
 Set of warnings about unexpected behavior that have already been printed.
 
bool m_errorOnUnexpectedBehaviour = false
 Whether to throw an exception instead of warning about unexpected behavior.
 
std::optional< uint32_t > m_seed
 
Random::Generator m_randGenerator
 
ML::ComputingDevice m_device = ML::ComputingDevice::GPUIfOpenGl
 
std::vector< ParameterBase * > m_params
 All registered parameters.
 
std::vector< ParameterBase * > m_manuallyConfiguredParams
 All registered parameters that should not be configured automatically.
 
std::unordered_map< std::string, ElementTypem_requiredFieldsTypes
 List of all required field types used by checkRequiredItemsTypes.
 
std::string m_recordIdentifier
 User-provided unique identifier for this operation, used for recording processing history and inversion.
 
std::vector< PreProcessHookm_preProcessHooks
 
std::vector< PostProcessHookm_postProcessHooks
 
std::vector< PreProcessHookm_temporaryPreProcessHooks
 Pre-process hooks that will be used for the next processing call only.
 
std::vector< PostProcessHookm_temporaryPostProcessHooks
 Post-process hooks that will be used for the next processing call only.
 

Additional Inherited Members

- Public Types inherited from Operation
enum  ProcessingPolicy { EverythingExceptLabels = 0 , Everything , OnlyLabels }
 Policy used by default when selecting on the fields on which the operation will be applied Note that "Labels" here refers to the target tag, not to be confused with Data::Modality::LABEL. More...
 
using PreProcessHook = std::function<void(Operation&, DataElement*)>
 
using PostProcessHook = std::function<void(Operation&, DataElement*)>
 
- Static Public Member Functions inherited from Operation
static std::string processingPolicyToString (const ProcessingPolicy policy)
 
static ProcessingPolicy stringToProcessingPolicy (const std::string &s)
 
static std::unique_ptr< OperationcreateFromFactories (const Operation::Specs &specs)
 Helper function to create an operation from any factory (both C++ and Python factories are tested)
 

Member Function Documentation

◆ process() [1/2]

void process ( DataItem & input)
overridevirtual

Process the input by finding and applying the inverse operation.

Reimplemented from Operation.

◆ process() [2/2]

std::shared_ptr< SharedImageSet > process ( std::shared_ptr< SharedImageSet > input)
overridevirtual

Utility method to process a SharedImageSet directly.

Parameters
inputThe input image set
Returns
The processed image set with the operation inverted

Reimplemented from Operation.

◆ configure()

bool configure ( const Properties & properties)
overridevirtual

Configure the operation from properties.

Reimplemented from Operation.

◆ configuration()

Properties configuration ( ) const
overridevirtual

Get the current configuration.

Reimplemented from Operation.

◆ doesNotModifyInput()

bool doesNotModifyInput ( ) const
inlineoverridevirtual

This operation does not modify its input directly.

Reimplemented from Operation.

◆ setComputingDevice()

void setComputingDevice ( ML::ComputingDevice device)
overridevirtual

Set the computing device selection strategy.

Reimplemented from Operation.

◆ setupInverseOperationByIdentifier()

bool setupInverseOperationByIdentifier ( DataItem & input,
const std::string & recordIdentifier )
protected

Set up the inverse operation based on the record identifier.

Returns
true if the inverse operation was successfully set up, false otherwise

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