Medical Imaging Interaction Toolkit  2024.06.00
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 <QmitknnUNetGPU.h>
18 #include <QString>
20 #include <QStandardPaths>
21 #include <ui_QmitkSegmentAnythingPreferencePage.h>
22 #include <QDir>
23 
24 class QWidget;
25 
26 namespace Ui
27 {
29 }
30 
32 {
33 public:
34  const QString VENV_NAME = ".sam";
35  const QString SAM_VERSION = "1.0"; // currently, unused
36  const std::vector<QString> PACKAGES = {QString("git+https://github.com/MIC-DKFZ/agent-sam.git@v0.2")};
37  const QString STORAGE_DIR;
39  const QString baseDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() +
40  qApp->organizationName() + QDir::separator())
41  : QmitkSetupVirtualEnvUtil(baseDir), STORAGE_DIR(baseDir){};
42  bool SetupVirtualEnv(const QString &) override;
43  QString GetVirtualEnvPath() override;
44 };
45 
47 {
48  Q_OBJECT
49  Q_INTERFACES(berry::IPreferencePage)
50 
51 public:
54 
55  void Init(berry::IWorkbench::Pointer workbench) override;
56  void CreateQtControl(QWidget* parent) override;
57  QWidget* GetQtControl() const override;
58  bool PerformOk() override;
59  void PerformCancel() override;
60  void Update() override;
61 
62 private slots:
63  void OnInstallBtnClicked();
64  void OnClearInstall();
65  std::pair<QString, QString> OnSystemPythonChanged(const QString &);
66 
67 protected:
72  void AutoParsePythonPaths();
73 
80  QString GetPythonPathFromUI(const QString &) const;
81 
87  void SetGPUInfo();
88 
93  int FetchSelectedGPUFromUI() const;
94 
95  void WriteStatusMessage(const QString &);
96  void WriteErrorMessage(const QString &);
97 
98 private:
99  Ui::QmitkSegmentAnythingPreferencePage* m_Ui;
100  QmitkSAMInstaller m_Installer;
101  QWidget* m_Control;
102  QmitkGPULoader m_GpuLoader;
103  QString m_PythonPath;
104  const QString CPU_ID = "cpu";
105  const QStringList VALID_MODELS = {"vit_b", "vit_l", "vit_h"};
106 };
107 
108 #endif
QmitkSAMInstaller
Definition: QmitkSegmentAnythingPreferencePage.h:31
QmitkSAMInstaller::STORAGE_DIR
const QString STORAGE_DIR
Definition: QmitkSegmentAnythingPreferencePage.h:37
QmitkSegmentAnythingPreferencePage::Init
void Init(berry::IWorkbench::Pointer workbench) override
QmitkSegmentAnythingPreferencePage::Update
void Update() override
QmitkSetupVirtualEnvUtil
Abstract Class to Setup a python virtual environment and pip install required packages....
Definition: QmitkSetupVirtualEnvUtil.h:25
QmitkSegmentAnythingPreferencePage
Definition: QmitkSegmentAnythingPreferencePage.h:46
QmitkSAMInstaller::SAM_VERSION
const QString SAM_VERSION
Definition: QmitkSegmentAnythingPreferencePage.h:35
QmitknnUNetGPU.h
QmitkGPULoader
Class to load and save GPU information for further validation.
Definition: QmitknnUNetGPU.h:35
berry::SmartPointer
Implements transparent reference counting.
Definition: berryICommandCategoryListener.h:21
QmitkSegmentAnythingPreferencePage::PerformOk
bool PerformOk() override
QmitkSetupVirtualEnvUtil.h
QmitkSegmentAnythingPreferencePage::WriteStatusMessage
void WriteStatusMessage(const QString &)
QmitkSegmentAnythingPreferencePage::GetPythonPathFromUI
QString GetPythonPathFromUI(const QString &) const
Get the virtual env path from UI combobox removing any extra special characters.
QmitkSegmentAnythingPreferencePage::~QmitkSegmentAnythingPreferencePage
~QmitkSegmentAnythingPreferencePage() override
berry::IQtPreferencePage
Definition: berryIQtPreferencePage.h:29
Ui
Definition: BlueBerryExampleLauncherDialog.h:21
QmitkSegmentAnythingPreferencePage::GetQtControl
QWidget * GetQtControl() const override
QmitkSegmentAnythingPreferencePage::QmitkSegmentAnythingPreferencePage
QmitkSegmentAnythingPreferencePage()
QmitkSAMInstaller::SetupVirtualEnv
bool SetupVirtualEnv(const QString &) override
Implement the method in child class to setup the virtual environment.
QmitkSAMInstaller::PACKAGES
const std::vector< QString > PACKAGES
Definition: QmitkSegmentAnythingPreferencePage.h:36
berryIQtPreferencePage.h
QmitkSegmentAnythingPreferencePage::SetGPUInfo
void SetGPUInfo()
Adds GPU information to the gpu combo box. In case, there aren't any GPUs avaialble,...
QmitkSAMInstaller::GetVirtualEnvPath
QString GetVirtualEnvPath() override
Get the Virtual Env Path object. Override this method in the respective tool installer class.
QmitkSAMInstaller::QmitkSAMInstaller
QmitkSAMInstaller(const QString baseDir=QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+QDir::separator()+qApp->organizationName()+QDir::separator())
Definition: QmitkSegmentAnythingPreferencePage.h:38
QmitkSegmentAnythingPreferencePage::FetchSelectedGPUFromUI
int FetchSelectedGPUFromUI() const
Returns GPU id of the selected GPU from the Combo box.
QmitkSegmentAnythingPreferencePage::PerformCancel
void PerformCancel() override
berry::IPreferencePage
Definition: berryIPreferencePage.h:42
QmitkSegmentAnythingPreferencePage::CreateQtControl
void CreateQtControl(QWidget *parent) override
QmitkSegmentAnythingPreferencePage::WriteErrorMessage
void WriteErrorMessage(const QString &)
QmitkSAMInstaller::VENV_NAME
const QString VENV_NAME
Definition: QmitkSegmentAnythingPreferencePage.h:34
QmitkSegmentAnythingPreferencePage::AutoParsePythonPaths
void AutoParsePythonPaths()
Searches and parses paths of python virtual enviroments from predefined lookout locations.