Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::nnInteractive Namespace Reference

Classes

class  BoxInteractor
 nnInteractive interactor for drawing rectangular boxes. More...
 
class  Interactor
 Base class for all nnInteractive interactors. More...
 
class  LassoInteractor
 nnInteractive interactor for drawing contours. More...
 
class  PointInteractor
 nnInteractive interactor for placing individual points. More...
 
class  ScribbleInteractor
 nnInteractive interactor for freehand brushstrokes. More...
 
struct  VersionCheckResult
 Result of CheckInstalledVersion(): the verdict plus the version strings it was derived from (empty when not determined). More...
 
struct  ModelInfo
 A model checkpoint entry as reported by nnInteractive's model management. More...
 
struct  ModelCheckResult
 Result of CheckModelUpdate(). More...
 

Typedefs

using InteractionBoundingBox = std::array< std::array< int, 2 >, 3 >
 

Enumerations

enum class  InteractionType { Point , Box , Scribble , Lasso }
 Specifies the types of interactions available. More...
 
enum class  PromptType { Positive , Negative }
 Specifies the types of prompts used in nnInteractive. More...
 
enum class  Backend { CUDA , CPU }
 Specifies the computation backends available for nnInteractive. More...
 
enum class  ColorIntensity { Muted , Vibrant }
 Specifies the intensity of the colors used in an interaction. More...
 
enum class  VersionStatus { Unknown , BelowMinimum , UpdateAvailable , UpToDate }
 Outcome of comparing the installed nnInteractive package against the version range this MITK build supports. More...
 
enum class  ModelUpdateStatus { Unknown , UpToDate , UpdateAvailable }
 Outcome of comparing the selected checkpoint against the library's recommended default. More...
 
enum class  ModelListStatus { Ok , Empty , Failed }
 Outcome of a ListModels() query, distinguishing an empty manifest from a hard failure. More...
 
enum class  UpdatePromptChoice { Update , ContinueInstalled , Cancel }
 The user's response to the version-update prompt. More...
 

Functions

MITKPYTHONSEGMENTATION_EXPORT const std::string & GetInteractionTypeAsString (InteractionType interactionType)
 Converts an InteractionType to a corresponding string representation. More...
 
MITKPYTHONSEGMENTATION_EXPORT const std::array< InteractionType, 4 > & GetAllInteractionTypes ()
 Returns all possible interaction types. More...
 
MITKPYTHONSEGMENTATION_EXPORT const std::string & GetPromptTypeAsString (PromptType promptType)
 Converts a PromptType to a corresponding string representation. More...
 
MITKPYTHONSEGMENTATION_EXPORT const std::array< PromptType, 2 > & GetAllPromptTypes ()
 Returns all possible prompt types. More...
 
MITKPYTHONSEGMENTATION_EXPORT const std::string & GetBackendAsString (Backend backend)
 Converts a Backend type to a corresponding string representation. More...
 
MITKPYTHONSEGMENTATION_EXPORT const std::array< Backend, 2 > & GetAllBackends ()
 Returns all possible backend types. More...
 
MITKPYTHONSEGMENTATION_EXPORT const Color & GetColor (PromptType promptType, ColorIntensity colorIntensity)
 Returns the color associated with a specific prompt type and color intensity. More...
 
MITKPYTHONSEGMENTATION_EXPORT VersionCheckResult CheckInstalledVersion (PythonContext &context, bool checkForUpdate=true, const std::string &distributionName="nnInteractive")
 Compares the installed nnInteractive package against the supported version range, using the given Python context. More...
 
MITKPYTHONSEGMENTATION_EXPORT VersionCheckResult CheckInstalledVersion (bool checkForUpdate=true, const std::string &distributionName="nnInteractive")
 Convenience overload for callers without a Python context. More...
 
bool ComputeStrokeBoundingBox (const Image *paintingSlice2D, const Image *referenceImage, InteractionBoundingBox &outBoundingBox)
 
Image::Pointer BuildBoundingBoxMaskImage (const Image *paintingSlice2D, const PlaneGeometry *slicingPlane, const Image *referenceImage, const InteractionBoundingBox &boundingBox)
 
void HideNodeIn3DRenderWindows (DataNode *node)
 
MITKPYTHONSEGMENTATIONUI_EXPORT PipInstallSpec BuildInstallSpec (IPreferences *prefs, const std::string &venvName, bool clientOnly)
 Builds the pip install spec for a fresh nnInteractive install. More...
 
