Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
178  using LabelMappingType = std::vector<std::pair<Label::PixelType, Label::PixelType> >;
179 
188  virtual void PreparePreviewToResultTransfer(const LabelMappingType& labelMapping);
189 
190  static void TransferLabelInformation(const LabelMappingType& labelMapping,
191  const mitk::LabelSetImage* source, mitk::LabelSetImage* target);
192 
195  static void TransferLabelSetImageContent(const LabelSetImage* source, LabelSetImage* target, TimeStepType timeStep);
196 
203  virtual void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, LabelSetImage* previewImage, TimeStepType timeStep) = 0;
204 
210  const Image* GetSegmentationInput() const;
211 
214  const Image* GetReferenceData() const;
215 
220  void ResetPreviewNode();
221 
224  void ResetPreviewContent();
225 
228  void ResetPreviewContentAtTimeStep(unsigned int timeStep);
229 
230  TimePointType GetLastTimePointOfUpdate() const;
231 
232  LabelSetImage::LabelValueType GetActiveLabelValueOfPreview() const;
233 
234  itkGetConstMacro(UserDefinedActiveLabel, Label::PixelType);
235 
236  itkSetObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
237  itkGetConstObjectMacro(WorkingPlaneGeometry, PlaneGeometry);
238 
239  private:
240  void TransferImageAtTimeStep(const Image* sourceImage, Image* destinationImage, const TimeStepType timeStep, const LabelMappingType& labelMapping);
241 
242  void CreateResultSegmentationFromPreview();
243 
244  void OnRoiDataChanged();
245  void OnTimePointChanged();
246 
254  bool EnsureUpToDateUserDefinedActiveLabel();
255 
259  LabelMappingType GetLabelMapping() const;
260 
262  DataNode::Pointer m_PreviewSegmentationNode;
264  DataNode::Pointer m_ReferenceDataNode;
267  DataNode::Pointer m_SegmentationInputNode;
268 
271  bool m_CreateAllTimeSteps = false;
272 
274  bool m_KeepActiveAfterAccept = false;
275 
281  bool m_LazyDynamicPreviews = false;
282 
283  bool m_IsTimePointChangeAware = true;
284 
287  bool m_ResetsToEmptyPreview = false;
288 
291  bool m_UseSpecialPreviewColor = true;
292 
293  TimePointType m_LastTimePointOfUpdate = 0.;
294 
295  bool m_IsUpdating = false;
296 
297  Label::PixelType m_UserDefinedActiveLabel = 1;
298 
304  PlaneGeometry::Pointer m_WorkingPlaneGeometry;
305 
312 
313  LabelTransferScope m_LabelTransferScope = LabelTransferScope::ActiveLabel;
314  SelectedLabelVectorType m_SelectedLabels = {};
315 
316  LabelTransferMode m_LabelTransferMode = LabelTransferMode::MapLabel;
317  };
318 
319 } // namespace
320 
321 #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:33
mitk::Tool
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:83
mitk
DataCollection - Class to facilitate loading/accessing structured data.
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:178
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