Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitknnInteractiveTool.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitknnInteractiveTool_h
14 #define mitknnInteractiveTool_h
15 
16 #include <mitkSegWithPreviewTool.h>
17 #include <mitknnInteractiveEnums.h>
18 
19 #include <optional>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 namespace mitk::nnInteractive
25 {
26  class Interactor;
27 }
28 
29 namespace mitk
30 {
31  class PythonContext;
32 
57  {
58  public:
62  {
63  std::string Name;
64  int Major;
65  int Minor;
67  };
68 
81  {
82  bool Point = true;
83  bool Box = true;
84  bool Scribble = true;
85  bool Lasso = true;
86  bool Mask = true;
87  };
88 
90  itkFactorylessNewMacro(Self)
91 
92 
96  const char* GetName() const override;
97 
104  us::ModuleResource GetIconResource() const override;
105 
115  void Deactivated() override;
116 
119  using InteractorMap = std::unordered_map<nnInteractive::InteractionType, std::unique_ptr<nnInteractive::Interactor>>;
120 
126  const InteractorMap& GetInteractors() const;
127 
136  const nnInteractive::Interactor* GetInteractor(nnInteractive::InteractionType interactionType) const;
137 
149  void EnableInteractor(nnInteractive::InteractionType nextInteractionType, nnInteractive::PromptType promptType);
150 
161  void DisableInteractor(std::optional<nnInteractive::InteractionType> interactionType = std::nullopt);
162 
169  void ResetInteractions();
170 
179  bool HasInteractions() const;
180 
195  void UndoLastInteraction();
196 
207  bool CanUndo() const;
208 
218  bool SupportsUndo() const;
219 
229  bool GetAutoZoom() const;
230 
243  void SetAutoZoom(bool autoZoom);
244 
254  bool GetAutoRefine() const;
255 
263  void SetAutoRefine(bool autoRefine);
264 
273  std::optional<nnInteractive::Backend> GetBackend() const;
274 
282  std::string GetVirtualEnvName() const;
283 
293  bool CreatePythonContext();
294 
302  PythonContext* GetPythonContext() const;
303 
313  bool IsInstalled() const;
314 
331  bool IsLocalInferenceAvailable() const;
332 
347  static const std::vector<std::pair<std::string, std::string>>& GetSessionDefiningPreferences();
348 
362  bool GetCUDADeviceInfo(CUDADeviceInfo& info) const;
363 
381  void StartSession();
382 
392  void EndSession();
393 
408  void AbortSession();
409 
415  bool IsSessionRunning() const;
416 
425  bool IsRemoteSession() const;
426 
446  void Heartbeat();
447 
460  int GetHeartbeatIntervalMs() const;
461 
471  SupportedInteractions GetSupportedInteractions() const;
472 
485  std::optional<std::string> GetModelLicense() const;
486 
499  void InitializeSessionWithMask(Image* mask);
500 
507  Message1<bool> ConfirmCleanUpEvent;
508 
517  Message<> PreviewUpdatedEvent;
518 
527  Message<> DeactivatedEvent;
528 
538  Message<> SessionEndedEvent;
539 
552  Message<> SessionExpiredEvent;
553 
554  protected:
558 
561  ~nnInteractiveTool() override;
562 
568  void SetToolManager(ToolManager* toolManager) override;
569 
582  void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, MultiLabelSegmentation* previewImage, TimeStepType timeStep) override;
583 
596  void OnTimePointChanged() override;
597 
603  void Notify(InteractionEvent* event, bool isHandled) override;
604 
609  void ConfirmCleanUp() override;
610 
620  void SetPreviewLabel(MultiLabelSegmentation::LabelValueType value, const Color& color);
621 
622  private:
629  void ConstructLocalSession();
630 
640  void ConstructRemoteSession();
641 
651  void BindSessionImageAndTargetBuffer();
652 
663  bool IsRemoteConnectionError(const std::string& message) const;
664 
676  bool HandleSessionError(const std::string& errorMessage);
677 
678  class Impl;
679  std::unique_ptr<Impl> m_Impl;
680  };
681 }
682 
683 #endif
#define MITKPYTHONSEGMENTATION_EXPORT
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
Base class for all interaction events in MITK.
Event/message class with one parameter.
Definition: mitkMessage.h:552
Event/message/notification class.
Definition: mitkMessage.h:521
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
MITK point type extending itk::Point with additional constructors and utility methods.
Definition: mitkPoint.h:49
Provides a Python interpreter context for executing Python code and interacting with MITK data like i...
Base class for any auto segmentation tool that provides a preview of the new segmentation.
Manages and coordinates instances of mitk::Tool.
Segmentation tool integrating the nnInteractive deep learning model.
mitkClassMacro(nnInteractiveTool, SegWithPreviewTool) static Pointer New()
std::unordered_map< nnInteractive::InteractionType, std::unique_ptr< nnInteractive::Interactor > > InteractorMap
Map type associating InteractionType keys to Interactor instances.
InteractionType
Specifies the types of interactions available.
PromptType
Specifies the types of prompts used in nnInteractive.
Backend
Specifies the computation backends available for nnInteractive.
Find image slices visible on a given plane.
itk::RGBPixel< float > Color
Standard RGB color typedef using float components.
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
Information about a CUDA-capable GPU device.
int Major
CUDA compute capability major version.
int TotalMemoryMB
Total device memory in megabytes.
int Minor
CUDA compute capability minor version.
std::string Name
Device name (e.g., "NVIDIA GeForce RTX 3080").
Which interaction types the running session's model checkpoint supports.