![]() |
ImFusion C++ SDK 4.4.0
|
#include <ImFusion/ML/Operations/CheckDataOperation.h>
Checks if all input data match a set of expected conditions. More...
Checks if all input data match a set of expected conditions.
If parameters are zero or empty, they are not checked.
Public Member Functions | |
| CheckDataOperation (int numDimensions=0, int numImages=0, int numChannels=0, std::string dataType="", const vec3i &dims=vec3i::Zero(), const vec3 &spacing=vec3::Zero(), bool match=false, std::string labelType="", std::vector< int > labelVals={}, const vec3i &labelDims=vec3i::Zero(), int labelChannels=0, bool checkRotationMatrix=false, bool checkDeformation=false, bool checkShiftScale=false, bool failOnError=true, std::string savePathOnError="", bool labelValsCheckSubset=false) | |
| std::shared_ptr< SharedImageSet > | processImages (std::shared_ptr< SharedImageSet > input) const override |
| Virtual function that every subclass should override. | |
| void | process (DataItem &item) override |
| Main function that processes a DataItem in-place, may throw OperationException The data to be processed is determined by the active fields (if set) and the processing policy otherwise (if set), otherwise all fields are processed. | |
| bool | doesNotModifyInput () const override |
| Returns whether the operation is guaranteed to not modify its input element, either because it computes its output out-of-place or because it is a no-op. | |
| bool | checkCondition (std::string message, bool condition, std::shared_ptr< SharedImageSet > input) const |
| Wrapper of checking condition and act according to setting of p_failOnError, and write offending images to p_savePathOnError. | |
| std::optional< std::string > | checkType (PixelType imgType, bool label=false) const |
| Check if the pixel type matches the expected type from the parameters. | |
| virtual std::shared_ptr< SharedImageSet > | process (std::shared_ptr< SharedImageSet > input) |
| Utility function to directly apply an operation on a SharedImageSet irrespective of active fields and processing policy. | |
| virtual std::shared_ptr< KeypointSet > | process (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< BoundingBoxSet > | process (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< SharedImageSet > | process (std::unique_ptr< SharedImageSet > input) final |
| Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden). | |
| Public Member Functions inherited from ImFusion::ML::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. | |
| 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::string & | name () const |
| Returns the name of the operation. | |
| virtual bool | configure (const Properties &properties) |
| Configure an Operation with the given properties and return whether the configuration was successful. | |
| virtual Properties | configuration () const |
| Return the Operation configuration. | |
| 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. | |
| virtual void | setComputingDevice (ML::ComputingDevice device) |
| Set the computing device selection strategy. | |
| 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::string & | recordIdentifier () const |
| Get the operation's record identifier. | |
| virtual void | setRecordIdentifier (const std::string &recordIdentifier) |
| Set the operation's record identifier. | |
| const std::string & | logDomain () 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< int > | p_numDimensions = {"num_dimensions", 0, this, ML::ParamRequired::No} |
| Expected number of dimensions in the input. Set to 0 to skip this check. | |
| OpParam< int > | p_numImages = {"num_images", 0, this, ML::ParamRequired::No} |
| Expected number of images in the input. Set to 0 to skip this check. | |
| OpParam< int > | p_numChannels = {"num_channels", 0, this, ML::ParamRequired::No} |
| Expected number of channels in the input. Set to 0 to skip this check. | |
| OpParam< std::string > | p_dataType = {"data_type", "", this, ML::ParamRequired::No} |
| Expected datatype of input. Must be one of: ["", "float", "uint8", "int8", "uint16", "int16", "uint32", "int32", "double"]. Empty string skips this check. | |
| OpParam< vec3i > | p_dims = {"dimensions", vec3i::Zero(), this, ML::ParamRequired::No} |
| Expected spatial dimensions [width, height, depth] of input image. Set all dimensions to 0 to skip checking it. | |
| OpParam< vec3 > | p_spacing = {"spacing", vec3::Zero(), this, ML::ParamRequired::No} |
| Expected spacing [x, y, z] of input image in mm. Set all components to 0 to skip checking it. | |
| OpParam< bool > | p_labelMatchInput = {"label_match_input", false, this, ML::ParamRequired::No} |
| Whether label dimensions and channel count must match the input image. | |
| OpParam< std::string > | p_labelType = {"label_type", "", this, ML::ParamRequired::No} |
| Expected datatype of labels. Must be one of: ["", "float", "uint8", "int8", "uint16", "int16", "uint32", "int32", "double"]. Empty string skips this check. | |
| OpParam< std::vector< int > > | p_labelValues = {"label_values", std::vector<int>{}, this, ML::ParamRequired::No} |
| List of required label values (excluding 0). No other values are allowed. When check_label_values_are_subset is false, all must be present. Empty list skips this check. | |
| OpParam< bool > | p_checkLabelValuesAreSubset = {"check_label_values_are_subset", false, this, ML::ParamRequired::No} |
| Whether to check if the label values are a subset of the label values provided with label_values, otherwise check if all values are present in the label image. | |
| OpParam< vec3i > | p_labelDims = {"label_dimensions", vec3i::Zero(), this, ML::ParamRequired::No} |
| Expected spatial dimensions [width, height, depth] of label image. Set all dimensions to 0 to skip checking it. | |
| OpParam< int > | p_labelChannels = {"label_channels", 0, this, ML::ParamRequired::No} |
| Expected number of channels in the label image. Set to 0 to skip this check. | |
| OpParam< bool > | p_checkRotationMatrix = {"check_rotation_matrix", false, this, ML::ParamRequired::No} |
| Whether to verify the input image has no rotation matrix. | |
| OpParam< bool > | p_checkDeformation = {"check_deformation", false, this, ML::ParamRequired::No} |
| Whether to verify the input image has no deformation. | |
| OpParam< bool > | p_checkShiftScale = {"check_shift_scale", false, this, ML::ParamRequired::No} |
| Whether to verify the input image has identity intensity transformation. | |
| OpParam< bool > | p_failOnError = {"fail_on_error", true, this, ML::ParamRequired::No} |
| Whether to raise an exception on validation failure (True) or just log an error (False). | |
| OpParam< std::string > | p_savePathOnError = {"save_path_on_error", "", this, ML::ParamRequired::No} |
| Path where to save the failing input as an ImFusion file (.imf) when validation fails. Empty string disables saving. | |
Additional Inherited Members | |
| Public Types inherited from ImFusion::ML::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 ImFusion::ML::Operation | |
| static std::string | processingPolicyToString (const ProcessingPolicy policy) |
| static ProcessingPolicy | stringToProcessingPolicy (const std::string &s) |
| static std::unique_ptr< Operation > | createFromFactories (const Operation::Specs &specs) |
| Helper function to create an operation from any factory (both C++ and Python factories are tested). | |
| Protected Member Functions inherited from ImFusion::ML::Operation | |
| virtual std::shared_ptr< BoundingBoxSet > | processBoxes (std::shared_ptr< BoundingBoxSet > input) const |
| Virtual function that every subclass should override. | |
| virtual std::shared_ptr< KeypointSet > | processPoints (std::shared_ptr< KeypointSet > input) const |
| Virtual function that every subclass should override. | |
| virtual std::shared_ptr< SharedImageSet > | processVectors (std::shared_ptr< SharedImageSet > input) const |
| Virtual function that every subclass should override. | |
| virtual std::shared_ptr< TensorSet > | processTensors (std::shared_ptr< TensorSet > input) const |
| Virtual function that every subclass should override. | |
| 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 * > ¶mSelection) 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 inherited from ImFusion::ML::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::string > | m_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, ElementType > | m_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< PreProcessHook > | m_preProcessHooks |
| std::vector< PostProcessHook > | m_postProcessHooks |
| std::vector< PreProcessHook > | m_temporaryPreProcessHooks |
| Pre-process hooks that will be used for the next processing call only. | |
| std::vector< PostProcessHook > | m_temporaryPostProcessHooks |
| Post-process hooks that will be used for the next processing call only. | |
|
overridevirtual |
Virtual function that every subclass should override.
Default implementation does nothing, so if those function are not implemented in a derived class, they won't act on the input in any way.
Reimplemented from ImFusion::ML::Operation.
|
overridevirtual |
Main function that processes a DataItem in-place, may throw OperationException The data to be processed is determined by the active fields (if set) and the processing policy otherwise (if set), otherwise all fields are processed.
Reimplemented from ImFusion::ML::Operation.
|
inlineoverridevirtual |
Returns whether the operation is guaranteed to not modify its input element, either because it computes its output out-of-place or because it is a no-op.
This can be used to decide whether a copy of the input should be made before calling the Operation::process function. Note that this only relates to the overloads taking specific elements as inputs (e.g. images, keypoints, etc.), since the Operation::process(DataItem& item) function always modifies its input.
Reimplemented from ImFusion::ML::Operation.
|
virtual |
Utility function to directly apply an operation on a SharedImageSet irrespective of active fields and processing policy.
Reimplemented from ImFusion::ML::Operation.
|
virtual |
Utility function to directly apply an operation on a set of KeypointSet irrespective of active fields and processing policy.
Reimplemented from ImFusion::ML::Operation.
|
virtual |
Utility function to directly apply an operation on a set of BoundingBoxSet irrespective of active fields and processing policy.
Reimplemented from ImFusion::ML::Operation.
|
finalvirtual |
Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden).
Reimplemented from ImFusion::ML::Operation.