Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::NonBlockingAlgorithm Class Reference

Base class for algorithms that can run in a background thread. More...

#include <mitkNonBlockingAlgorithm.h>

Inheritance diagram for mitk::NonBlockingAlgorithm:
Collaboration diagram for mitk::NonBlockingAlgorithm:

Public Member Functions

 mitkClassMacroItkParent (NonBlockingAlgorithm, itk::Object)
 
void SetDataStorage (DataStorage &storage)
 Set the DataStorage for this algorithm. More...
 
DataStorage * GetDataStorage ()
 Get the DataStorage associated with this algorithm. More...
 
template<typename T >
void SetParameter (const char *parameter, const T &value)
 Set a parameter of any normal (value) type. More...
 
template<typename T >
void SetPointerParameter (const char *parameter, const itk::SmartPointer< T > &value)
 Set a parameter that holds a smart pointer. More...
 
void SetPointerParameter (const char *parameter, BaseData *value)
 Set a parameter that holds a BaseData pointer (Image, Surface, etc.). More...
 
template<typename TPixel , unsigned int VImageDimension>
void SetItkImageAsMITKImagePointerParameter (const char *parameter, itk::Image< TPixel, VImageDimension > *itkImage)
 Set an ITK image as a MITK Image parameter (raw pointer version). More...
 
template<typename TPixel , unsigned int VImageDimension>
void SetItkImageAsMITKImagePointerParameter (const char *parameter, const itk::SmartPointer< itk::Image< TPixel, VImageDimension >> &itkImage)
 Set an ITK image as a MITK Image parameter (smart pointer version). More...
 
template<typename T >
void GetParameter (const char *parameter, T &value) const
 Get a parameter of any normal (value) type. More...
 
template<typename T >
void GetPointerParameter (const char *parameter, itk::SmartPointer< T > &value) const
 Get a parameter that holds a smart pointer. More...
 
virtual void Reset ()
 Reset the algorithm to its initial state. More...
 
void StartAlgorithm ()
 Start the algorithm asynchronously in a background thread. More...
 
void StartBlockingAlgorithm ()
 Start the algorithm and block until it completes. More...
 
void StopAlgorithm ()
 Wait for the running algorithm thread to finish. More...
 
void TriggerParameterModified (const itk::EventObject &event)
 Callback invoked when a trigger parameter is modified. More...
 
void ThreadedUpdateSuccessful (const itk::EventObject &event)
 GUI-thread callback when the threaded update succeeds. More...
 
void ThreadedUpdateFailed (const itk::EventObject &event)
 GUI-thread callback when the threaded update fails. More...
 

Protected Member Functions

 NonBlockingAlgorithm ()
 
 ~NonBlockingAlgorithm () override
 
void DefineTriggerParameter (const char *)
 
void UnDefineTriggerParameter (const char *)
 
virtual void Initialize (const NonBlockingAlgorithm *other=nullptr)
 
virtual bool ReadyToRun ()
 
virtual bool ThreadedUpdateFunction ()
 
virtual void ThreadedUpdateSuccessful ()
 
virtual void ThreadedUpdateFailed ()
 

Protected Attributes

PropertyList::Pointer m_Parameters
 
WeakPointer< DataStorage > m_DataStorage
 

Detailed Description

Base class for algorithms that can run in a background thread.

NonBlockingAlgorithm provides a framework for running computations asynchronously. Subclasses implement ThreadedUpdateFunction() with their algorithm logic. The algorithm can be started via StartAlgorithm() (non-blocking) or StartBlockingAlgorithm() (blocking). Upon completion, a ResultAvailable or ProcessingError event is emitted via the GUI thread.

Parameters are stored in a PropertyList and can be set via SetParameter(), SetPointerParameter(), or SetItkImageAsMITKImagePointerParameter(). Trigger parameters can be defined so that modifying them automatically restarts the algorithm.

Note
Use the mitkAlgorithmNewMacro() macro for subclass instantiation, as Initialize() cannot be called from the base constructor (virtual dispatch).
See also
NonBlockingAlgorithmEvent
ResultAvailable
ProcessingError
SegmentationSink