MITKPYTHONSEGMENTATIONUI_EXPORT PipInstallSpec BuildUpgradeSpec (const std::string &venvName, bool clientOnly)
 Builds the pip spec for an in-place update of an existing install. More...
 
MITKPYTHONSEGMENTATIONUI_EXPORT std::vector< ModelInfo > ListModels (const std::string &venvName, ModelListStatus *status=nullptr, QWidget *parent=nullptr)
 Lists the model checkpoints known to nnInteractive's model management. More...
 
MITKPYTHONSEGMENTATIONUI_EXPORT ModelCheckResult CheckModelUpdate (const std::string &venvName, const std::string &selectedModelId, QWidget *parent=nullptr)
 Checks whether a checkpoint newer than the selected one is recommended. More...
 
MITKPYTHONSEGMENTATIONUI_EXPORT UpdatePromptChoice ShowUpdatePrompt (QWidget *parent, const VersionCheckResult &result, bool modulesLoaded, bool inInitFlow)
 Shows the standard nnInteractive version-status dialog and returns the user's choice. More...
 

Variables

constexpr const char * MINIMUM_VERSION
 Minimum nnInteractive version this MITK build supports. More...
 
constexpr const char * MAXIMUM_VERSION_EXCLUSIVE
 Exclusive upper bound on the supported nnInteractive version (the next major release is assumed to break compatibility). More...
 

Typedef Documentation

◆ InteractionBoundingBox

using mitk::nnInteractive::InteractionBoundingBox = typedef std::array<std::array<int, 2>, 3>

Definition at line 26 of file mitknnInteractiveBoundingBox.h.

Enumeration Type Documentation

◆ Backend

Specifies the computation backends available for nnInteractive.

Backends define the computational resources used, such as GPU (CUDA) or CPU for processing.

Note
Whenever modifying this enum class, make sure to also adapt its utility functions GetBackendAsString() and GetAllBackends().
See also
GetBackendAsString(), GetAllBackends()
Enumerator
CUDA 

CUDA backend for GPU computation (fast)

CPU 

Backend for CPU computation (slow)

Definition at line 105 of file mitknnInteractiveEnums.h.

◆ ColorIntensity

Specifies the intensity of the colors used in an interaction.

See also
GetColor()
Enumerator
Muted 

Muted color intensity

Vibrant 

Vibrant color intensity

Definition at line 132 of file mitknnInteractiveEnums.h.

◆ InteractionType

Specifies the types of interactions available.

Interaction types represent the different modes of interaction for prompting available in nnInteractive, each corresponding to a specific user action.

Note
Whenever modifying this enum class, make sure to also adapt its utility functions GetInteractionTypeAsString() and GetAllInteractionTypes().
See also
Interactor::Interactor(), GetInteractionTypeAsString(), GetAllInteractionTypes()
Enumerator
Point 

Interaction for placing individual points

Box 

Interaction for drawing rectangular boxes

Scribble 

Interaction for freehand brushstrokes

Lasso 

Interaction for drawing contours

Definition at line 34 of file mitknnInteractiveEnums.h.

◆ ModelListStatus

Outcome of a ListModels() query, distinguishing an empty manifest from a hard failure.

Enumerator
Ok 

The query ran and returned at least one model.

Empty 

The query ran but the manifest contains no models.

Failed 

The query could not run (no environment, offline, no model management).

Definition at line 63 of file mitknnInteractiveModel.h.

◆ ModelUpdateStatus

Outcome of comparing the selected checkpoint against the library's recommended default.

See also
CheckModelUpdate()
Enumerator
Unknown 

Could not determine (offline, no model management, or empty list).

UpToDate 

The selection already matches the recommended default.

UpdateAvailable 

A different checkpoint is now recommended as the default.

Definition at line 45 of file mitknnInteractiveModel.h.

◆ PromptType

Specifies the types of prompts used in nnInteractive.

Prompt types distinguish between positive and negative prompts, e.g., should the labeled region by an interaction be included in or excluded from the resulting segmentation.

Note
Whenever modifying this enum class, make sure to also adapt its utility functions GetPromptTypeAsString() and GetAllPromptTypes().
See also
GetPromptTypeAsString(), GetAllPromptTypes()
Enumerator
Positive 

Include region in segmentation

Negative 

Exclude region from segmentation

Definition at line 71 of file mitknnInteractiveEnums.h.

