Medical Imaging Interaction Toolkit  2024.06.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.2.1";
37  const std::vector<QString> PACKAGES = {QString("Totalsegmentator==") + TOTALSEGMENTATOR_VERSION,
38  QString("setuptools")}; /* just in case */
39  const QString STORAGE_DIR;
41  const QString baseDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator()
42  + qApp->organizationName() + QDir::separator())
43  : QmitkSetupVirtualEnvUtil(baseDir), STORAGE_DIR(baseDir){};
44  bool SetupVirtualEnv(const QString &) override;
45  QString GetVirtualEnvPath() override;
46 };
47 
54 {
55  Q_OBJECT
56 
57 public:
59  itkFactorylessNewMacro(Self);
60  itkCloneMacro(Self);
61 
62 protected slots:
63 
67  void OnPreviewBtnClicked();
68 
72  void OnPythonPathChanged(const QString &);
73 
77  std::pair<QString, QString> OnSystemPythonChanged(const QString &);
78 
82  void OnInstallBtnClicked();
83 
87  void OnOverrideChecked(int);
88 
92  void OnClearInstall();
93 
94 protected:
96  ~QmitkTotalSegmentatorToolGUI() = default;
97 
98  void ConnectNewTool(mitk::SegWithPreviewTool *newTool) override;
99  void InitializeUI(QBoxLayout *mainLayout) override;
100 
104  void EnableAll(bool);
105 
110  void AutoParsePythonPaths();
111 
117  bool IsTotalSegmentatorInstalled(const QString &);
118 
122  void ShowErrorMessage(const std::string &, QMessageBox::Icon = QMessageBox::Critical);
123 
127  void WriteStatusMessage(const QString &);
128 
132  void WriteErrorMessage(const QString &);
133 
139  void SetGPUInfo();
140 
146  unsigned int FetchSelectedGPUFromUI() const;
147 
154  QString GetPythonPathFromUI(const QString &) const;
155 
159  QSettings m_Settings;
160 
161  QString m_PythonPath;
163  Ui_QmitkTotalSegmentatorToolGUIControls m_Controls;
164  bool m_FirstPreviewComputation = true;
165  bool m_IsInstalled = false;
167 
168  const std::string WARNING_TOTALSEG_NOT_FOUND =
169  "TotalSegmentator is not detected in the selected python environment.Please select a valid "
170  "python environment or install TotalSegmentator.";
171  const QStringList VALID_TASKS = {
172  "total",
173  "total_mr",
174  "cerebral_bleed",
175  "hip_implant",
176  "coronary_arteries",
177  "body",
178  "lung_vessels",
179  "pleural_pericard_effusion"
180  };
182 };
183 #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:162
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:163
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:161
QmitkTotalSegmentatorToolGUI::m_SuperclassEnableConfirmSegBtnFnc
EnableConfirmSegBtnFunctionType m_SuperclassEnableConfirmSegBtnFnc
Definition: QmitkTotalSegmentatorToolGUI.h:166
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:181
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:159
QmitkTotalSegmentatorToolInstaller::STORAGE_DIR
const QString STORAGE_DIR
Definition: QmitkTotalSegmentatorToolGUI.h:39
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:40
MitkSegmentationUIExports.h
QmitkTotalSegmentatorToolInstaller::VENV_NAME
const QString VENV_NAME
Definition: QmitkTotalSegmentatorToolGUI.h:35
QmitkTotalSegmentatorToolGUI
GUI for mitk::TotalSegmentatorTool.
Definition: QmitkTotalSegmentatorToolGUI.h:53
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)