Definition at line 86 of file mitkNonBlockingAlgorithm.h.

Constructor & Destructor Documentation

◆ NonBlockingAlgorithm()

mitk::NonBlockingAlgorithm::NonBlockingAlgorithm ( )
protected

◆ ~NonBlockingAlgorithm()

mitk::NonBlockingAlgorithm::~NonBlockingAlgorithm ( )
overrideprotected

Member Function Documentation

◆ DefineTriggerParameter()

void mitk::NonBlockingAlgorithm::DefineTriggerParameter ( const char *  )
protected

◆ GetDataStorage()

DataStorage* mitk::NonBlockingAlgorithm::GetDataStorage ( )

Get the DataStorage associated with this algorithm.

Returns
Pointer to the DataStorage, or nullptr if expired.

◆ GetParameter()

template<typename T >
void mitk::NonBlockingAlgorithm::GetParameter ( const char *  parameter,
T &  value 
) const
inline

Get a parameter of any normal (value) type.

Template Parameters
TThe parameter value type.
Parameters
[in]parameterThe parameter name.
[out]valueThe retrieved parameter value.
Exceptions
std::invalid_argumentif the parameter does not exist.

Definition at line 201 of file mitkNonBlockingAlgorithm.h.

References mitk::GenericProperty< T >::GetValue().

◆ GetPointerParameter()

template<typename T >
void mitk::NonBlockingAlgorithm::GetPointerParameter ( const char *  parameter,
itk::SmartPointer< T > &  value 
) const
inline

Get a parameter that holds a smart pointer.

Template Parameters
TThe type pointed to by the smart pointer.
Parameters
[in]parameterThe parameter name.
[out]valueThe retrieved smart pointer value.
Exceptions
std::invalid_argumentif the parameter does not exist.

Definition at line 229 of file mitkNonBlockingAlgorithm.h.

References mitk::SmartPointerProperty::GetSmartPointer().

◆ Initialize()

virtual void mitk::NonBlockingAlgorithm::Initialize ( const NonBlockingAlgorithm *  other = nullptr)
protectedvirtual

◆ mitkClassMacroItkParent()

mitk::NonBlockingAlgorithm::mitkClassMacroItkParent ( NonBlockingAlgorithm  ,
itk::Object   
)

◆ ReadyToRun()

◆ Reset()

virtual void mitk::NonBlockingAlgorithm::Reset ( )
virtual

Reset the algorithm to its initial state.

Calls Initialize() to re-create default parameters.

◆ SetDataStorage()

void mitk::NonBlockingAlgorithm::SetDataStorage ( DataStorage &  storage)

Set the DataStorage for this algorithm.

Parameters
[in]storageReference to the DataStorage to use.

◆ SetItkImageAsMITKImagePointerParameter() [1/2]

template<typename TPixel , unsigned int VImageDimension>
void mitk::NonBlockingAlgorithm::SetItkImageAsMITKImagePointerParameter ( const char *  parameter,
const itk::SmartPointer< itk::Image< TPixel, VImageDimension >> &  itkImage 
)
inline

Set an ITK image as a MITK Image parameter (smart pointer version).

The ITK image is imported into a mitk::Image and stored as a pointer parameter.

Template Parameters
TPixelThe pixel type of the ITK image.
VImageDimensionThe dimensionality of the ITK image.
Parameters
[in]parameterThe parameter name.
[in]itkImageSmart pointer to the ITK image to store.

Definition at line 182 of file mitkNonBlockingAlgorithm.h.

References mitk::ImportItkImage(), and mitk::Image::New().

◆ SetItkImageAsMITKImagePointerParameter() [2/2]

template<typename TPixel , unsigned int VImageDimension>
void mitk::NonBlockingAlgorithm::SetItkImageAsMITKImagePointerParameter ( const char *  parameter,
itk::Image< TPixel, VImageDimension > *  itkImage 
)
inline

Set an ITK image as a MITK Image parameter (raw pointer version).

The ITK image is imported into a mitk::Image and stored as a pointer parameter.

Template Parameters
TPixelThe pixel type of the ITK image.
VImageDimensionThe dimensionality of the ITK image.
Parameters
[in]parameterThe parameter name.
[in]itkImageThe ITK image to store.

