Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
QmitkTotalSegmentatorToolGUI.h
Go to the documentation of this file.
1 #ifndef QmitkTotalSegmentatorToolGUI_h_Included
2 #define QmitkTotalSegmentatorToolGUI_h_Included
3 
6 #include "QmitknnUNetGPU.h"
7 #include "ui_QmitkTotalSegmentatorGUIControls.h"
9 #include <QMessageBox>
10 #include <QSettings>
11 #include <QStandardPaths>
12 
20 {
21 public:
22  const QString VENV_NAME = ".totalsegmentator";
23  const QString TOTALSEGMENTATOR_VERSION = "1.5.5";
24  const std::vector<QString> PACKAGES = {QString("Totalsegmentator==") + TOTALSEGMENTATOR_VERSION,
25  QString("scipy==1.9.1"),
26  QString("urllib3==1.26.15")};
27  const QString STORAGE_DIR;
29  const QString baseDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator()
30  + qApp->organizationName() + QDir::separator())
31  : QmitkSetupVirtualEnvUtil(baseDir), STORAGE_DIR(baseDir){};
32  bool SetupVirtualEnv(const QString &) override;
33  QString GetVirtualEnvPath() override;
34 };
35 
42 {
43  Q_OBJECT
44 
45 public:
47  itkFactorylessNewMacro(Self);
48  itkCloneMacro(Self);
49 
50 protected slots:
51 
55  void OnPreviewBtnClicked();
56 
60  void OnPythonPathChanged(const QString &);
61 
65  QString OnSystemPythonChanged(const QString &);
66 
70  void OnInstallBtnClicked();
71 
75  void OnOverrideChecked(int);
76 
80  void OnClearInstall();
81 
82 protected:
84  ~QmitkTotalSegmentatorToolGUI() = default;
85 
86  void ConnectNewTool(mitk::SegWithPreviewTool *newTool) override;
87  void InitializeUI(QBoxLayout *mainLayout) override;
88 
92  void EnableAll(bool);
93 
98  void AutoParsePythonPaths();
99 
105  bool IsTotalSegmentatorInstalled(const QString &);
106 
110  void ShowErrorMessage(const std::string &, QMessageBox::Icon = QMessageBox::Critical);
111 
115  void WriteStatusMessage(const QString &);
116 
120  void WriteErrorMessage(const QString &);
121 
127  void SetGPUInfo();
128 
134  unsigned int FetchSelectedGPUFromUI() const;
135 
142  QString GetPythonPathFromUI(const QString &) const;
143 
149  QString GetExactPythonPath(const QString &) const;
150 
154  QSettings m_Settings;
155 
156  QString m_PythonPath;
158  Ui_QmitkTotalSegmentatorToolGUIControls m_Controls;
159  bool m_FirstPreviewComputation = true;
160  bool m_IsInstalled = false;
162 
163  const std::string WARNING_TOTALSEG_NOT_FOUND =
164  "TotalSegmentator is not detected in the selected python environment.Please select a valid "
165  "python environment or install TotalSegmentator.";
166  const QStringList VALID_TASKS = {
167  "total",
168  "cerebral_bleed",
169  "hip_implant",
170  "coronary_arteries",
171  "body",
172  "lung_vessels",
173  "pleural_pericard_effusion"
174  };
176 };
177 #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:157
QmitkTotalSegmentatorToolInstaller
Installer class for TotalSegmentator Tool. Class specifies the virtual environment name,...
Definition: QmitkTotalSegmentatorToolGUI.h:19
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelSegWithPreviewToolGUIBase.h
QmitkTotalSegmentatorToolGUI::m_Controls
Ui_QmitkTotalSegmentatorToolGUIControls m_Controls
Definition: QmitkTotalSegmentatorToolGUI.h:158
QmitkSetupVirtualEnvUtil
Abstract Class to Setup a python virtual environment and pip install required packages....
Definition: QmitkSetupVirtualEnvUtil.h:27
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:156
QmitkTotalSegmentatorToolGUI::m_SuperclassEnableConfirmSegBtnFnc
EnableConfirmSegBtnFunctionType m_SuperclassEnableConfirmSegBtnFnc
Definition: QmitkTotalSegmentatorToolGUI.h:161
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:175
QmitkTotalSegmentatorToolInstaller::TOTALSEGMENTATOR_VERSION
const QString TOTALSEGMENTATOR_VERSION
Definition: QmitkTotalSegmentatorToolGUI.h:23
QmitkMultiLabelSegWithPreviewToolGUIBase::mitkClassMacro
mitkClassMacro(QmitkMultiLabelSegWithPreviewToolGUIBase, QmitkSegWithPreviewToolGUIBase)
QmitkTotalSegmentatorToolInstaller::PACKAGES
const std::vector< QString > PACKAGES
Definition: QmitkTotalSegmentatorToolGUI.h:24
QmitkTotalSegmentatorToolGUI::m_Settings
QSettings m_Settings
For storing values like Python path across sessions.
Definition: QmitkTotalSegmentatorToolGUI.h:154
QmitkTotalSegmentatorToolInstaller::STORAGE_DIR
const QString STORAGE_DIR
Definition: QmitkTotalSegmentatorToolGUI.h:27
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:28
MitkSegmentationUIExports.h
QmitkTotalSegmentatorToolInstaller::VENV_NAME
const QString VENV_NAME
Definition: QmitkTotalSegmentatorToolGUI.h:22
QmitkTotalSegmentatorToolGUI
GUI for mitk::TotalSegmentatorTool.
Definition: QmitkTotalSegmentatorToolGUI.h:41
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)