Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitknnInteractiveToolGUI Class Reference

GUI widget for the nnInteractiveTool segmentation tool. More...

#include <QmitknnInteractiveToolGUI.h>

Inheritance diagram for QmitknnInteractiveToolGUI:
Collaboration diagram for QmitknnInteractiveToolGUI:

Public Member Functions

 mitkClassMacro (QmitknnInteractiveToolGUI, QmitkSegWithPreviewToolGUIBase)
 
- Public Member Functions inherited from QmitkSegWithPreviewToolGUIBase
 mitkClassMacro (QmitkSegWithPreviewToolGUIBase, QmitkToolGUI)
 
Pointer Clone () const
 
virtual bool GetMode2D () const
 
- Public Member Functions inherited from QmitkToolGUI
 mitkClassMacroItkParent (QmitkToolGUI, itk::Object)
 
void SetTool (mitk::Tool *tool)
 Associates the given tool with this GUI, emitting NewToolAssociated. More...
 
void SetMultiLabelInspector (QmitkMultiLabelInspector *inspector)
 Provides the segmentation view's label inspector to this GUI. More...
 
QmitkMultiLabelInspector * GetMultiLabelInspector () const
 Returns the inspector associated with this GUI, or null if none. More...
 
void Register () const override
 Intentional no-op; prevents ITK reference counting from interfering with Qt ownership. More...
 
void UnRegister () const ITK_NOEXCEPT ITK_OVERRIDE
 Intentional no-op; prevents ITK reference counting from interfering with Qt ownership. More...
 
void SetReferenceCount (int) override
 Intentional no-op; prevents ITK reference counting from interfering with Qt ownership. More...
 
 ~QmitkToolGUI () override
 

Static Public Member Functions

static Pointer New ()
 

Protected Types

using InteractionType = mitk::nnInteractive::InteractionType
 Alias for mitk::nnInteractive::InteractionType. More...
 
using PromptType = mitk::nnInteractive::PromptType
 Alias for mitk::nnInteractive::PromptType. More...
 
- Protected Types inherited from QmitkSegWithPreviewToolGUIBase
using EnableConfirmSegBtnFunctionType = std::function< bool(bool)>
 

Protected Member Functions

 QmitknnInteractiveToolGUI ()
 Constructs the GUI with confirm segmentation button disabled by default. More...
 
 ~QmitknnInteractiveToolGUI () override
 Destructor. Restores any override cursors and disconnects events. More...
 
void InitializeUI (QBoxLayout *mainLayout) override
 Initializes the UI widgets and connects signals. More...
 
void InitializePromptType ()
 Initializes the prompt type button group and shortcut. More...
 
void InitializeInteractorButtons ()
 Initializes the interactor toggle buttons with icons and shortcuts. More...
 
void EnableInitializeButtons (bool enabled)
 Enables or disables the initialize and settings buttons. More...
 
void OnInitializeButtonToggled (bool checked)
 Handles the initialize button toggle event. More...
 
void OnSettingsButtonClicked ()
 Opens the nnInteractive preferences dialog. More...
 
void OnResetInteractionsButtonClicked ()
 Resets all interactions and switches to positive prompt type. More...
 
void OnUndoButtonClicked ()
 Undoes the last interaction and refreshes the Undo button state. More...
 
void OnAutoRefineCheckBoxToggled (bool checked)
 Handles auto-refine checkbox toggle. More...
 
void OnAutoZoomCheckBoxToggled (bool checked)
 Handles auto-zoom checkbox toggle. More...
 
void OnPromptTypeChanged ()
 Handles prompt type changes between positive and negative. More...
 
void OnInteractorToggled (mitk::nnInteractive::InteractionType interactionType, bool checked)
 Handles toggling of an interactor button. More...
 
void OnActiveLabelChanged (const mitk::MultiLabelSegmentation::LabelValueVectorType &labels)
 Reacts to a change of the selected label in the host's label inspector while a session is running. More...
 
void OnConfirmCleanUp (bool isConfirmed)
 Handles cleanup confirmation from the tool. More...
 
void OnPreviewUpdated ()
 Handles the tool's PreviewUpdatedEvent. More...
 
void OnToolDeactivated ()
 Handles the tool's DeactivatedEvent. More...
 