◆ UpdatePromptChoice

The user's response to the version-update prompt.

Enumerator
Update 

Run the in-place update now.

ContinueInstalled 

Keep using the installed version.

Cancel 

Do nothing / abort the surrounding flow.

Definition at line 27 of file mitknnInteractiveUpdatePrompt.h.

◆ VersionStatus

Outcome of comparing the installed nnInteractive package against the version range this MITK build supports.

See also
CheckInstalledVersion()
Enumerator
Unknown 

The installed or latest version could not be determined.

BelowMinimum 

Installed version is older than MINIMUM_VERSION (incompatible).

UpdateAvailable 

A newer in-range release exists on PyPI than the one installed.

UpToDate 

Installed version is supported and no newer in-range release is known.

Definition at line 31 of file mitknnInteractiveVersion.h.

Function Documentation

◆ BuildBoundingBoxMaskImage()

Image::Pointer mitk::nnInteractive::BuildBoundingBoxMaskImage ( const Image *  paintingSlice2D,
const PlaneGeometry *  slicingPlane,
const Image *  referenceImage,
const InteractionBoundingBox &  boundingBox 
)

◆ BuildInstallSpec()

MITKPYTHONSEGMENTATIONUI_EXPORT PipInstallSpec mitk::nnInteractive::BuildInstallSpec ( IPreferences *  prefs,
const std::string &  venvName,
bool  clientOnly 
)

Builds the pip install spec for a fresh nnInteractive install.

Full mode installs PyTorch and nnInteractive and queues a post-install step that pre-downloads the model checkpoint (unless a local checkpoint folder is configured); client-only mode installs just the lightweight, torch-free nninteractive-client. On Windows the torch group uses the CUDA wheel index.

Parameters
[in]prefsPreferences used to resolve the model source and checkpoint for the pre-download step (may be nullptr to skip it).
[in]venvNameVirtual environment to create and install into.
[in]clientOnlyWhether to build a client-only (remote) install.

◆ BuildUpgradeSpec()

MITKPYTHONSEGMENTATIONUI_EXPORT PipInstallSpec mitk::nnInteractive::BuildUpgradeSpec ( const std::string &  venvName,
bool  clientOnly 
)

Builds the pip spec for an in-place update of an existing install.

Reuses the resolve-then-install engine with –upgrade; the venv already exists, so pip is not upgraded first. On Windows the torch group is upgraded from the CUDA wheel index so a transitive torch bump cannot pull a non-CUDA wheel from PyPI.

Parameters
[in]venvNameExisting virtual environment to upgrade in place.
[in]clientOnlyWhether this upgrades nninteractive-client (vs nnInteractive).

◆ CheckInstalledVersion() [1/2]

MITKPYTHONSEGMENTATION_EXPORT VersionCheckResult mitk::nnInteractive::CheckInstalledVersion ( bool  checkForUpdate = true,
const std::string &  distributionName = "nnInteractive" 
)

Convenience overload for callers without a Python context.

Creates and activates a transient Python context for the nnInteractive virtual environment, then forwards to the context-taking overload. If the context cannot be created (e.g. the virtual environment is missing or the interpreter fails to initialize), the result Status is Unknown.

Parameters
[in]checkForUpdateWhether to query PyPI for a newer release.
[in]distributionNameThe installed pip distribution to query ("nnInteractive" for a full install, "nninteractive-client" for a client-only install).
Returns
A VersionCheckResult (see the context-taking overload).
See also
CheckInstalledVersion(PythonContext&, bool, const std::string&)

◆ CheckInstalledVersion() [2/2]

MITKPYTHONSEGMENTATION_EXPORT VersionCheckResult mitk::nnInteractive::CheckInstalledVersion ( PythonContext &  context,
bool  checkForUpdate = true,
const std::string &  distributionName = "nnInteractive" 
)

Compares the installed nnInteractive package against the supported version range, using the given Python context.

Reads the installed version via importlib.metadata and compares it with MINIMUM_VERSION using packaging's version semantics. When checkForUpdate is true and the installed version meets the minimum, it additionally queries PyPI (best-effort, short timeout) for the newest release within the supported range to spot an available update; the query is skipped when the installed version is already below the minimum (it is going to be reinstalled anyway) and on any network failure, so the offline verdict is always fast and reliable. Pass false to do the offline minimum check only (the caller has already performed the update check this run, so the network round-trip would be wasted).

