Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
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);
76 
77  /*itk macro was not used on purpose, to avoid the change of mtime.*/
78  void SetOverwriteStyle(MultiLabelSegmentation::OverwriteStyle 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  LabelSetImage* GetTargetSegmentation() const;
139 
142  LabelSetImage* GetPreviewSegmentation();
143  const LabelSetImage* 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 
199  static void TransferLabelInformation(const LabelMappingType& labelMapping,
200  const mitk::LabelSetImage* source, mitk::LabelSetImage* target);
201 
204  static void TransferLabelSetImageContent(const LabelSetImage* source, LabelSetImage* target, TimeStepType timeStep);
205 
212  virtual void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, LabelSetImage* previewImage, TimeStepType timeStep) = 0;
213 
219  const Image* GetSegmentationInput() const;
220 
223  const Image* GetReferenceData() const;
224 
229  void ResetPreviewNode();
230 
233  void ResetPreviewContent();
234 
237  void ResetPreviewContentAtTimeStep(unsigned int timeStep);
238 
239  TimePointType GetLastTimePointOfUpdate() const;
240 
241  LabelSetImage::LabelValueType GetActiveLabelValueOfPreview() const;
242 
243  itkGetConstMacro(UserDefinedActiveLabel, Label::PixelType);
244 
245  itkSetObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
246  itkGetConstObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
247 
248  bool ConfirmBeforeDeactivation() override;
249 
250  private:
251  void TransferImageAtTimeStep(const Image* sourceImage, Image* destinationImage, const TimeStepType timeStep, const LabelMappingType& labelMapping);
252 
253  void CreateResultSegmentationFromPreview();
254 
255  void OnRoiDataChanged();
256  void OnTimePointChanged();
257 
265  bool EnsureUpToDateUserDefinedActiveLabel();
266 
270  LabelMappingType GetLabelMapping() const;
271 
273  DataNode::Pointer m_PreviewSegmentationNode;
275  DataNode::Pointer m_ReferenceDataNode;
278  DataNode::Pointer m_SegmentationInputNode;
279 
282  bool m_CreateAllTimeSteps = false;
283 
285  bool m_KeepActiveAfterAccept = false;
286 
292  bool m_LazyDynamicPreviews = false;
293 
294  bool m_IsTimePointChangeAware = true;
295 
298  bool m_ResetsToEmptyPreview = false;
299 
302  bool m_UseSpecialPreviewColor = true;
303 
304  TimePointType m_LastTimePointOfUpdate = 0.;
305 
306  bool m_IsUpdating = false;
307 
308  Label::PixelType m_UserDefinedActiveLabel = 1;
309 
315  PlaneGeometry::Pointer m_WorkingPlaneGeometry;
316 
323 
324  LabelTransferScope m_LabelTransferScope = LabelTransferScope::ActiveLabel;
325  SelectedLabelVectorType m_SelectedLabels = {};
326 
327  LabelTransferMode m_LabelTransferMode = LabelTransferMode::MapLabel;
328 
329  bool m_IsPreviewGenerated = false;
330 
334  bool m_RequestDeactivationConfirmation = false;
335  };
336 
337 } // namespace
338 
339 #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::OverwriteStyle::RegardLocks
@ RegardLocks
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::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:83
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::SegWithPreviewTool::LabelTransferScope
LabelTransferScope
Definition: mitkSegWithPreviewTool.h:81
mitk::MultiLabelSegmentation::MergeStyle::Replace
@ Replace
mitkToolCommand.h
mitk::MultiLabelSegmentation::MergeStyle
MergeStyle
Definition: mitkLabelSetImage.h:605
us::Module
Definition: usModule.h:78
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
mitk::MultiLabelSegmentation::OverwriteStyle
OverwriteStyle
Definition: mitkLabelSetImage.h:613
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::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
mitk::LabelSetImage
LabelSetImage class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:43
mitk::LabelSetImage::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:75