Medical Imaging Interaction Toolkit  2024.12.99-01bcec80
Medical Imaging Interaction Toolkit
mitkSegTool2D.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 mitkSegTool2D_h
14 #define mitkSegTool2D_h
15 
16 #include <mitkCommon.h>
17 #include <mitkImage.h>
18 #include <mitkTool.h>
20 
22 
23 #include <mitkInteractionConst.h>
26 
27 #include <mitkSegSliceOperation.h>
28 
29 #include <usModuleResource.h>
30 
31 namespace mitk
32 {
33  class BaseRenderer;
34 
57  {
58  public:
60 
71  static bool DetermineAffectedImageSlice(const Image *image,
72  const PlaneGeometry *plane,
73  int &affectedDimension,
74  int &affectedSlice);
75 
85  static void UpdateAllSurfaceInterpolations(const MultiLabelSegmentation* workingImage,
86  TimeStepType timeStep,
87  const PlaneGeometry *plane,
88  bool detectIntersection);
89 
100  static Image::Pointer GetAffectedImageSliceAs2DImage(const InteractionPositionEvent* positionEvent, const Image* image, unsigned int component = 0);
101 
113  static Image::Pointer GetAffectedImageSliceAs2DImage(const PlaneGeometry* planeGeometry,
114  const Image* image,
115  TimeStepType timeStep,
116  unsigned int component = 0);
117  static Image::Pointer GetAffectedImageSliceAs2DImageByTimePoint(const PlaneGeometry* planeGeometry,
118  const Image* image,
119  TimePointType timePoint,
120  unsigned int component = 0);
121 
134  static void WriteBackSegmentationResult(const DataNode* workingNode, const PlaneGeometry* planeGeometry, const Image* segmentationResult, TimeStepType timeStep, const std::string& toolName);
135 
143  static void WriteSliceToVolume(Image* workingImage, const PlaneGeometry* planeGeometry, const Image* slice, TimeStepType timeStep);
144 
145  void SetShowMarkerNodes(bool);
146 
151  void SetEnable3DInterpolation(bool);
152 
153  void Activated() override;
154  void Deactivated() override;
155 
156  itkSetMacro(IsTimePointChangeAware, bool);
157  itkGetMacro(IsTimePointChangeAware, bool);
158  itkBooleanMacro(IsTimePointChangeAware);
159 
160  protected:
161  SegTool2D(); // purposely hidden
162  SegTool2D(const char *, const us::Module *interactorModule = nullptr); // purposely hidden
163  ~SegTool2D() override;
164 
168  DataNode* GetWorkingDataNode() const;
169  MultiLabelSegmentation* GetWorkingData() const;
170 
171  DataNode* GetReferenceDataNode() const;
172  Image* GetReferenceData() const;
173 
177  virtual void OnTimePointChanged();
178 
180  {
182  const mitk::PlaneGeometry *plane = nullptr;
183  mitk::TimeStepType timestep = 0;
184  unsigned int slicePosition;
185 
186  SliceInformation() = default;
187  SliceInformation(const mitk::Image* aSlice, const mitk::PlaneGeometry* aPlane, mitk::TimeStepType aTimestep);
188  };
189 
200  static void UpdateSurfaceInterpolation(const std::vector<SliceInformation>& sliceInfos,
201  const Image* workingImage,
202  bool detectIntersection,
203  mitk::Label::PixelType activeLabelValue, bool silent = false);
204 
205 
212  bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode) override;
213 
220  Image::Pointer GetAffectedWorkingSlice(const InteractionPositionEvent *) const;
221 
228  Image::Pointer GetAffectedReferenceSlice(const InteractionPositionEvent *) const;
230  Image::Pointer GetAffectedReferenceSlice(const PlaneGeometry* planeGeometry, TimeStepType timeStep) const;
231 
234  void WriteBackSegmentationResult(const InteractionPositionEvent *, const Image* segmentationResult);
235 
238  void WriteBackSegmentationResult(const PlaneGeometry *planeGeometry, const Image* segmentationResult, TimeStepType timeStep);
239 
242  void WriteBackSegmentationResults(const std::vector<SliceInformation> &sliceList, bool writeSliceToVolume = true);
243 
255  static void WriteBackSegmentationResults(const DataNode* workingNode, const std::vector<SliceInformation>& sliceList, bool writeSliceToVolume = true, bool allowUndo = true, const std::string& toolName = "");
256 
264  static void WriteSliceToVolume(Image* workingImage, const SliceInformation &sliceInfo);
265 
271  int AddContourmarker(const PlaneGeometry* planeGeometry, unsigned int sliceIndex);
272  void DisableContourMarkers();
273 
274  void InteractiveSegmentationBugMessage(const std::string &message) const;
275 
278  static bool IsPositionEventInsideImageRegion(InteractionPositionEvent* positionEvent, const BaseData* data);
279 
280  BaseRenderer *m_LastEventSender = nullptr;
281  unsigned int m_LastEventSlice = 0;
282 
283  itkGetMacro(LastTimePointTriggered, TimePointType);
284 
285  void PushCursor();
286  void PushCursor(us::ModuleResource cursorResource);
287  void PopCursor(bool popFirstCursor = false);
288  void PopAllCursors();
289 
290  private:
294  void OnTimePointChangedInternal();
295 
296  static void RemoveContourFromInterpolator(const SliceInformation& sliceInfo, MultiLabelSegmentation::LabelValueType labelValue);
297 
298  // The prefix of the contourmarkername. Suffix is a consecutive number
299  const std::string m_Contourmarkername;
300  bool m_EnableContourMarkers = true;
301  bool m_ShowMarkerNodes = false;
302  static bool m_SurfaceInterpolationEnabled;
303 
304  bool m_IsTimePointChangeAware = true;
305 
306  TimePointType m_LastTimePointTriggered = 0.;
307 
308  unsigned int m_NumPushedCursors = 0;
309  };
310 
311 } // namespace
312 
313 #endif
mitkTool.h
mitkInteractionConst.h
Constants for most interaction classes, due to the generic StateMachines.
mitk::InteractionEvent
Definition: mitkInteractionEvent.h:26
mitkImage.h
mitk::PlaneGeometry
Describes a two-dimensional, rectangular plane.
Definition: mitkPlaneGeometry.h:78
mitk::SegTool2D::SliceInformation::slice
mitk::Image::ConstPointer slice
Definition: mitkSegTool2D.h:181
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
mitkRestorePlanePositionOperation.h
mitk::SegTool2D::SliceInformation::slicePosition
unsigned int slicePosition
Definition: mitkSegTool2D.h:184
itk::SmartPointer< Self >
mitkPlanePositionManager.h
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
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::SegTool2D::SliceInformation
Definition: mitkSegTool2D.h:179
mitkSegSliceOperation.h
mitk::SegTool2D
Abstract base class for segmentation tools.
Definition: mitkSegTool2D.h:56
mitk::InteractionPositionEvent
Super class for all position events.
Definition: mitkInteractionPositionEvent.h:36
mitkInteractionPositionEvent.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::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
us::ModuleResource
Definition: usModuleResource.h:55
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::BaseRenderer
Definition: mitkBaseRenderer.h:56
mitk::TimePointType
mitk::ScalarType TimePointType
Definition: mitkTimeGeometry.h:26
MitkSegmentationExports.h
usModuleResource.h
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63