void OnSessionEnded ()
 Handles the tool's SessionEndedEvent. More...
 
void OnSessionExpired ()
 Handles the tool's SessionExpiredEvent. More...
 
void OnHeartbeatTimeout ()
 Sends a keep-alive heartbeat to the remote nnInteractive server. More...
 
void UpdateModelLicenseDisplay (const std::optional< std::string > &license)
 Shows the model checkpoint license below the Initialize button, or clears it when passed std::nullopt. More...
 
mitk::nnInteractiveTool * GetTool ()
 Returns the connected nnInteractiveTool. More...
 
void UncheckOtherInteractorButtons (QPushButton *interactorButton)
 Unchecks all interactor buttons except the specified one. More...
 
bool Install ()
 Checks if nnInteractive is installed and shows the install dialog if not. More...
 
- Protected Member Functions inherited from QmitkSegWithPreviewToolGUIBase
 QmitkSegWithPreviewToolGUIBase (bool mode2D, bool enableProcessingOfAllTimeSteps=true)
 
 ~QmitkSegWithPreviewToolGUIBase () override
 
virtual void DisconnectOldTool (mitk::SegWithPreviewTool *oldTool)
 
virtual void ConnectNewTool (mitk::SegWithPreviewTool *newTool)
 
void BusyStateChanged (bool isBusy) override
 Called when the tool's busy state changes. Override to enable/disable UI elements. More...
 
virtual void EnableWidgets (bool enabled)
 
template<class TTool >
TTool * GetConnectedToolAs ()
 
void SetMergeStyle (mitk::MultiLabelSegmentation::MergeStyle mergeStyle)
 
void SetOverwriteStyle (mitk::MultiLabelSegmentation::OverwriteStyle overwriteStyle)
 
QPushButton * GetConfirmSegmentationButton () const
 
QCheckBox * GetPreviewVisibilityCheckBox () const
 
QLabel * GetPreviewLabel () const
 
- Protected Member Functions inherited from QmitkToolGUI
 QmitkToolGUI ()=default
 

Additional Inherited Members

- Signals inherited from QmitkToolGUI
void NewToolAssociated (mitk::Tool *)
 Emitted when a new tool is associated with this GUI via SetTool(). More...
 
- Protected Slots inherited from QmitkSegWithPreviewToolGUIBase
void OnNewToolAssociated (mitk::Tool *)
 
void OnAcceptPreview ()
 
void OnPreviewOpacityChanged (int value)
 
void OnPreviewVisibilityToggled (bool checked)
 
- Protected Attributes inherited from QmitkSegWithPreviewToolGUIBase
EnableConfirmSegBtnFunctionType m_EnableConfirmSegBtnFnc
 
- Protected Attributes inherited from QmitkToolGUI
mitk::Tool::Pointer m_Tool
 
QmitkMultiLabelInspector * m_MultiLabelInspector
 

Detailed Description

GUI widget for the nnInteractiveTool segmentation tool.

This class provides the user interface for the nnInteractive segmentation tool. It extends QmitkSegWithPreviewToolGUIBase and manages:

  • Session initialization and settings (initialize button, settings)
  • Prompt type selection (positive / negative)
  • Interactor mode buttons (point, box, scribble, lasso)
  • Auto-zoom and auto-refine options
  • Mask-based session initialization
  • Automation modes (auto-confirm after a single interaction; auto-create-next-label on confirm, with an optional bypass of the global label-naming preferences)
  • Optional shortcut hints in button labels
  • Keyboard shortcuts for common actions (R: reset, U: undo, C: confirm, T: toggle prompt type, P/B/S/L: toggle interactors, V: toggle preview visibility)
See also
mitk::nnInteractiveTool, QmitkSegWithPreviewToolGUIBase, QmitkPipInstallDialog

Definition at line 65 of file QmitknnInteractiveToolGUI.h.

Member Typedef Documentation

◆ InteractionType

◆ PromptType

Constructor & Destructor Documentation

◆ QmitknnInteractiveToolGUI()

QmitknnInteractiveToolGUI::QmitknnInteractiveToolGUI ( )
protected

Constructs the GUI with confirm segmentation button disabled by default.