A successful update query sets VersionCheckResult::Latest to the newest in-range release (equal to the installed version when it is already the newest); a network failure leaves it empty. So an UpToDate result with a non-empty Latest means PyPI was actually reached, an empty one means it was not, which lets a caller distinguish a confirmed up-to-date verdict from an offline check.

Parameters
[in]contextAn activated Python context bound to the nnInteractive virtual environment.
[in]checkForUpdateWhether to query PyPI for a newer release.
[in]distributionNameThe installed pip distribution to query. The full install registers the distribution "nnInteractive"; a client-only install registers "nninteractive-client". The shared "nnInteractive" import namespace is the same for both, so the distribution name (not the import name) must be used here for importlib.metadata and the PyPI lookup. Only C++-controlled literals are ever passed.
Returns
A VersionCheckResult; Status is Unknown when the installed version could not be read (the caller should then not block or nag).
See also
VersionStatus

◆ CheckModelUpdate()

MITKPYTHONSEGMENTATIONUI_EXPORT ModelCheckResult mitk::nnInteractive::CheckModelUpdate ( const std::string &  venvName,
const std::string &  selectedModelId,
QWidget *  parent = nullptr 
)

Checks whether a checkpoint newer than the selected one is recommended.

Compares selectedModelId against get_default_model_id() (queried in a subprocess, see ListModels()): the result is UpdateAvailable when the default is non-empty and differs from the selection, UpToDate when they match (or when the selection is empty, i.e. already tracking the default), and Unknown on any failure (offline, no model management). It deliberately does not parse version suffixes; "newer" means "the library now recommends a different default checkpoint".

While it runs, a modal progress dialog parented to parent keeps the UI responsive and lets the user cancel (a cancel is reported as Unknown).

Parameters
[in]venvNameThe nnInteractive virtual environment to query.
[in]selectedModelIdThe model id currently configured (may be empty to mean "use the recommended default").
[in]parentWidget the modal progress dialog is parented to (may be nullptr).
Returns
A ModelCheckResult; Status is Unknown when it could not be determined (the caller should then not prompt).
See also
ModelUpdateStatus

◆ ComputeStrokeBoundingBox()

bool mitk::nnInteractive::ComputeStrokeBoundingBox ( const Image *  paintingSlice2D,
const Image *  referenceImage,
InteractionBoundingBox &  outBoundingBox 
)

◆ GetAllBackends()

MITKPYTHONSEGMENTATION_EXPORT const std::array<Backend, 2>& mitk::nnInteractive::GetAllBackends ( )

Returns all possible backend types.

Returns
A reference to a static array containing all Backend enumerators.

◆ GetAllInteractionTypes()

MITKPYTHONSEGMENTATION_EXPORT const std::array<InteractionType, 4>& mitk::nnInteractive::GetAllInteractionTypes ( )

Returns all possible interaction types.

Returns
A reference to a static array containing all InteractionType enumerators.

◆ GetAllPromptTypes()

MITKPYTHONSEGMENTATION_EXPORT const std::array<PromptType, 2>& mitk::nnInteractive::GetAllPromptTypes ( )

Returns all possible prompt types.

Returns
A reference to a static array containing all PromptType enumerators.

◆ GetBackendAsString()

MITKPYTHONSEGMENTATION_EXPORT const std::string& mitk::nnInteractive::GetBackendAsString ( Backend  backend)

Converts a Backend type to a corresponding string representation.

Parameters
[in]backendThe backend type to convert.
Returns
A reference to a static string representing the backend (e.g., "CUDA", "CPU").
Exceptions
std::out_of_rangeif the backend type is out of the valid range.

◆ GetColor()

MITKPYTHONSEGMENTATION_EXPORT const Color& mitk::nnInteractive::GetColor ( PromptType  promptType,
ColorIntensity  colorIntensity 
)

Returns the color associated with a specific prompt type and color intensity.

Use this function for color lookup to ensure a coherent color scheme across different interactors. Positive prompts use green tones, negative prompts use red tones.

Parameters
[in]promptTypeThe prompt type determining the base color hue.
[in]colorIntensityThe color intensity variant (muted or vibrant).
Returns
A reference to a static Color object.

◆ GetInteractionTypeAsString()

MITKPYTHONSEGMENTATION_EXPORT const std::string& mitk::nnInteractive::GetInteractionTypeAsString ( InteractionType  interactionType)

