Medical Imaging Interaction Toolkit  2025.12.02
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 
114  const Image* image,
115  TimeStepType timeStep,
116  unsigned int component = 0);
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 
152 
153  void Activated() override;
154  void Deactivated() override;
155 
156  itkSetMacro(IsTimePointChangeAware, bool);
157  itkGetMacro(IsTimePointChangeAware, bool);
158  itkBooleanMacro(IsTimePointChangeAware);
159 
165 
168 
169  protected:
170  SegTool2D(); // purposely hidden
171  SegTool2D(const char *, const us::Module *interactorModule = nullptr); // purposely hidden
172  ~SegTool2D() override;
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 
221 
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);
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);
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
#define MITKSEGMENTATION_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Image class for storing images.
Definition: mitkImage.h:70
Super class for all position events.
unsigned short PixelType
Definition: mitkLabel.h:94
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
mitk::Label::PixelType LabelValueType
Describes a two-dimensional, rectangular plane.
Abstract base class for segmentation tools.
Definition: mitkSegTool2D.h:57
void SetShowMarkerNodes(bool)
static void WriteBackSegmentationResults(const DataNode *workingNode, const std::vector< SliceInformation > &sliceList, bool writeSliceToVolume=true, bool allowUndo=true, const std::string &toolName="")
Writes all provided source slices into the data of the passed workingNode. The function does the foll...
static Image::Pointer GetAffectedImageSliceAs2DImage(const PlaneGeometry *planeGeometry, const Image *image, TimeStepType timeStep, unsigned int component=0)
Extract the slice of an image cut by given plane. The given component denotes the vector component of...
SegTool2D(const char *, const us::Module *interactorModule=nullptr)
static Image::Pointer GetAffectedImageSliceAs2DImage(const InteractionPositionEvent *positionEvent, const Image *image, unsigned int component=0)
Extract the slice of an image that the user just scribbles on. The given component denotes the vector...
DataNode * GetReferenceDataNode() const
int AddContourmarker(const PlaneGeometry *planeGeometry, unsigned int sliceIndex)
Adds a new node called Contourmarker to the datastorage which holds a mitk::PlanarFigure....
~SegTool2D() override
static void UpdateAllSurfaceInterpolations(const MultiLabelSegmentation *workingImage, TimeStepType timeStep, const PlaneGeometry *plane, bool detectIntersection)
Updates the surface interpolations by extracting the contour form the given slice for all labels that...
void WriteBackSegmentationResult(const InteractionPositionEvent *, const Image *segmentationResult)
void PushCursor(us::ModuleResource cursorResource)
void WriteBackSegmentationResult(const PlaneGeometry *planeGeometry, const Image *segmentationResult, TimeStepType timeStep)
MultiLabelSegmentation * GetWorkingData() const
mitkClassMacro(SegTool2D, Tool)
void SetEnable3DInterpolation(bool)
Enables or disables the 3D interpolation after writing back the 2D segmentation result,...
bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode) override
Filters events that cannot be handled by 2D segmentation tools.
static void WriteSliceToVolume(Image *workingImage, const PlaneGeometry *planeGeometry, const Image *slice, TimeStepType timeStep)
static bool DetermineAffectedImageSlice(const Image *image, const PlaneGeometry *plane, int &affectedDimension, int &affectedSlice)
Calculates for a given Image and PlaneGeometry, which slice of the image (in index coordinates) is me...
Image::Pointer GetAffectedWorkingSlice(const InteractionPositionEvent *) const
Extract the slice of the currently selected working image that the user just scribbles on.
static void WriteBackSegmentationResult(const DataNode *workingNode, const PlaneGeometry *planeGeometry, const Image *segmentationResult, TimeStepType timeStep, const std::string &toolName)
Writes the provided segmentation result slice into the data of the passed workingNode....
static Image::Pointer GetAffectedImageSliceAs2DImageByTimePoint(const PlaneGeometry *planeGeometry, const Image *image, TimePointType timePoint, unsigned int component=0)
void PopCursor(bool popFirstCursor=false)
void WriteBackSegmentationResults(const std::vector< SliceInformation > &sliceList, bool writeSliceToVolume=true)
static void WriteSliceToVolume(Image *workingImage, const SliceInformation &sliceInfo)
void InteractiveSegmentationBugMessage(const std::string &message) const
DataNode * GetWorkingDataNode() const
returns the segmentation node that should be modified by the tool.
virtual void OnTimePointChanged()
Image::Pointer GetAffectedReferenceSlice(const PlaneGeometry *planeGeometry, TimeStepType timeStep) const
void PopAllCursors()
Image::Pointer GetAffectedReferenceSlice(const InteractionPositionEvent *) const
Extract the slice of the currently selected reference image that the user just scribbles on.
Image * GetReferenceData() const
void Activated() override
Called when the tool gets activated.
static bool IsPositionEventInsideImageRegion(InteractionPositionEvent *positionEvent, const BaseData *data)
static void UpdateSurfaceInterpolation(const std::vector< SliceInformation > &sliceInfos, const Image *workingImage, bool detectIntersection, mitk::Label::PixelType activeLabelValue, bool silent=false)
Updates the surface interpolation by extracting the contour form the given slice.
void DisableContourMarkers()
void Deactivated() override
Called when the tool gets deactivated.
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:79
Constants for most interaction classes, due to the generic StateMachines.
Find image slices visible on a given plane.
std::size_t TimeStepType
mitk::ScalarType TimePointType
SliceInformation(const mitk::Image *aSlice, const mitk::PlaneGeometry *aPlane, mitk::TimeStepType aTimestep)
mitk::Image::ConstPointer slice