Medical Imaging Interaction Toolkit  2024.12.99-2f135637
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 
47  void ConfirmSegmentation();
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 
73  /*itk macro was not used on purpose, to avoid the change of mtime.*/
74  void SetMergeStyle(MultiLabelSegmentation::MergeStyle mergeStyle);
75  itkGetMacro(MergeStyle, MultiLabelSegmentation::MergeStyle);
76 
77  /*itk macro was not used on purpose, to avoid the change of mtime.*/
78  void SetOverwriteStyle(MultiLabelSegmentation::OverwriteStyle overwriteStyle);
79  itkGetMacro(OverwriteStyle, MultiLabelSegmentation::OverwriteStyle);
80 
81  enum class LabelTransferScope
82  {
83  ActiveLabel, //Only the selected label will be transferred from the preview segmentation
84  //to the result segmentation.
85  //If this mode is selected the class expects that GetSelectedLabels indicate
86  //the label in the preview.
87  SelectedLabels, //The labels defined as selected labels will be transferred.
88  AllLabels //Transfer all labels of the preview
89  };
90  /*itk macro was not used on purpose, to avoid the change of mtime.*/
91  void SetLabelTransferScope(LabelTransferScope labelTransferScope);
92  itkGetMacro(LabelTransferScope, LabelTransferScope);
93 
94  using SelectedLabelVectorType = std::vector<Label::PixelType>;
100  void SetSelectedLabels(const SelectedLabelVectorType& labelsToTransfer);
101  itkGetMacro(SelectedLabels, SelectedLabelVectorType);
102 
103  enum class LabelTransferMode
104  {
105  MapLabel, //Only the active label will be transferred from preview to segmentation.
106  AddLabel //The labels defined as selected labels will be transferred.
107  };
108  /*itk macro was not used on purpose, to avoid the change of mtime.*/
109  void SetLabelTransferMode(LabelTransferMode labelTransferMode);
110  itkGetMacro(LabelTransferMode, LabelTransferMode);
111 
112  bool CanHandle(const BaseData* referenceData, const BaseData* workingData) const override;
113 
121  void UpdatePreview(bool ignoreLazyPreviewSetting = false);
122 
124  bool IsUpdating() const;
125 
131  std::string GetCurrentSegmentationName();
132 
137  virtual DataNode* GetTargetSegmentationNode() const;
138  MultiLabelSegmentation* GetTargetSegmentation() const;
139 
142  MultiLabelSegmentation* GetPreviewSegmentation();
143  const MultiLabelSegmentation* GetPreviewSegmentation() const;
144  DataNode* GetPreviewSegmentationNode();
145 
146  protected:
148 
149  SegWithPreviewTool(bool lazyDynamicPreviews = false); // purposely hidden
150  SegWithPreviewTool(bool lazyDynamicPreviews, const char* interactorType, const us::Module* interactorModule = nullptr); // purposely hidden
151 
152  ~SegWithPreviewTool() override;
153 
154  const char* GetGroup() const override;
155 
157  static Image::ConstPointer GetImageByTimeStep(const Image* image, TimeStepType timestep);
159  static Image::Pointer GetImageByTimeStep(Image* image, TimeStepType timestep);
161  static Image::ConstPointer GetImageByTimePoint(const Image* image, TimePointType timePoint);
162 
163  void EnsureTargetSegmentationNodeInDataStorage() const;
164 
170  virtual void InitiateToolByInput();
171 
175  virtual void UpdatePrepare();
176 
180  virtual void UpdateCleanUp();
181 
185  virtual void ConfirmCleanUp();
186 
187  using LabelMappingType = std::vector<std::pair<Label::PixelType, Label::PixelType> >;
188 
197  virtual void PreparePreviewToResultTransfer(const LabelMappingType& labelMapping);
198 
204  static void TransferLabelInformation(const LabelMappingType& labelMapping,
206 
213  virtual void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, MultiLabelSegmentation* previewImage, TimeStepType timeStep) = 0;
214 
220  const Image* GetSegmentationInput() const;
221 
224  const Image* GetReferenceData() const;
225 
230  void ResetPreviewNode();
231 
234  void ResetPreviewContent();
235 
238  void ResetPreviewContentAtTimeStep(unsigned int timeStep);
239 
240  TimePointType GetLastTimePointOfUpdate() const;
241 
242  MultiLabelSegmentation::LabelValueType GetActiveLabelValueOfPreview() const;
243 
244  itkGetConstMacro(UserDefinedActiveLabel, Label::PixelType);
245 
246  itkSetObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
247  itkGetConstObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
248 
249  bool ConfirmBeforeDeactivation() override;
250 
251  private:
252  void TransferSegmentationsAtTimeStep(const MultiLabelSegmentation* sourceSeg, MultiLabelSegmentation* destinationSeg, const TimeStepType timeStep, const LabelMappingType& labelMapping);
253 
254  void CreateResultSegmentationFromPreview();
255 
256  void OnRoiDataChanged();
257  void OnTimePointChanged();
258 
266  bool EnsureUpToDateUserDefinedActiveLabel();
267 
271  LabelMappingType GetLabelMapping() const;
272 
274  DataNode::Pointer m_PreviewSegmentationNode;
276  DataNode::Pointer m_ReferenceDataNode;
279  DataNode::Pointer m_SegmentationInputNode;
280 
283  bool m_CreateAllTimeSteps = false;
284 
286  bool m_KeepActiveAfterAccept = false;
287 
293  bool m_LazyDynamicPreviews = false;
294 
295  bool m_IsTimePointChangeAware = true;
296 
299  bool m_ResetsToEmptyPreview = false;
300 
303  bool m_UseSpecialPreviewColor = true;
304 
305  TimePointType m_LastTimePointOfUpdate = 0.;
306 
307  bool m_IsUpdating = false;
308 
309  Label::PixelType m_UserDefinedActiveLabel = 1;
310 
316  PlaneGeometry::Pointer m_WorkingPlaneGeometry;
317 
324 
325  LabelTransferScope m_LabelTransferScope = LabelTransferScope::ActiveLabel;
326  SelectedLabelVectorType m_SelectedLabels = {};
327 
328  LabelTransferMode m_LabelTransferMode = LabelTransferMode::MapLabel;
329 
330  bool m_IsPreviewGenerated = false;
331 
335  bool m_RequestDeactivationConfirmation = false;
336  };
337 
338 } // namespace
339 
340 #endif
mitk::SegWithPreviewTool
Base class for any auto segmentation tool that provides a preview of the new segmentation.
Definition: mitkSegWithPreviewTool.h:38
mitkTool.h
mitk::MultiLabelSegmentation::MergeStyle::Replace
@ Replace
mitk::SegWithPreviewTool::m_ProgressCommand
ToolCommand::Pointer m_ProgressCommand
Definition: mitkSegWithPreviewTool.h:147
mitk::PlaneGeometry
Describes a two-dimensional, rectangular plane.
Definition: mitkPlaneGeometry.h:78
mitk::MultiLabelSegmentation::OverwriteStyle
OverwriteStyle
Definition: mitkLabelSetImage.h:74
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
itk::SmartPointer< Self >
mitk::Label::PixelType
unsigned short PixelType
Definition: mitkLabel.h:34
mitk::Tool
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:78
mitk::MultiLabelSegmentation::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:57
mitk::MultiLabelSegmentation::OverwriteStyle::RegardLocks
@ RegardLocks
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::SegWithPreviewTool::LabelTransferScope
LabelTransferScope
Definition: mitkSegWithPreviewTool.h:81
mitkToolCommand.h
us::Module
Definition: usModule.h:78
mitk::MultiLabelSegmentation
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:43
mitkCommon.h
MITKSEGMENTATION_EXPORT
#define MITKSEGMENTATION_EXPORT
Definition: MitkSegmentationExports.h:15
mitk::SegWithPreviewTool::LabelTransferMode
LabelTransferMode
Definition: mitkSegWithPreviewTool.h:103
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitkDataNode.h
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::TimePointType
mitk::ScalarType TimePointType
Definition: mitkTimeGeometry.h:26
MitkSegmentationExports.h
mitk::SegWithPreviewTool::LabelMappingType
std::vector< std::pair< Label::PixelType, Label::PixelType > > LabelMappingType
Definition: mitkSegWithPreviewTool.h:187
mitk::SegWithPreviewTool::SelectedLabelVectorType
std::vector< Label::PixelType > SelectedLabelVectorType
Definition: mitkSegWithPreviewTool.h:94
mitk::MultiLabelSegmentation::MergeStyle
MergeStyle
Definition: mitkLabelSetImage.h:66
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63