Converts an InteractionType to a corresponding string representation.

Parameters
[in]interactionTypeThe interaction type to convert.
Returns
A reference to a static string representing the interaction type (e.g., "Point", "Box", "Scribble", "Lasso").
Exceptions
std::out_of_rangeif the interaction type is out of the valid range.

◆ GetPromptTypeAsString()

MITKPYTHONSEGMENTATION_EXPORT const std::string& mitk::nnInteractive::GetPromptTypeAsString ( PromptType  promptType)

Converts a PromptType to a corresponding string representation.

Parameters
[in]promptTypeThe prompt type to convert.
Returns
A reference to a static string representing the prompt type (e.g., "Positive", "Negative").
Exceptions
std::out_of_rangeif the prompt type is out of the valid range.

◆ HideNodeIn3DRenderWindows()

void mitk::nnInteractive::HideNodeIn3DRenderWindows ( DataNode *  node)

◆ ListModels()

MITKPYTHONSEGMENTATIONUI_EXPORT std::vector<ModelInfo> mitk::nnInteractive::ListModels ( const std::string &  venvName,
ModelListStatus *  status = nullptr,
QWidget *  parent = nullptr 
)

Lists the model checkpoints known to nnInteractive's model management.

Runs nnInteractive.model_management.list_models() in a short-lived subprocess driven by the virtual environment's own Python interpreter, rather than the embedded interpreter. This keeps model management (and its transitive native dependencies, e.g. PyYAML) out of the host process, so it never maps libraries from the virtual environment that would block a later in-place update on Windows. The call refreshes the model manifest from Hugging Face (remote-first, with an offline cache fallback).

Returns an empty list when the virtual environment or its interpreter is missing, model management is unavailable (a client-only install), or the query fails, so callers can treat "no models" as "fall back to free-text entry". Pass status to tell a genuinely empty manifest (Empty) apart from a failure to query at all (Failed); both yield an empty list.

While it runs, a modal progress dialog parented to parent keeps the UI responsive and lets the user cancel (a cancel is reported as Failed).

Parameters
[in]venvNameThe nnInteractive virtual environment to query.
[out]statusOptional; set to Ok, Empty, or Failed (may be nullptr).
[in]parentWidget the modal progress dialog is parented to (may be nullptr).
Returns
The known model checkpoints (possibly empty).

◆ ShowUpdatePrompt()

MITKPYTHONSEGMENTATIONUI_EXPORT UpdatePromptChoice mitk::nnInteractive::ShowUpdatePrompt ( QWidget *  parent,
const VersionCheckResult &  result,
bool  modulesLoaded,
bool  inInitFlow 
)

Shows the standard nnInteractive version-status dialog and returns the user's choice.

Handles the BelowMinimum and UpdateAvailable verdicts (read from result.Status); passing any other status is a usage error. The wording and the available buttons adapt to two flags:

  • modulesLoaded: nnInteractive is already imported into this process, so an in-place update would fail on Windows (locked files). The dialog then offers no "Update now" and asks the user to restart first.
  • inInitFlow: shown during initialization, where declining still proceeds with the working installed version (offers "Continue with installed", which maps to ContinueInstalled). When false (the preferences page), declining simply closes the dialog.

The application name used in the restart hint is read from QCoreApplication.

Parameters
[in]parentDialog parent (may be nullptr).
[in]resultVersion check verdict; only BelowMinimum / UpdateAvailable.
[in]modulesLoadedWhether nnInteractive modules are loaded in-process.
[in]inInitFlowWhether the prompt is shown during initialization.
Returns
The user's choice. BelowMinimum never yields ContinueInstalled.

Variable Documentation

◆ MAXIMUM_VERSION_EXCLUSIVE

constexpr const char* mitk::nnInteractive::MAXIMUM_VERSION_EXCLUSIVE
inlineconstexpr

Exclusive upper bound on the supported nnInteractive version (the next major release is assumed to break compatibility).

Definition at line 60 of file mitknnInteractiveVersion.h.

◆ MINIMUM_VERSION

constexpr const char* mitk::nnInteractive::MINIMUM_VERSION
inlineconstexpr

Minimum nnInteractive version this MITK build supports.

Used both to build the pip requirement at install time and to detect a too-old package left behind in a reused virtual environment (see CheckInstalledVersion()). Keep in sync with the install requirement.

Definition at line 55 of file mitknnInteractiveVersion.h.