Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkSegWithPreviewTool.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 mitkSegWithPreviewTool_h
14 #define mitkSegWithPreviewTool_h
15 
16 #include <mitkTool.h>
17 #include <mitkCommon.h>
18 #include <mitkDataNode.h>
19 #include <mitkToolCommand.h>
21 
22 namespace mitk
23 {
39  {
40  public:
41 
43 
44  void Activated() override;
45  void Deactivated() override;
46 
50 
58 
60  itkSetMacro(CreateAllTimeSteps, bool);
61  itkGetMacro(CreateAllTimeSteps, bool);
62  itkBooleanMacro(CreateAllTimeSteps);
63 
65  itkSetMacro(KeepActiveAfterAccept, bool);
66  itkGetMacro(KeepActiveAfterAccept, bool);
67  itkBooleanMacro(KeepActiveAfterAccept);
68 
70  itkSetMacro(IsTimePointChangeAware, bool);
71  itkGetMacro(IsTimePointChangeAware, bool);
72  itkBooleanMacro(IsTimePointChangeAware);
73 
75  itkSetMacro(ResetsToEmptyPreview, bool);
76  itkGetMacro(ResetsToEmptyPreview, bool);
77  itkBooleanMacro(ResetsToEmptyPreview);
78 
80  itkSetMacro(UseSpecialPreviewColor, bool);
81  itkGetMacro(UseSpecialPreviewColor, bool);
82  itkBooleanMacro(UseSpecialPreviewColor);
83 
85  itkSetMacro(RequestDeactivationConfirmation, bool);
86  itkGetMacro(RequestDeactivationConfirmation, bool);
87  itkBooleanMacro(RequestDeactivationConfirmation);
88 
94 
101  itkGetMacro(MergeStyle, MultiLabelSegmentation::MergeStyle);
102 
109  itkGetMacro(OverwriteStyle, MultiLabelSegmentation::OverwriteStyle);
110 
115  {
116  ActiveLabel,
117  SelectedLabels,
118  AllLabels
119  };
120 
126  void SetLabelTransferScope(LabelTransferScope labelTransferScope);
128 
130  using SelectedLabelVectorType = std::vector<Label::PixelType>;
131 
140  void SetSelectedLabels(const SelectedLabelVectorType& labelsToTransfer);
141  itkGetMacro(SelectedLabels, SelectedLabelVectorType);
142 
146  enum class LabelTransferMode
147  {
148  MapLabel,
149  AddLabel
150  };
151 
157  void SetLabelTransferMode(LabelTransferMode labelTransferMode);
159 
160  bool CanHandle(const BaseData* referenceData, const BaseData* workingData) const override;
161 
171  void UpdatePreview(bool ignoreLazyPreviewSetting = false);
172 
174  bool IsUpdating() const;
175 
181 
188 
194 
197  void SetPreviewOpacity(float opacity);
198  itkGetConstMacro(PreviewOpacity, float);
199 
202  void SetPreviewVisibility(bool visible);
203  itkGetConstMacro(PreviewVisibility, bool);
204 
205  protected:
207 
208  SegWithPreviewTool(bool lazyDynamicPreviews = false); // purposely hidden
209  SegWithPreviewTool(bool lazyDynamicPreviews, const char* interactorType, const us::Module* interactorModule = nullptr); // purposely hidden
210 
212 
213  const char* GetGroup() const override;
214 
216  static Image::ConstPointer GetImageByTimeStep(const Image* image, TimeStepType timestep);
218  static Image::Pointer GetImageByTimeStep(Image* image, TimeStepType timestep);
220  static Image::ConstPointer GetImageByTimePoint(const Image* image, TimePointType timePoint);
221 
223 
229  virtual void InitiateToolByInput();
230 
234  virtual void UpdatePrepare();
235 
239  virtual void UpdateCleanUp();
240 
244  virtual void ConfirmCleanUp();
245 
246  using LabelMappingType = std::vector<std::pair<Label::PixelType, Label::PixelType> >;
247 
256  virtual void PreparePreviewToResultTransfer(const LabelMappingType& labelMapping);
257 
265  static void TransferLabelInformation(const LabelMappingType& labelMapping,
267 
274  virtual void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, MultiLabelSegmentation* previewImage, TimeStepType timeStep) = 0;
275 
281  const Image* GetSegmentationInput() const;
282 
285  const Image* GetReferenceData() const;
286 
292 
296 
299  void ResetPreviewContentAtTimeStep(unsigned int timeStep);
300 
302 
304 
305  itkGetConstMacro(UserDefinedActiveLabel, Label::PixelType);
306 
307  itkSetObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
308  itkGetConstObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
309 
310  bool ConfirmBeforeDeactivation() override;
311 
317  virtual void OnTimePointChanged();
318 
319  private:
320  void TransferSegmentationsAtTimeStep(const MultiLabelSegmentation* sourceSeg, MultiLabelSegmentation* destinationSeg, const TimeStepType timeStep, const LabelMappingType& labelMapping);
321 
322  void CreateResultSegmentationFromPreview();
323 
324  void OnRoiDataChanged();
325 
333  bool EnsureUpToDateUserDefinedActiveLabel();
334 
338  LabelMappingType GetLabelMapping() const;
339 
341  DataNode::Pointer m_PreviewSegmentationNode;
343  DataNode::Pointer m_ReferenceDataNode;
346  DataNode::Pointer m_SegmentationInputNode;
347 
350  bool m_CreateAllTimeSteps = false;
351 
353  bool m_KeepActiveAfterAccept = false;
354 
360  bool m_LazyDynamicPreviews = false;
361 
362  bool m_IsTimePointChangeAware = true;
363 
366  bool m_ResetsToEmptyPreview = false;
367 
370  bool m_UseSpecialPreviewColor = true;
371 
372  TimePointType m_LastTimePointOfUpdate = 0.;
373 
374  bool m_IsUpdating = false;
375 
376  Label::PixelType m_UserDefinedActiveLabel = 1;
377 
383  PlaneGeometry::Pointer m_WorkingPlaneGeometry;
384 
391 
392  LabelTransferScope m_LabelTransferScope = LabelTransferScope::ActiveLabel;
393  SelectedLabelVectorType m_SelectedLabels = {};
394 
395  LabelTransferMode m_LabelTransferMode = LabelTransferMode::MapLabel;
396 
397  bool m_IsPreviewGenerated = false;
398 
403  float m_PreviewOpacity = 1.0f / 3.0f;
404 
408  bool m_PreviewVisibility = true;
409 
413  bool m_RequestDeactivationConfirmation = false;
414  };
415 
416 } // namespace
417 
418 #endif
#define MITKSEGMENTATION_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
unsigned short PixelType
Pixel type used for label values (unsigned short).
Definition: mitkLabel.h:106
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.
@ RegardLocks
Locked labels in the same spatial group will not be overwritten/changed.
mitk::Label::PixelType LabelValueType
Describes the geometry of a plane object.
Base class for any auto segmentation tool that provides a preview of the new segmentation.
virtual void UpdateCleanUp()
void SetOverwriteStyle(MultiLabelSegmentation::OverwriteStyle overwriteStyle)
Sets whether locked labels should be overwritten during transfer.
virtual void UpdatePrepare()
LabelTransferMode
Defines how labels are transferred from preview to the working image.
DataNode * GetPreviewSegmentationNode()
void EnsureTargetSegmentationNodeInDataStorage() const
virtual void InitiateToolByInput()
void SetPreviewOpacity(float opacity)
mitk::Label::AlgorithmType GetAlgorithmType() const override
Preview tools are SEMIAUTOMATIC by default (the user supplies seeds/parameters). Fully automatic prev...
static Image::ConstPointer GetImageByTimePoint(const Image *image, TimePointType timePoint)
bool ConfirmBeforeDeactivation() override
Method call to invoke a dialog box just before exiting.
virtual void ConfirmCleanUp()
Color GetSpecialPreviewColor() const
Returns the special preview color.
virtual void OnTimePointChanged()
void SetSelectedLabels(const SelectedLabelVectorType &labelsToTransfer)
Sets the labels to transfer from preview to working image on confirmation.
virtual DataNode * GetTargetSegmentationNode() const
Returns the currently selected segmentation node.
SegWithPreviewTool(bool lazyDynamicPreviews, const char *interactorType, const us::Module *interactorModule=nullptr)
std::vector< std::pair< Label::PixelType, Label::PixelType > > LabelMappingType
MultiLabelSegmentation * GetTargetSegmentation() const
const char * GetGroup() const override
Name of a group.
static void TransferLabelInformation(const LabelMappingType &labelMapping, const mitk::MultiLabelSegmentation *source, mitk::MultiLabelSegmentation *target)
Copies label information (not pixel content) from one segmentation to another.
virtual void DoUpdatePreview(const Image *inputAtTimeStep, const Image *oldSegAtTimeStep, MultiLabelSegmentation *previewImage, TimeStepType timeStep)=0
mitkClassMacro(SegWithPreviewTool, Tool)
~SegWithPreviewTool() override
MultiLabelSegmentation::LabelValueType GetActiveLabelValueOfPreview() const
void SetPreviewVisibility(bool visible)
void SetMergeStyle(MultiLabelSegmentation::MergeStyle mergeStyle)
Sets how the preview content is merged into the working image upon confirmation.
SegWithPreviewTool(bool lazyDynamicPreviews=false)
bool CanHandle(const BaseData *referenceData, const BaseData *workingData) const override
Checks if a tool can handle the given reference data and optional working data.
MultiLabelSegmentation * GetPreviewSegmentation()
std::vector< Label::PixelType > SelectedLabelVectorType
Type for the vector of selected label values.
void ConfirmSegmentation()
Confirms the current preview segmentation and transfers it to the working image.
static Image::ConstPointer GetImageByTimeStep(const Image *image, TimeStepType timestep)
void UpdatePreview(bool ignoreLazyPreviewSetting=false)
Triggers the update of the preview segmentation.
LabelTransferScope
Defines which labels from the preview are transferred on confirmation.
std::string GetCurrentSegmentationName()
Returns the name of the currently selected segmentation node.
TimePointType GetLastTimePointOfUpdate() const
virtual void PreparePreviewToResultTransfer(const LabelMappingType &labelMapping)
Called before the preview content is transferred to the segmentation on confirmation.
const Image * GetReferenceData() const
const MultiLabelSegmentation * GetPreviewSegmentation() const
void SetLabelTransferMode(LabelTransferMode labelTransferMode)
Sets how labels are transferred from preview to the working image.
ToolCommand::Pointer m_ProgressCommand
void SetLabelTransferScope(LabelTransferScope labelTransferScope)
Sets which labels from the preview are transferred on confirmation.
void Deactivated() override
Called when the tool gets deactivated.
void ResetPreviewContentAtTimeStep(unsigned int timeStep)
const Image * GetSegmentationInput() const
static Image::Pointer GetImageByTimeStep(Image *image, TimeStepType timestep)
void Activated() override
Called when the tool gets activated.
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:80
Represents a CppMicroServices module.
Definition: usModule.h:70
Find image slices visible on a given plane.
itk::RGBPixel< float > Color
Standard RGB color typedef using float components.
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
mitk::ScalarType TimePointType
Type for time point values in milliseconds (ms).