Definition at line 161 of file mitkNonBlockingAlgorithm.h.

References mitk::ImportItkImage(), and mitk::Image::New().

◆ SetParameter()

template<typename T >
void mitk::NonBlockingAlgorithm::SetParameter ( const char *  parameter,
const T &  value 
)
inline

Set a parameter of any normal (value) type.

Template Parameters
TThe parameter value type.
Parameters
[in]parameterThe parameter name.
[in]valueThe parameter value.

Definition at line 112 of file mitkNonBlockingAlgorithm.h.

◆ SetPointerParameter() [1/2]

void mitk::NonBlockingAlgorithm::SetPointerParameter ( const char *  parameter,
BaseData *  value 
)

Set a parameter that holds a BaseData pointer (Image, Surface, etc.).

The value is stored internally as a SmartPointerProperty.

Parameters
[in]parameterThe parameter name.
[in]valueThe BaseData pointer.

◆ SetPointerParameter() [2/2]

template<typename T >
void mitk::NonBlockingAlgorithm::SetPointerParameter ( const char *  parameter,
const itk::SmartPointer< T > &  value 
)
inline

Set a parameter that holds a smart pointer.

Template Parameters
TThe type pointed to by the smart pointer.
Parameters
[in]parameterThe parameter name.
[in]valueThe smart pointer value.

Definition at line 127 of file mitkNonBlockingAlgorithm.h.

References mitk::SmartPointerProperty::New().

◆ StartAlgorithm()

void mitk::NonBlockingAlgorithm::StartAlgorithm ( )

Start the algorithm asynchronously in a background thread.

The algorithm will only start if ReadyToRun() returns true and no kill request is pending. If the thread is already running, additional update requests are queued.

◆ StartBlockingAlgorithm()

void mitk::NonBlockingAlgorithm::StartBlockingAlgorithm ( )

Start the algorithm and block until it completes.

Equivalent to calling StartAlgorithm() followed by StopAlgorithm().

◆ StopAlgorithm()

void mitk::NonBlockingAlgorithm::StopAlgorithm ( )

Wait for the running algorithm thread to finish.

◆ ThreadedUpdateFailed() [1/2]

virtual void mitk::NonBlockingAlgorithm::ThreadedUpdateFailed ( )
protectedvirtual

◆ ThreadedUpdateFailed() [2/2]

void mitk::NonBlockingAlgorithm::ThreadedUpdateFailed ( const itk::EventObject &  event)

GUI-thread callback when the threaded update fails.

Parameters
[in]eventThe event object (unused).

◆ ThreadedUpdateFunction()

virtual bool mitk::NonBlockingAlgorithm::ThreadedUpdateFunction ( )
protectedvirtual

◆ ThreadedUpdateSuccessful() [1/2]

virtual void mitk::NonBlockingAlgorithm::ThreadedUpdateSuccessful ( )
protectedvirtual

◆ ThreadedUpdateSuccessful() [2/2]

void mitk::NonBlockingAlgorithm::ThreadedUpdateSuccessful ( const itk::EventObject &  event)

GUI-thread callback when the threaded update succeeds.

Parameters
[in]eventThe event object (unused).

◆ TriggerParameterModified()

void mitk::NonBlockingAlgorithm::TriggerParameterModified ( const itk::EventObject &  event)

Callback invoked when a trigger parameter is modified.

Automatically restarts the algorithm.

Parameters
[in]eventThe modification event (unused).

◆ UnDefineTriggerParameter()

void mitk::NonBlockingAlgorithm::UnDefineTriggerParameter ( const char *  )
protected

Member Data Documentation

◆ m_DataStorage

WeakPointer<DataStorage> mitk::NonBlockingAlgorithm::m_DataStorage
protected

Definition at line 319 of file mitkNonBlockingAlgorithm.h.

◆ m_Parameters

PropertyList::Pointer mitk::NonBlockingAlgorithm::m_Parameters
protected

Definition at line 317 of file mitkNonBlockingAlgorithm.h.


The documentation for this class was generated from the following file: