Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
QmitkTotalSegmentatorToolGUI.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 QmitkTotalSegmentatorToolGUI_h_Included
14 #define QmitkTotalSegmentatorToolGUI_h_Included
15 
18 #include "QmitknnUNetGPU.h"
19 #include "ui_QmitkTotalSegmentatorGUIControls.h"
21 #include <QMessageBox>
22 #include <QSettings>
23 #include <QStandardPaths>
24 #include <QDir>
25 
33 {
34 public:
35  const QString VENV_NAME = ".totalsegmentator_v2";
36  const QString TOTALSEGMENTATOR_VERSION = "2.0.5";
37  const std::vector<QString> PACKAGES = {QString("Totalsegmentator==") + TOTALSEGMENTATOR_VERSION};
38  const QString STORAGE_DIR;
40  const QString baseDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator()
41  + qApp->organizationName() + QDir::separator())
42  : QmitkSetupVirtualEnvUtil(baseDir), STORAGE_DIR(baseDir){};
43  bool SetupVirtualEnv(const QString &) override;
44  QString GetVirtualEnvPath() override;
45 };
46 
53 {
54  Q_OBJECT
55 
56 public:
58  itkFactorylessNewMacro(Self);
59  itkCloneMacro(Self);
60 
61 protected slots:
62 
66  void OnPreviewBtnClicked();
67 
71  void OnPythonPathChanged(const QString &);
72 
76  std::pair<QString, QString> OnSystemPythonChanged(const QString &);
77 
81  void OnInstallBtnClicked();
82 
86  void OnOverrideChecked(int);
87 
91  void OnClearInstall();
92 
93 protected:
95  ~QmitkTotalSegmentatorToolGUI() = default;
96 
97  void ConnectNewTool(mitk::SegWithPreviewTool *newTool) override;
98  void InitializeUI(QBoxLayout *mainLayout) override;
99 
103  void EnableAll(bool);
104 
109  void AutoParsePythonPaths();
110 
116  bool IsTotalSegmentatorInstalled(const QString &);
117 
121  void ShowErrorMessage(const std::string &, QMessageBox::Icon = QMessageBox::Critical);
122 
126  void WriteStatusMessage(const QString &);
127 
131  void WriteErrorMessage(const QString &);
132 
138  void SetGPUInfo();
139 
145  unsigned int FetchSelectedGPUFromUI() const;
146 
153  QString GetPythonPathFromUI(const QString &) const;
154 
158  QSettings m_Settings;
159 
160  QString m_PythonPath;
162  Ui_QmitkTotalSegmentatorToolGUIControls m_Controls;
163  bool m_FirstPreviewComputation = true;
164  bool m_IsInstalled = false;
166 
167  const std::string WARNING_TOTALSEG_NOT_FOUND =
168  "TotalSegmentator is not detected in the selected python environment.Please select a valid "
169  "python environment or install TotalSegmentator.";
170  const QStringList VALID_TASKS = {
171  "total",
172  "cerebral_bleed",
173  "hip_implant",
174  "coronary_arteries",
175  "body",
176  "lung_vessels",
177  "pleural_pericard_effusion"
178  };
180 };
181 #endif
mitk::SegWithPreviewTool
Base class for any auto segmentation tool that provides a preview of the new segmentation.
Definition: mitkSegWithPreviewTool.h:38
QmitkTotalSegmentatorToolGUI::m_GpuLoader
QmitkGPULoader m_GpuLoader
Definition: QmitkTotalSegmentatorToolGUI.h:161
QmitkTotalSegmentatorToolInstaller
Installer class for TotalSegmentator Tool. Class specifies the virtual environment name,...
Definition: QmitkTotalSegmentatorToolGUI.h:32
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelSegWithPreviewToolGUIBase.h
QmitkTotalSegmentatorToolGUI::m_Controls
Ui_QmitkTotalSegmentatorToolGUIControls m_Controls
Definition: QmitkTotalSegmentatorToolGUI.h:162
QmitkSetupVirtualEnvUtil
Abstract Class to Setup a python virtual environment and pip install required packages....
Definition: QmitkSetupVirtualEnvUtil.h:25
QmitknnUNetGPU.h
QmitkGPULoader
Class to load and save GPU information for further validation.
Definition: QmitknnUNetGPU.h:35
QmitkMultiLabelSegWithPreviewToolGUIBase::InitializeUI
void InitializeUI(QBoxLayout *mainLayout) override
QmitkTotalSegmentatorToolGUI::m_PythonPath
QString m_PythonPath
Definition: QmitkTotalSegmentatorToolGUI.h:160
QmitkTotalSegmentatorToolGUI::m_SuperclassEnableConfirmSegBtnFnc
EnableConfirmSegBtnFunctionType m_SuperclassEnableConfirmSegBtnFnc
Definition: QmitkTotalSegmentatorToolGUI.h:165
QmitkSetupVirtualEnvUtil.h
QmitkTotalSegmentatorToolInstaller::SetupVirtualEnv
bool SetupVirtualEnv(const QString &) override
Implement the method in child class to setup the virtual environment.
QmitkTotalSegmentatorToolGUI::m_Installer
QmitkTotalSegmentatorToolInstaller m_Installer
Definition: QmitkTotalSegmentatorToolGUI.h:179
QmitkTotalSegmentatorToolInstaller::TOTALSEGMENTATOR_VERSION
const QString TOTALSEGMENTATOR_VERSION
Definition: QmitkTotalSegmentatorToolGUI.h:36
QmitkMultiLabelSegWithPreviewToolGUIBase::mitkClassMacro
mitkClassMacro(QmitkMultiLabelSegWithPreviewToolGUIBase, QmitkSegWithPreviewToolGUIBase)
QmitkTotalSegmentatorToolInstaller::PACKAGES
const std::vector< QString > PACKAGES
Definition: QmitkTotalSegmentatorToolGUI.h:37
QmitkTotalSegmentatorToolGUI::m_Settings
QSettings m_Settings
For storing values like Python path across sessions.
Definition: QmitkTotalSegmentatorToolGUI.h:158
QmitkTotalSegmentatorToolInstaller::STORAGE_DIR
const QString STORAGE_DIR
Definition: QmitkTotalSegmentatorToolGUI.h:38
QmitkTotalSegmentatorToolInstaller::GetVirtualEnvPath
QString GetVirtualEnvPath() override
Get the Virtual Env Path object. Override this method in the respective tool installer class.
QmitkTotalSegmentatorToolInstaller::QmitkTotalSegmentatorToolInstaller
QmitkTotalSegmentatorToolInstaller(const QString baseDir=QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+QDir::separator()+qApp->organizationName()+QDir::separator())
Definition: QmitkTotalSegmentatorToolGUI.h:39
MitkSegmentationUIExports.h
QmitkTotalSegmentatorToolInstaller::VENV_NAME
const QString VENV_NAME
Definition: QmitkTotalSegmentatorToolGUI.h:35
QmitkTotalSegmentatorToolGUI
GUI for mitk::TotalSegmentatorTool.
Definition: QmitkTotalSegmentatorToolGUI.h:52
QmitkMultiLabelSegWithPreviewToolGUIBase
GUI for tools based on mitk::AutoMLSegmentationWithPreviewTool.
Definition: QmitkMultiLabelSegWithPreviewToolGUIBase.h:28
QmitkSegWithPreviewToolGUIBase::EnableConfirmSegBtnFunctionType
std::function< bool(bool)> EnableConfirmSegBtnFunctionType
Definition: QmitkSegWithPreviewToolGUIBase.h:63
QmitkSegWithPreviewToolGUIBase::ConnectNewTool
virtual void ConnectNewTool(mitk::SegWithPreviewTool *newTool)