Medical Imaging Interaction Toolkit  2026.06.00
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 
18 #include <functional>
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 namespace us
24 {
25  class ModuleResource;
26 }
27 
28 namespace mitk
29 {
48  {
49  public:
51  itkFactorylessNewMacro(Self);
52  itkCloneMacro(Self);
53 
55  enum class Speed
56  {
57  Normal,
58  Fast,
59  Fastest
60  };
61 
68  using CommandRunner = std::function<bool(const std::string& executable, const std::vector<std::string>& args)>;
69 
70  const char *GetName() const override;
71 
74 
76  void Activated() override;
77 
78  itkSetMacro(Task, std::string);
79  itkGetConstMacro(Task, std::string);
80 
81  itkSetMacro(Speed, Speed);
82  itkGetConstMacro(Speed, Speed);
83 
84  itkSetMacro(Device, std::string);
85  itkGetConstMacro(Device, std::string);
86 
87  itkSetMacro(ExecutablePath, std::string);
88  itkGetConstMacro(ExecutablePath, std::string);
89 
95  void SetLabelNameLookup(const std::map<mitk::Label::PixelType, std::string>& lookup);
96 
98 
108  const std::string& GetLastErrorMessage() const;
109 
110  protected:
113 
121  void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, MultiLabelSegmentation* previewImage, TimeStepType timeStep) override;
122  void UpdatePrepare() override;
123 
124  private:
126  std::vector<std::string> BuildArguments(const std::string& inputImagePath, const std::string& outputImagePath) const;
127 
129  void MapLabelsToSegmentation(const MultiLabelSegmentation* source, MultiLabelSegmentation* dest) const;
130 
131  std::string m_MitkTempDir;
132  std::string m_Task = "total";
133  Speed m_Speed = Speed::Normal;
134  std::string m_Device = "gpu";
135  std::string m_ExecutablePath;
136  std::map<mitk::Label::PixelType, std::string> m_LabelNameLookup;
137  CommandRunner m_CommandRunner;
138  std::string m_LastErrorMessage;
139  };
140 } // namespace mitk
141 #endif
#define MITKPYTHONSEGMENTATION_EXPORT
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
AlgorithmType
Enumeration describing how a label was created or refined.
Definition: mitkLabel.h:283
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
Base class for any auto segmentation tool that provides a preview of the new segmentation.
TotalSegmentator segmentation tool.
void SetLabelNameLookup(const std::map< mitk::Label::PixelType, std::string > &lookup)
Sets the label-id-to-name lookup for the selected task.
mitkClassMacro(TotalSegmentatorTool, SegWithPreviewTool)
void DoUpdatePreview(const Image *inputAtTimeStep, const Image *oldSegAtTimeStep, MultiLabelSegmentation *previewImage, TimeStepType timeStep) override
Runs TotalSegmentator on the input and loads its multi-label output.
void Activated() override
Called when the tool gets activated.
us::ModuleResource GetIconResource() const override
Returns the tool button icon of the tool wrapped by a usModuleResource.
const std::string & GetLastErrorMessage() const
Human-readable reason the last run produced no result, or empty if it succeeded or was cancelled by t...
Speed
Model resolution: full (1.5 mm), –fast (3 mm) or –fastest (6 mm).
void UpdatePrepare() override
mitk::Label::AlgorithmType GetAlgorithmType() const override
TotalSegmentator runs with no per-image human input, so AUTOMATIC.
void SetCommandRunner(CommandRunner runner)
const char * GetName() const override
Returns the name of this tool. Make it short!
std::function< bool(const std::string &executable, const std::vector< std::string > &args)> CommandRunner
Runs executable with args, returning true on success (exit 0) and false on cancellation or failure.
Represents a resource (text file, image, etc.) embedded in a CppMicroServices module.
Find image slices visible on a given plane.
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).