◆ ~QmitknnInteractiveToolGUI()

QmitknnInteractiveToolGUI::~QmitknnInteractiveToolGUI ( )
overrideprotected

Destructor. Restores any override cursors and disconnects events.

Member Function Documentation

◆ EnableInitializeButtons()

void QmitknnInteractiveToolGUI::EnableInitializeButtons ( bool  enabled)
protected

Enables or disables the initialize and settings buttons.

Parameters
[in]enabledWhether the buttons should be enabled.

◆ GetTool()

mitk::nnInteractiveTool* QmitknnInteractiveToolGUI::GetTool ( )
protected

Returns the connected nnInteractiveTool.

Returns
Pointer to the connected nnInteractiveTool.

◆ InitializeInteractorButtons()

void QmitknnInteractiveToolGUI::InitializeInteractorButtons ( )
protected

Initializes the interactor toggle buttons with icons and shortcuts.

◆ InitializePromptType()

void QmitknnInteractiveToolGUI::InitializePromptType ( )
protected

Initializes the prompt type button group and shortcut.

◆ InitializeUI()

void QmitknnInteractiveToolGUI::InitializeUI ( QBoxLayout *  mainLayout)
overrideprotectedvirtual

Initializes the UI widgets and connects signals.

Sets up the form from the .ui file, initializes icons, prompt type buttons, interactor buttons, checkboxes, keyboard shortcuts, and connects all signal/slot connections.

Parameters
[in]mainLayoutThe parent layout to add the GUI widgets to.

Reimplemented from QmitkSegWithPreviewToolGUIBase.

◆ Install()

bool QmitknnInteractiveToolGUI::Install ( )
protected

Checks if nnInteractive is installed and shows the install dialog if not.

Creates the virtual environment and installs all required packages.

Returns
true if nnInteractive is installed (or was successfully installed), false otherwise.

◆ mitkClassMacro()

QmitknnInteractiveToolGUI::mitkClassMacro ( QmitknnInteractiveToolGUI  ,
QmitkSegWithPreviewToolGUIBase   
)

◆ New()

static Pointer QmitknnInteractiveToolGUI::New ( )
static

◆ OnActiveLabelChanged()

void QmitknnInteractiveToolGUI::OnActiveLabelChanged ( const mitk::MultiLabelSegmentation::LabelValueVectorType &  labels)
protected

Reacts to a change of the selected label in the host's label inspector while a session is running.

Acts only on a single-label selection and delegates to MaybeInitializeWithLabelMask(), which seeds the session from the selected label if it has content.

Parameters
[in]labelsThe now-selected label values.

◆ OnAutoRefineCheckBoxToggled()

void QmitknnInteractiveToolGUI::OnAutoRefineCheckBoxToggled ( bool  checked)
protected

Handles auto-refine checkbox toggle.

Parameters
[in]checkedWhether auto-refine should be enabled.

◆ OnAutoZoomCheckBoxToggled()

void QmitknnInteractiveToolGUI::OnAutoZoomCheckBoxToggled ( bool  checked)
protected

Handles auto-zoom checkbox toggle.

Parameters
[in]checkedWhether auto-zoom should be enabled.

◆ OnConfirmCleanUp()

void QmitknnInteractiveToolGUI::OnConfirmCleanUp ( bool  isConfirmed)
protected

Handles cleanup confirmation from the tool.

Parameters
[in]isConfirmedWhether the cleanup was confirmed.

◆ OnHeartbeatTimeout()

void QmitknnInteractiveToolGUI::OnHeartbeatTimeout ( )
protected

Sends a keep-alive heartbeat to the remote nnInteractive server.

Connected to the heartbeat timer's timeout while a remote session runs. Delegates to nnInteractiveTool::Heartbeat(), which keeps the server-side lease alive and, on a definitive expiry, triggers the SessionExpiredEvent teardown path. Has no effect for local sessions.

◆ OnInitializeButtonToggled()

void QmitknnInteractiveToolGUI::OnInitializeButtonToggled ( bool  checked)
protected

Handles the initialize button toggle event.

When checked, creates the virtual environment, Python context, and installs nnInteractive if needed, then starts the inference session.

When unchecked, ends the current inference session.

