Medical Imaging Interaction Toolkit  2023.12.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 
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  /*itk macro was not used on purpose, to aviod the change of mtime.*/
70  void SetMergeStyle(MultiLabelSegmentation::MergeStyle mergeStyle);
72 
73  /*itk macro was not used on purpose, to aviod the change of mtime.*/
74  void SetOverwriteStyle(MultiLabelSegmentation::OverwriteStyle overwriteStyle);
76 
77  enum class LabelTransferScope
78  {
79  ActiveLabel, //Only the selected label will be transfered from the preview segmentation
80  //to the result segmentation.
81  //If this mode is selected the class expects that GetSelectedLabels indicate
82  //the label in the preview.
83  SelectedLabels, //The labels defined as selected labels will be transfered.
84  AllLabels //Transfer all labels of the preview
85  };
86  /*itk macro was not used on purpose, to aviod the change of mtime.*/
87  void SetLabelTransferScope(LabelTransferScope labelTransferScope);
88  itkGetMacro(LabelTransferScope, LabelTransferScope);
89 
90  using SelectedLabelVectorType = std::vector<Label::PixelType>;
96  void SetSelectedLabels(const SelectedLabelVectorType& labelsToTransfer);
97  itkGetMacro(SelectedLabels, SelectedLabelVectorType);
98 
99  enum class LabelTransferMode
100  {
101  MapLabel, //Only the active label will be transfered from preview to segmentation.
102  AddLabel //The labels defined as selected labels will be transfered.
103  };
104  /*itk macro was not used on purpose, to aviod the change of mtime.*/
105  void SetLabelTransferMode(LabelTransferMode labelTransferMode);
106  itkGetMacro(LabelTransferMode, LabelTransferMode);
107 
108  bool CanHandle(const BaseData* referenceData, const BaseData* workingData) const override;
109 
117  void UpdatePreview(bool ignoreLazyPreviewSetting = false);
118 
120  bool IsUpdating() const;
121 
127  std::string GetCurrentSegmentationName();
128 
133  virtual DataNode* GetTargetSegmentationNode() const;
134  LabelSetImage* GetTargetSegmentation() const;
135 
138  LabelSetImage* GetPreviewSegmentation();
139  const LabelSetImage* GetPreviewSegmentation() const;
140  DataNode* GetPreviewSegmentationNode();
141 
142  protected:
144 
145  SegWithPreviewTool(bool lazyDynamicPreviews = false); // purposely hidden
146  SegWithPreviewTool(bool lazyDynamicPreviews, const char* interactorType, const us::Module* interactorModule = nullptr); // purposely hidden
147 
148  ~SegWithPreviewTool() override;
149 
150  const char* GetGroup() const override;
151 
153  static Image::ConstPointer GetImageByTimeStep(const Image* image, TimeStepType timestep);
155  static Image::Pointer GetImageByTimeStep(Image* image, TimeStepType timestep);
157  static Image::ConstPointer GetImageByTimePoint(const Image* image, TimePointType timePoint);
158 
159  void EnsureTargetSegmentationNodeInDataStorage() const;
160 
166  virtual void InitiateToolByInput();
167 
171  virtual void UpdatePrepare();
172 
176  virtual void UpdateCleanUp();
177 
181  virtual void ConfirmCleanUp();
182 
183  using LabelMappingType = std::vector<std::pair<Label::PixelType, Label::PixelType> >;
184 
193  virtual void PreparePreviewToResultTransfer(const LabelMappingType& labelMapping);
194 
195  static void TransferLabelInformation(const LabelMappingType& labelMapping,
196  const mitk::LabelSetImage* source, mitk::LabelSetImage* target);
197 
200  static void TransferLabelSetImageContent(const LabelSetImage* source, LabelSetImage* target, TimeStepType timeStep);
201 
208  virtual void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, LabelSetImage* previewImage, TimeStepType timeStep) = 0;
209 
215  const Image* GetSegmentationInput() const;
216 
219  const Image* GetReferenceData() const;
220 
225  void ResetPreviewNode();
226 
229  void ResetPreviewContent();
230 
233  void ResetPreviewContentAtTimeStep(unsigned int timeStep);
234 
235  TimePointType GetLastTimePointOfUpdate() const;
236 
237  LabelSetImage::LabelValueType GetActiveLabelValueOfPreview() const;
238 
239  itkGetConstMacro(UserDefinedActiveLabel, Label::PixelType);
240 
241  itkSetObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
242  itkGetConstObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
243 
244  private:
245  void TransferImageAtTimeStep(const Image* sourceImage, Image* destinationImage, const TimeStepType timeStep, const LabelMappingType& labelMapping);
246 
247  void CreateResultSegmentationFromPreview();
248 
249  void OnRoiDataChanged();
250  void OnTimePointChanged();
251 
259  bool EnsureUpToDateUserDefinedActiveLabel();
260 
264  LabelMappingType GetLabelMapping() const;
265 
267  DataNode::Pointer m_PreviewSegmentationNode;
269  DataNode::Pointer m_ReferenceDataNode;
272  DataNode::Pointer m_SegmentationInputNode;
273 
276  bool m_CreateAllTimeSteps = false;
277 
279  bool m_KeepActiveAfterAccept = false;
280 
286  bool m_LazyDynamicPreviews = false;
287 
288  bool m_IsTimePointChangeAware = true;
289 
292  bool m_ResetsToEmptyPreview = false;
293 
296  bool m_UseSpecialPreviewColor = true;
297 
298  TimePointType m_LastTimePointOfUpdate = 0.;
299 
300  bool m_IsUpdating = false;
301 
302  Label::PixelType m_UserDefinedActiveLabel = 1;
303 
309  PlaneGeometry::Pointer m_WorkingPlaneGeometry;
310 
317 
318  LabelTransferScope m_LabelTransferScope = LabelTransferScope::ActiveLabel;
319  SelectedLabelVectorType m_SelectedLabels = {};
320 
321  LabelTransferMode m_LabelTransferMode = LabelTransferMode::MapLabel;
322  };
323 
324 } // namespace
325 
326 #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:143
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:77
mitk::MultiLabelSegmentation::MergeStyle::Replace
@ Replace
mitkToolCommand.h
mitk::MultiLabelSegmentation::MergeStyle
MergeStyle
Definition: mitkLabelSetImage.h:568
us::Module
Definition: usModule.h:78
mitkCommon.h
MITKSEGMENTATION_EXPORT
#define MITKSEGMENTATION_EXPORT
Definition: MitkSegmentationExports.h:15
mitk::SegWithPreviewTool::LabelTransferMode
LabelTransferMode
Definition: mitkSegWithPreviewTool.h:99
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::MultiLabelSegmentation::OverwriteStyle
OverwriteStyle
Definition: mitkLabelSetImage.h:576
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:183
mitk::SegWithPreviewTool::SelectedLabelVectorType
std::vector< Label::PixelType > SelectedLabelVectorType
Definition: mitkSegWithPreviewTool.h:90
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:29
mitk::LabelSetImage::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:62