Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::nnInteractive::Interactor Class Referenceabstract

Base class for all nnInteractive interactors. More...

#include <mitknnInteractiveInteractor.h>

Inheritance diagram for mitk::nnInteractive::Interactor:
Collaboration diagram for mitk::nnInteractive::Interactor:

Public Member Functions

virtual ~Interactor ()
 Destructor. More...
 
InteractionType GetType () const
 Returns the interaction type associated with this interactor. More...
 
void SetToolManager (ToolManager *toolManager)
 Sets the ToolManager for this interactor. More...
 
void HandleEvent (InteractionEvent *event)
 Handles an interaction event. More...
 
void Enable (PromptType promptType)
 Enables the interactor for the given prompt type. More...
 
void Disable ()
 Disables the interactor. More...
 
bool IsEnabled () const
 Checks whether the interactor is currently enabled. More...
 
void Reset ()
 Resets the interactor to its initial state. More...
 
std::string GetIcon () const
 Retrieves the SVG icon as a string from module resources. More...
 
std::string GetCursor (PromptType promptType) const
 Retrieves the SVG cursor as a string from module resources based on PromptType. More...
 
virtual bool HasInteractions () const =0
 Checks whether any interactions have occurred. More...
 
virtual void RemoveLastInteraction (PromptType promptType)=0
 Removes the most recent interaction for the given prompt type. More...
 

Public Attributes

Message1< bool > UpdatePreviewEvent
 Event triggered after an interaction has occurred. More...
 

Protected Member Functions

 Interactor (InteractionType type)
 Constructs an interactor with a given type. More...
 
virtual void OnSetToolManager ()
 Called when a ToolManager is assigned. More...
 
virtual void OnHandleEvent (InteractionEvent *event)
 Called when an interaction event is received. More...
 
virtual void OnEnable ()=0
 Called when the interactor is enabled. More...
 
virtual void OnDisable ()=0
 Called when the interactor is disabled. More...
 
virtual void OnReset ()=0
 Called when the interactor is reset. More...
 
ToolManager * GetToolManager () const
 Returns the ToolManager associated with this interactor. More...
 
DataStorage * GetDataStorage () const
 Convenience method for accessing the DataStorage. More...
 
PromptType GetCurrentPromptType () const
 Returns the currently active prompt type. More...
 

Detailed Description

Base class for all nnInteractive interactors.

This class encapsulates the common logic and control interface for nnInteractive interactors. Essentially, they can be enabled, disabled, and reset. Derived classes must respond to these events by overriding the corresponding methods: OnEnable(), OnDisable(), and OnReset().

nnInteractive interactors are typically implemented by reusing an existing MITK interactor or by driving a custom EventStateMachine. In the latter case, OnHandleEvent() can be overridden to forward relevant events to the state machine.

Utility methods such as GetToolManager(), GetDataStorage(), and GetCurrentPromptType() provide essential functionality for derived classes.

Derived classes are pragmatically linked to this base class through their InteractionType, an enum class with enumerators for each interactor. This simplifies handling collections of interactors, such as using InteractionType as a key in maps (see GetType()).

This base class blocks global crosshair navigation via left clicks while an nnInteractive interactor is enabled. This allows derived classes to use plain left clicks in MITK interactor event configurations, which would otherwise require modifier keys.

nnInteractive interactors are mutually exclusive, and the client is responsible for ensuring that no more than one interactor is enabled at a time.

Definition at line 57 of file mitknnInteractiveInteractor.h.

Constructor & Destructor Documentation

◆ ~Interactor()

virtual mitk::nnInteractive::Interactor::~Interactor ( )
virtual

Destructor.

◆ Interactor()

mitk::nnInteractive::Interactor::Interactor ( InteractionType  type)
explicitprotected

Constructs an interactor with a given type.

Note
Enumerators of InteractionType must not be reused across different derived classes. Each interactor must be associated with a unique interaction type.
Parameters
typeThe interaction type associated with this interactor.