Parameters
[in]checkedWhether the button is checked.

◆ OnInteractorToggled()

void QmitknnInteractiveToolGUI::OnInteractorToggled ( mitk::nnInteractive::InteractionType  interactionType,
bool  checked 
)
protected

Handles toggling of an interactor button.

When checked, enables the corresponding interactor and sets an appropriate cursor. When unchecked, disables the interactor and restores the default cursor.

Parameters
[in]interactionTypeThe interaction type being toggled.
[in]checkedWhether the interactor should be enabled.

◆ OnPreviewUpdated()

void QmitknnInteractiveToolGUI::OnPreviewUpdated ( )
protected

Handles the tool's PreviewUpdatedEvent.

When "auto-confirm" is enabled, schedules an auto-click of the Confirm button on the next event-loop tick. No-op otherwise.

◆ OnPromptTypeChanged()

void QmitknnInteractiveToolGUI::OnPromptTypeChanged ( )
protected

Handles prompt type changes between positive and negative.

Re-enables the currently active interactor with the new prompt type and updates the cursor accordingly.

◆ OnResetInteractionsButtonClicked()

void QmitknnInteractiveToolGUI::OnResetInteractionsButtonClicked ( )
protected

Resets all interactions and switches to positive prompt type.

Also clears the auto-created-label tracking via InvalidateAutoCreatedLabel() so the next deactivation does not try to remove a label the user has effectively re-claimed by resetting.

◆ OnSessionEnded()

void QmitknnInteractiveToolGUI::OnSessionEnded ( )
protected

Handles the tool's SessionEndedEvent.

Reverts the session-dependent UI controls (interactor toggles, prompt type, reset, settings) back to their pre-init state and re-enables the Initialize button. Fires when the user changes the time step during a 4D session, and also as part of a normal tool deactivation (where the extra UI revert is harmless because the GUI is being torn down).

◆ OnSessionExpired()

void QmitknnInteractiveToolGUI::OnSessionExpired ( )
protected

Handles the tool's SessionExpiredEvent.

A remote session was lost server-side (idle timeout, server restart, or the server is at capacity / unreachable). The session is still live when this fires: it stops the heartbeat timer and defers teardown to the next event-loop tick (AbortSession(), which ends the session and clears the interactions and preview), then informs the user that they need to re-initialize. Deferring both the teardown and the dialog avoids re-entrancy when the event fires from within an interaction. A guard ensures a second expiry event cannot stack a duplicate teardown or dialog.

◆ OnSettingsButtonClicked()

void QmitknnInteractiveToolGUI::OnSettingsButtonClicked ( )
protected

Opens the nnInteractive preferences dialog.

◆ OnToolDeactivated()

void QmitknnInteractiveToolGUI::OnToolDeactivated ( )
protected

Handles the tool's DeactivatedEvent.

Runs on a proper user-initiated tool deactivation (as opposed to the GUI's Qt destructor, which may fire during application shutdown when observers and widgets are partially destroyed). Performs the unused- auto-label cleanup here so we never touch the segmentation from the destructor path.

◆ OnUndoButtonClicked()

void QmitknnInteractiveToolGUI::OnUndoButtonClicked ( )
protected

Undoes the last interaction and refreshes the Undo button state.

Delegates to nnInteractiveTool::UndoLastInteraction(), which reverts the most recent interaction (single-level) and removes its prompt visualization.

◆ UncheckOtherInteractorButtons()

void QmitknnInteractiveToolGUI::UncheckOtherInteractorButtons ( QPushButton *  interactorButton)
protected

Unchecks all interactor buttons except the specified one.

Parameters
[in]interactorButtonThe button to keep checked, or nullptr to uncheck all.

◆ UpdateModelLicenseDisplay()

void QmitknnInteractiveToolGUI::UpdateModelLicenseDisplay ( const std::optional< std::string > &  license)
protected

Shows the model checkpoint license below the Initialize button, or clears it when passed std::nullopt.

Mirrors the napari plugin: a normal license string is shown as "Model license: <value>", the "!!MISSING!!" sentinel is shown as a red "Model license: UNKNOWN (warning!)", and an empty/absent license hides the label. Driven by the session lifecycle, so it works for local and remote sessions alike.


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