Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
QmitkSegmentAnythingPreferencePage.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 QmitkSegmentAnythingPreferencePage_h
14 #define QmitkSegmentAnythingPreferencePage_h
15 
16 #include <berryIQtPreferencePage.h>
17 #include <mitkCoreServices.h>
18 #include <mitkIPreferences.h>
20 #include <QmitknnUNetGPU.h>
21 #include <QString>
22 #include <QStandardPaths>
23 #include <ui_QmitkSegmentAnythingPreferencePage.h>
24 #include <QDir>
25 #include <QMessageBox>
27 
28 namespace Ui
29 {
31 }
32 
34 {
35  Q_OBJECT
36  Q_INTERFACES(berry::IPreferencePage)
37 
38 public:
41 
42  void Init(berry::IWorkbench::Pointer workbench) override;
43  void CreateQtControl(QWidget* parent) override;
44  QWidget* GetQtControl() const override;
45  bool PerformOk() override;
46  void PerformCancel() override;
47  void Update() override;
48 
49 private slots:
50  void OnInstallBtnClicked();
51  void OnClearInstall();
52  void OnSystemPythonChanged(const QString &pyEnv);
53 
54 protected:
59  bool IsSAMInstalled(const QString &pythonPath);
60 
67  QString GetPythonPathFromUI(const QString &) const;
68 
74  void SetDeviceInfo();
75 
81 
82  void WriteStatusMessage(const QString &);
83  void WriteErrorMessage(const QString &);
84 
85 private:
86 
90  void ShowErrorMessage(const QString &, QMessageBox::Icon = QMessageBox::Critical);
91 
92  Ui::QmitkSegmentAnythingPreferencePage* m_Ui;
93  QmitkSAMToolInstaller m_Installer;
94  QWidget* m_Control;
95  QmitkGPULoader m_GpuLoader;
96  QString m_PythonPath;
97  QString m_SysPythonPath;
98  const QString CPU_ID = "cpu";
99  const QStringList VALID_MODELS = {"vit_b", "vit_l", "vit_h"};
100  static const QString WARNING_PYTHON_NOT_FOUND;
101 
102  mitk::IPreferences *m_Preferences;
103 };
104 
105 #endif
Class to load and save GPU information for further validation.
QWidget * GetQtControl() const override
int FetchSelectedDeviceFromUI() const
Returns GPU id of the selected GPU from the Combo box.
void SetDeviceInfo()
Adds GPU information to the gpu combo box. In case, there aren't any GPUs available,...
void WriteStatusMessage(const QString &)
void CreateQtControl(QWidget *parent) override
void Init(berry::IWorkbench::Pointer workbench) override
bool IsSAMInstalled(const QString &pythonPath)
Checks if SegmentAnything is found inside the selected python virtual environment.
QString GetPythonPathFromUI(const QString &) const
Get the virtual env path from UI combobox removing any extra special characters.
void WriteErrorMessage(const QString &)
Implements transparent reference counting.
Interface to application preferences.