Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
mitkTotalSegmentatorTool.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 #ifndef MITKTOTALSEGMENTATORTOOL_H
13 #define MITKTOTALSEGMENTATORTOOL_H
14 
15 #include "mitkSegWithPreviewTool.h"
17 #include "mitkProcessExecutor.h"
18 
19 
20 namespace us
21 {
22  class ModuleResource;
23 }
24 
25 namespace mitk
26 {
27 
37  {
38  public:
40  itkFactorylessNewMacro(Self);
41  itkCloneMacro(Self);
42 
43  const char *GetName() const override;
44  const char **GetXPM() const override;
45  us::ModuleResource GetIconResource() const override;
46  void Activated() override;
47 
48  itkSetMacro(MitkTempDir, std::string);
49  itkGetConstMacro(MitkTempDir, std::string);
50 
51  itkSetMacro(SubTask, std::string);
52  itkGetConstMacro(SubTask, std::string);
53 
54  itkSetMacro(PythonPath, std::string);
55  itkGetConstMacro(PythonPath, std::string);
56 
57  itkSetMacro(GpuId, int);
58  itkGetConstMacro(GpuId, int);
59 
60  itkSetMacro(Fast, bool);
61  itkGetConstMacro(Fast, bool);
62  itkBooleanMacro(Fast);
63 
69  static void onPythonProcessEvent(itk::Object *, const itk::EventObject &e, void *);
70 
71  protected:
74 
89  void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, LabelSetImage* previewImage, TimeStepType timeStep) override;
90  void UpdatePrepare() override;
91 
92  private:
93 
98  void run_totalsegmentator(ProcessExecutor*, const std::string&, const std::string&, bool, bool, int, const std::string&);
99 
104  void MapLabelsToSegmentation(const mitk::LabelSetImage*, mitk::LabelSetImage*, std::map<mitk::Label::PixelType, std::string>&);
105 
111  void ParseLabelMapTotalDefault();
112 
118  std::string GetLabelMapPath();
119 
129  LabelSetImage::Pointer AgglomerateLabelFiles(std::vector<std::string>& filePaths, const unsigned int* dimension, mitk::BaseGeometry* geometry);
130 
131  std::string m_MitkTempDir;
132  std::string m_PythonPath;
133  std::string m_SubTask = "total";
134  int m_GpuId = 0;
135  std::map<mitk::Label::PixelType, std::string> m_LabelMapTotal;
136  std::map<mitk::Label::PixelType, std::string> m_LabelMapTotalMR;
137  bool m_Fast = true;
138  const std::string TEMPLATE_FILENAME = "XXXXXX_000_0000.nii.gz";
139  const std::string DEFAULT_TOTAL_TASK = "total";
140  const std::string DEFAULT_TOTAL_TASK_MRI = "total_mr";
141  const std::unordered_map<std::string, std::vector<std::string>> SUBTASKS_MAP =
142  {
143  {"body", { "body.nii.gz", "body_trunc.nii.gz", "body_extremities.nii.gz", "skin.nii.gz"}},
144  {"hip_implant", {"hip_implant.nii.gz"}},
145  {"cerebral_bleed", {"intracerebral_hemorrhage.nii.gz"}},
146  {"coronary_arteries", {"coronary_arteries.nii.gz"}},
147  {"lung_vessels", {"lung_vessels.nii.gz", "lung_trachea_bronchia.nii.gz"}},
148  {"pleural_pericard_effusion", {"pleural_effusion.nii.gz", "pericardial_effusion.nii.gz"}},
149  {"head_glands_cavities", {"eye_left.nii.gz", "eye_right.nii.gz", "eye_lens_left.nii.gz", "eye_lens_right.nii.gz", "optic_nerve_left.nii.gz", "optic_nerve_right.nii.gz", "parotid_gland_left.nii.gz", "parotid_gland_right.nii.gz", "submandibular_gland_right.nii.gz", "submandibular_gland_left.nii.gz", "nasopharynx.nii.gz", "oropharynx.nii.gz", "hypopharynx.nii.gz", "nasal_cavity_right.nii.gz", "nasal_cavity_left.nii.gz", "auditory_canal_right.nii.gz", "auditory_canal_left.nii.gz", "soft_palate.nii.gz", "hard_palate.nii.gz" }},
150  {"head_muscles", {"masseter_right.nii.gz", "masseter_left.nii.gz", "temporalis_right.nii.gz", "temporalis_left.nii.gz", "lateral_pterygoid_right.nii.gz", "lateral_pterygoid_left.nii.gz", "medial_pterygoid_right.nii.gz", "medial_pterygoid_left.nii.gz", "tongue.nii.gz", "digastric_right.nii.gz", "digastric_left.nii.gz"}},
151  {"headneck_bones_vessels", {"larynx_air.nii.gz" , "thyroid_cartilage.nii.gz" , "hyoid.nii.gz" , "cricoid_cartilage.nii.gz", "zygomatic_arch_right.nii.gz", "zygomatic_arch_left.nii.gz", "styloid_process_right.nii.gz", "styloid_process_left.nii.gz", "internal_carotid_artery_right.nii.gz", "internal_carotid_artery_left.nii.gz", "internal_jugular_vein_right.nii.gz", "internal_jugular_vein_left.nii.gz"}},
152  {"headneck_muscles", {"sternocleidomastoid_right.nii.gz", "sternocleidomastoid_left.nii.gz", "superior_pharyngeal_constrictor.nii.gz", "middle_pharyngeal_constrictor.nii.gz", "inferior_pharyngeal_constrictor.nii.gz", "trapezius_right.nii.gz", "trapezius_left.nii.gz", "platysma_right.nii.gz", "platysma_left.nii.gz", "levator_scapulae_right.nii.gz", "levator_scapulae_left.nii.gz", "anterior_scalene_right.nii.gz", "anterior_scalene_left.nii.gz", "middle_scalene_right.nii.gz", "middle_scalene_left.nii.gz", "posterior_scalene_right.nii.gz", "posterior_scalene_left.nii.gz", "sterno_thyroid_right.nii.gz", "sterno_thyroid_left.nii.gz", "thyrohyoid_right.nii.gz", "thyrohyoid_left.nii.gz", "prevertebral_right.nii.gz", "prevertebral_left.nii.gz"}},
153  {"liver_vessels", {"liver_vessels.nii.gz" , "liver_tumor.nii.gz"}}
154  };
155  }; // class
156 } // namespace
157 #endif
mitk::SegWithPreviewTool
Base class for any auto segmentation tool that provides a preview of the new segmentation.
Definition: mitkSegWithPreviewTool.h:38
mitkProcessExecutor.h
us
Definition: mitkAbstractFileReader.h:29
mitkSegWithPreviewTool.h
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
itk::SmartPointer< Self >
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::EventStateMachine
‍**
Definition: mitkEventStateMachine.h:111
mitk::BaseGeometry
BaseGeometry Describes the geometry of a data object.
Definition: mitkBaseGeometry.h:94
MITKSEGMENTATION_EXPORT
#define MITKSEGMENTATION_EXPORT
Definition: MitkSegmentationExports.h:15
us::ModuleResource
Definition: usModuleResource.h:55
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
MitkSegmentationExports.h
mitk::ProcessExecutor
You may register an observer for an ExternalProcessOutputEvent, ExternalProcessStdOutEvent or Externa...
Definition: mitkProcessExecutor.h:67
mitk::LabelSetImage
LabelSetImage class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:43
mitk::TotalSegmentatorTool
TotalSegmentator segmentation tool.
Definition: mitkTotalSegmentatorTool.h:36