Member Function Documentation

◆ Disable()

void mitk::nnInteractive::Interactor::Disable ( )

Disables the interactor.

Derived classes must implement OnDisable() to define specific behavior.

Restores left mouse button crosshair navigation that was blocked while the interactor was enabled.

See also
OnDisable()

◆ Enable()

void mitk::nnInteractive::Interactor::Enable ( PromptType  promptType)

Enables the interactor for the given prompt type.

Derived classes must implement OnEnable() to define specific behavior. To switch the prompt type for an enabled interactor, simply call this method again and it will automatically call Disable() before re-enabling the interactor for the other prompt type.

Crosshair navigation via left click is blocked while the interactor is enabled and restored on Disable().

Parameters
[in]promptTypeThe prompt type (positive or negative) to enable this interactor for.
See also
OnEnable(), Disable(), GetCurrentPromptType()

◆ GetCurrentPromptType()

PromptType mitk::nnInteractive::Interactor::GetCurrentPromptType ( ) const
protected

Returns the currently active prompt type.

The active prompt type is determined by the most recent call to Enable(). Before the first call to Enable(), the default is PromptType::Positive.

Returns
The currently active PromptType.
See also
Enable()

◆ GetCursor()

std::string mitk::nnInteractive::Interactor::GetCursor ( PromptType  promptType) const

Retrieves the SVG cursor as a string from module resources based on PromptType.

The cursor path is automatically determined using the InteractionType and the specified PromptType, e.g., "nnInteractive/PositivePointCursor.svg".

Parameters
[in]promptTypeThe prompt type used to determine the cursor variant.
Returns
The SVG cursor data as a string, or an empty string if the cursor is not found in the resources.

◆ GetDataStorage()

DataStorage* mitk::nnInteractive::Interactor::GetDataStorage ( ) const
protected

Convenience method for accessing the DataStorage.

Retrieves the DataStorage from the associated ToolManager.

Precondition
SetToolManager() must have been called beforehand.
Returns
Pointer to the DataStorage, or nullptr if no ToolManager has been set.
See also
SetToolManager(), GetToolManager()

◆ GetIcon()

std::string mitk::nnInteractive::Interactor::GetIcon ( ) const

Retrieves the SVG icon as a string from module resources.

The icon path is automatically determined based on the InteractionType, e.g., "nnInteractive/Point.svg".

Returns
The SVG icon data as a string, or an empty string if the icon is not found in the resources.

◆ GetToolManager()

ToolManager* mitk::nnInteractive::Interactor::GetToolManager ( ) const
protected

Returns the ToolManager associated with this interactor.

Precondition
SetToolManager() must have been called beforehand.
Returns
Pointer to the associated ToolManager, or nullptr if none has been set.
See also
SetToolManager()

◆ GetType()

InteractionType mitk::nnInteractive::Interactor::GetType ( ) const

Returns the interaction type associated with this interactor.

The interaction type serves as a unique identifier for each interactor, allowing them to be easily distinguished or mapped in data structures.

Returns
The InteractionType that was assigned during construction.

◆ HandleEvent()

void mitk::nnInteractive::Interactor::HandleEvent ( InteractionEvent *  event)

Handles an interaction event.

This method forwards input events to enabled interactors. If a derived class uses a segmentation tool class, override OnHandleEvent() to call Tool::HandleEvent().

Events are only forwarded when the interactor is enabled.

Parameters
[in]eventThe interaction event to handle.
Precondition
The interactor must be enabled for the event to be processed.
See also
OnHandleEvent(), IsEnabled()

◆ HasInteractions()

virtual bool mitk::nnInteractive::Interactor::HasInteractions ( ) const
pure virtual

Checks whether any interactions have occurred.

Derived classes must implement this method to determine whether the interactor has processed any interactions.

Returns
true if at least one interaction has been recorded, false otherwise.

