Medical Imaging Interaction Toolkit  2025.12.02
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 
21 namespace mitk::nnInteractive
22 {
23  class Interactor;
24 }
25 
26 namespace mitk
27 {
28  class PythonContext;
29 
31  {
32  public:
34  {
35  std::string Name;
36  int Major;
37  int Minor;
39  };
40 
42  itkFactorylessNewMacro(Self)
43 
44  const char* GetName() const override;
45  const char** GetXPM() const override;
46  us::ModuleResource GetIconResource() const override;
47  bool CanHandle(const BaseData* referenceData, const BaseData* workingData) const override;
48  void Deactivated() override;
49 
50  using InteractorMap = std::unordered_map<nnInteractive::InteractionType, std::unique_ptr<nnInteractive::Interactor>>;
51  const InteractorMap& GetInteractors() const;
52  const nnInteractive::Interactor* GetInteractor(nnInteractive::InteractionType interactionType) const;
53 
54  void EnableInteractor(nnInteractive::InteractionType nextInteractionType, nnInteractive::PromptType promptType);
55  void DisableInteractor(std::optional<nnInteractive::InteractionType> interactionType = std::nullopt);
56  void ResetInteractions();
57  bool HasInteractions() const;
58 
59  bool GetAutoZoom() const;
60  void SetAutoZoom(bool autoZoom);
61 
62  bool GetAutoRefine() const;
63  void SetAutoRefine(bool autoRefine);
64 
65  std::optional<nnInteractive::Backend> GetBackend() const;
66 
67  std::string GetVirtualEnvName() const;
68  bool CreatePythonContext();
69  PythonContext* GetPythonContext() const;
70  bool IsInstalled() const;
71  bool GetCUDADeviceInfo(CUDADeviceInfo& info) const;
72  void StartSession();
73  void EndSession();
74  bool IsSessionRunning() const;
75  void InitializeSessionWithMask(Image* mask);
76 
77  Message1<bool> ConfirmCleanUpEvent;
78 
79  protected:
81  ~nnInteractiveTool() override;
82 
83  void SetToolManager(ToolManager* toolManager) override;
84  void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, MultiLabelSegmentation* previewImage, TimeStepType timeStep) override;
85  void Notify(InteractionEvent* event, bool isHandled) override;
86  void ConfirmCleanUp() override;
87 
88  void SetPreviewLabel(MultiLabelSegmentation::LabelValueType value, const Color& color);
89 
90  private:
91  class Impl;
92  std::unique_ptr<Impl> m_Impl;
93  };
94 }
95 
96 #endif
#define MITKPYTHONSEGMENTATION_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
Image class for storing images.
Definition: mitkImage.h:70
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
Base class for any auto segmentation tool that provides a preview of the new segmentation.
Manages and coordinates instances of mitk::Tool.
mitkClassMacro(nnInteractiveTool, SegWithPreviewTool) static Pointer New()
std::unordered_map< nnInteractive::InteractionType, std::unique_ptr< nnInteractive::Interactor > > InteractorMap
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
Color Standard RGB color typedef (float)
std::size_t TimeStepType