Medical Imaging Interaction Toolkit  2025.12.02
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 
48 
49  itkSetMacro(CreateAllTimeSteps, bool);
50  itkGetMacro(CreateAllTimeSteps, bool);
51  itkBooleanMacro(CreateAllTimeSteps);
52 
53  itkSetMacro(KeepActiveAfterAccept, bool);
54  itkGetMacro(KeepActiveAfterAccept, bool);
55  itkBooleanMacro(KeepActiveAfterAccept);
56 
57  itkSetMacro(IsTimePointChangeAware, bool);
58  itkGetMacro(IsTimePointChangeAware, bool);
59  itkBooleanMacro(IsTimePointChangeAware);
60 
61  itkSetMacro(ResetsToEmptyPreview, bool);
62  itkGetMacro(ResetsToEmptyPreview, bool);
63  itkBooleanMacro(ResetsToEmptyPreview);
64 
65  itkSetMacro(UseSpecialPreviewColor, bool);
66  itkGetMacro(UseSpecialPreviewColor, bool);
67  itkBooleanMacro(UseSpecialPreviewColor);
68 
69  itkSetMacro(RequestDeactivationConfirmation, bool);
70  itkGetMacro(RequestDeactivationConfirmation, bool);
71  itkBooleanMacro(RequestDeactivationConfirmation);
72 
74 
75  /*itk macro was not used on purpose, to avoid the change of mtime.*/
77  itkGetMacro(MergeStyle, MultiLabelSegmentation::MergeStyle);
78 
79  /*itk macro was not used on purpose, to avoid the change of mtime.*/
81  itkGetMacro(OverwriteStyle, MultiLabelSegmentation::OverwriteStyle);
82 
83  enum class LabelTransferScope
84  {
85  ActiveLabel, //Only the selected label will be transferred from the preview segmentation
86  //to the result segmentation.
87  //If this mode is selected the class expects that GetSelectedLabels indicate
88  //the label in the preview.
89  SelectedLabels, //The labels defined as selected labels will be transferred.
90  AllLabels //Transfer all labels of the preview
91  };
92  /*itk macro was not used on purpose, to avoid the change of mtime.*/
93  void SetLabelTransferScope(LabelTransferScope labelTransferScope);
95 
96  using SelectedLabelVectorType = std::vector<Label::PixelType>;
102  void SetSelectedLabels(const SelectedLabelVectorType& labelsToTransfer);
103  itkGetMacro(SelectedLabels, SelectedLabelVectorType);
104 
105  enum class LabelTransferMode
106  {
107  MapLabel, //Only the active label will be transferred from preview to segmentation.
108  AddLabel //The labels defined as selected labels will be transferred.
109  };
110  /*itk macro was not used on purpose, to avoid the change of mtime.*/
111  void SetLabelTransferMode(LabelTransferMode labelTransferMode);
113 
114  bool CanHandle(const BaseData* referenceData, const BaseData* workingData) const override;
115 
123  void UpdatePreview(bool ignoreLazyPreviewSetting = false);
124 
126  bool IsUpdating() const;
127 
134 
141 
147 
148  protected:
150 
151  SegWithPreviewTool(bool lazyDynamicPreviews = false); // purposely hidden
152  SegWithPreviewTool(bool lazyDynamicPreviews, const char* interactorType, const us::Module* interactorModule = nullptr); // purposely hidden
153 
155 
156  const char* GetGroup() const override;
157 
164 
166 
172  virtual void InitiateToolByInput();
173 
177  virtual void UpdatePrepare();
178 
182  virtual void UpdateCleanUp();
183 
187  virtual void ConfirmCleanUp();
188 
189  using LabelMappingType = std::vector<std::pair<Label::PixelType, Label::PixelType> >;
190 
199  virtual void PreparePreviewToResultTransfer(const LabelMappingType& labelMapping);
200 
206  static void TransferLabelInformation(const LabelMappingType& labelMapping,
208 
215  virtual void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, MultiLabelSegmentation* previewImage, TimeStepType timeStep) = 0;
216 
222  const Image* GetSegmentationInput() const;
223 
226  const Image* GetReferenceData() const;
227 
233 
237 
240  void ResetPreviewContentAtTimeStep(unsigned int timeStep);
241 
243 
245 
246  itkGetConstMacro(UserDefinedActiveLabel, Label::PixelType);
247 
248  itkSetObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
249  itkGetConstObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
250 
251  bool ConfirmBeforeDeactivation() override;
252 
253  private:
254  void TransferSegmentationsAtTimeStep(const MultiLabelSegmentation* sourceSeg, MultiLabelSegmentation* destinationSeg, const TimeStepType timeStep, const LabelMappingType& labelMapping);
255 
256  void CreateResultSegmentationFromPreview();
257 
258  void OnRoiDataChanged();
259  void OnTimePointChanged();
260 
268  bool EnsureUpToDateUserDefinedActiveLabel();
269 
273  LabelMappingType GetLabelMapping() const;
274 
276  DataNode::Pointer m_PreviewSegmentationNode;
278  DataNode::Pointer m_ReferenceDataNode;
281  DataNode::Pointer m_SegmentationInputNode;
282 
285  bool m_CreateAllTimeSteps = false;
286 
288  bool m_KeepActiveAfterAccept = false;
289 
295  bool m_LazyDynamicPreviews = false;
296 
297  bool m_IsTimePointChangeAware = true;
298 
301  bool m_ResetsToEmptyPreview = false;
302 
305  bool m_UseSpecialPreviewColor = true;
306 
307  TimePointType m_LastTimePointOfUpdate = 0.;
308 
309  bool m_IsUpdating = false;
310 
311  Label::PixelType m_UserDefinedActiveLabel = 1;
312 
318  PlaneGeometry::Pointer m_WorkingPlaneGeometry;
319 
326 
327  LabelTransferScope m_LabelTransferScope = LabelTransferScope::ActiveLabel;
328  SelectedLabelVectorType m_SelectedLabels = {};
329 
330  LabelTransferMode m_LabelTransferMode = LabelTransferMode::MapLabel;
331 
332  bool m_IsPreviewGenerated = false;
333 
337  bool m_RequestDeactivationConfirmation = false;
338  };
339 
340 } // namespace
341 
342 #endif
#define MITKSEGMENTATION_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Image class for storing images.
Definition: mitkImage.h:70
unsigned short PixelType
Definition: mitkLabel.h:94
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 a two-dimensional, rectangular plane.
Base class for any auto segmentation tool that provides a preview of the new segmentation.
virtual void UpdateCleanUp()
void SetOverwriteStyle(MultiLabelSegmentation::OverwriteStyle overwriteStyle)
virtual void UpdatePrepare()
DataNode * GetPreviewSegmentationNode()
void EnsureTargetSegmentationNodeInDataStorage() const
virtual void InitiateToolByInput()
static Image::ConstPointer GetImageByTimePoint(const Image *image, TimePointType timePoint)
bool ConfirmBeforeDeactivation() override
Method call to invoke a dialog box just before exiting. The method can be reimplemented in the respec...
virtual void ConfirmCleanUp()
Color GetSpecialPreviewColor() const
void SetSelectedLabels(const SelectedLabelVectorType &labelsToTransfer)
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)
virtual void DoUpdatePreview(const Image *inputAtTimeStep, const Image *oldSegAtTimeStep, MultiLabelSegmentation *previewImage, TimeStepType timeStep)=0
mitkClassMacro(SegWithPreviewTool, Tool)
~SegWithPreviewTool() override
MultiLabelSegmentation::LabelValueType GetActiveLabelValueOfPreview() const
void SetMergeStyle(MultiLabelSegmentation::MergeStyle mergeStyle)
SegWithPreviewTool(bool lazyDynamicPreviews=false)
bool CanHandle(const BaseData *referenceData, const BaseData *workingData) const override
MultiLabelSegmentation * GetPreviewSegmentation()
std::vector< Label::PixelType > SelectedLabelVectorType
static Image::ConstPointer GetImageByTimeStep(const Image *image, TimeStepType timestep)
void UpdatePreview(bool ignoreLazyPreviewSetting=false)
std::string GetCurrentSegmentationName()
Gets the name of the currently selected segmentation node.
TimePointType GetLastTimePointOfUpdate() const
virtual void PreparePreviewToResultTransfer(const LabelMappingType &labelMapping)
const Image * GetReferenceData() const
const MultiLabelSegmentation * GetPreviewSegmentation() const
void SetLabelTransferMode(LabelTransferMode labelTransferMode)
ToolCommand::Pointer m_ProgressCommand
void SetLabelTransferScope(LabelTransferScope labelTransferScope)
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:79
Find image slices visible on a given plane.
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
std::size_t TimeStepType
mitk::ScalarType TimePointType