Implemented in mitk::nnInteractive::ScribbleInteractor, mitk::nnInteractive::PointInteractor, mitk::nnInteractive::LassoInteractor, and mitk::nnInteractive::BoxInteractor.

◆ IsEnabled()

bool mitk::nnInteractive::Interactor::IsEnabled ( ) const

Checks whether the interactor is currently enabled.

Returns
true if the interactor has been enabled via Enable() and has not yet been disabled, false otherwise.
See also
Enable(), Disable()

◆ OnDisable()

virtual void mitk::nnInteractive::Interactor::OnDisable ( )
protectedpure virtual

Called when the interactor is disabled.

Derived classes must implement this method to define specific behavior when the interactor is deactivated.

See also
Disable()

◆ OnEnable()

virtual void mitk::nnInteractive::Interactor::OnEnable ( )
protectedpure virtual

Called when the interactor is enabled.

Derived classes must implement this method to define specific behavior when the interactor is activated.

See also
Enable()

◆ OnHandleEvent()

virtual void mitk::nnInteractive::Interactor::OnHandleEvent ( InteractionEvent *  event)
protectedvirtual

Called when an interaction event is received.

Invoked only when the interactor is enabled.

Derived classes can override this method to forward the event to an internal state machine.

Parameters
[in]eventThe interaction event to handle.
See also
HandleEvent()

◆ OnReset()

virtual void mitk::nnInteractive::Interactor::OnReset ( )
protectedpure virtual

Called when the interactor is reset.

Derived classes must implement this method to handle reset logic, ensuring the interactor returns to a clean state.

Note
Consider calling this method also from a derived class destructor to perform clean up.
See also
Reset()

◆ OnSetToolManager()

virtual void mitk::nnInteractive::Interactor::OnSetToolManager ( )
protectedvirtual

Called when a ToolManager is assigned.

Derived classes can override this method to configure tools and set up necessary connections when a ToolManager is assigned.

See also
SetToolManager(), GetToolManager()

◆ RemoveLastInteraction()

virtual void mitk::nnInteractive::Interactor::RemoveLastInteraction ( PromptType  promptType)
pure virtual

Removes the most recent interaction for the given prompt type.

Drops the last recorded prompt of promptType (the most recently placed point, box, scribble, or lasso) and its visualization. Used to undo the last interaction; the prompt type is the one that was active when that interaction was made, which is not necessarily the currently active prompt type. A no-op if no such interaction exists.

Parameters
[in]promptTypeThe prompt type whose most recent interaction should be removed.

Implemented in mitk::nnInteractive::ScribbleInteractor, mitk::nnInteractive::PointInteractor, mitk::nnInteractive::LassoInteractor, and mitk::nnInteractive::BoxInteractor.

◆ Reset()

void mitk::nnInteractive::Interactor::Reset ( )

Resets the interactor to its initial state.

This function clears any ongoing interactions and restores the interactor to a clean state.

Derived classes must implement OnReset() for specific behavior.

See also
OnReset()

◆ SetToolManager()

void mitk::nnInteractive::Interactor::SetToolManager ( ToolManager *  toolManager)

Sets the ToolManager for this interactor.

The ToolManager is responsible for managing segmentation tools potentially used by derived classes. This method should be called as early as possible to ensure that derived classes have access to the tool manager (and data storage) if needed.

If the provided ToolManager is the same as the currently set one, this method is a no-op.

Parameters
[in]toolManagerPointer to the ToolManager to associate with this interactor.
See also
OnSetToolManager(), GetToolManager(), GetDataStorage()

Member Data Documentation

◆ UpdatePreviewEvent

Message1<bool> mitk::nnInteractive::Interactor::UpdatePreviewEvent

Event triggered after an interaction has occurred.

Observers of this event are notified whenever a new interaction is completed (e.g., a point is placed, a box is drawn). The boolean parameter signature matches SegWithPreviewTool::UpdatePreview().

See also
mitk::nnInteractiveTool

Definition at line 207 of file mitknnInteractiveInteractor.h.


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