Medical Imaging Interaction Toolkit  2026.06.00
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 
89  static void UpdateAllSurfaceInterpolations(const MultiLabelSegmentation* workingImage,
90  TimeStepType timeStep,
91  const PlaneGeometry *plane,
92  bool detectIntersection);
93 
104  static Image::Pointer GetAffectedImageSliceAs2DImage(const InteractionPositionEvent* positionEvent, const Image* image, unsigned int component = 0);
105 
117  static Image::Pointer GetAffectedImageSliceAs2DImage(const PlaneGeometry* planeGeometry,
118  const Image* image,
119  TimeStepType timeStep,
120  unsigned int component = 0);
130  static Image::Pointer GetAffectedImageSliceAs2DImageByTimePoint(const PlaneGeometry* planeGeometry,
131  const Image* image,
132  TimePointType timePoint,
133  unsigned int component = 0);
134 
150  static void WriteBackSegmentationResult(const DataNode* workingNode, const PlaneGeometry* planeGeometry, const Image* segmentationResult, TimeStepType timeStep, const std::string& toolName);
151 
163  static void WriteSliceToVolume(Image* workingImage, const PlaneGeometry* planeGeometry, const Image* slice, TimeStepType timeStep);
164 
169  void SetShowMarkerNodes(bool show);
170 
176 
177  void Activated() override;
178  void Deactivated() override;
179 
180  itkSetMacro(IsTimePointChangeAware, bool);
181  itkGetMacro(IsTimePointChangeAware, bool);
182  itkBooleanMacro(IsTimePointChangeAware);
183 
189 
192 
195 
198 
199  protected:
200  SegTool2D(); // purposely hidden
201  SegTool2D(const char *, const us::Module *interactorModule = nullptr); // purposely hidden
202  ~SegTool2D() override;
203 
207  virtual void OnTimePointChanged();
208 
210  {
211  mitk::Image::ConstPointer slice;
212  const mitk::PlaneGeometry *plane = nullptr;
213  mitk::TimeStepType timestep = 0;
214  unsigned int slicePosition;
215 
216  SliceInformation() = default;
217  SliceInformation(const mitk::Image* aSlice, const mitk::PlaneGeometry* aPlane, mitk::TimeStepType aTimestep);
218  };
219 
231  static void UpdateSurfaceInterpolation(const std::vector<SliceInformation>& sliceInfos,
232  const Image* workingImage,
233  bool detectIntersection,
234  mitk::Label::PixelType activeLabelValue, bool silent = false);
235 
236 
243  bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode) override;
244 
251  Image::Pointer GetAffectedWorkingSlice(const InteractionPositionEvent *) const;
252 
261  Image::Pointer GetAffectedReferenceSlice(const PlaneGeometry* planeGeometry, TimeStepType timeStep) const;
262 
265  void WriteBackSegmentationResult(const InteractionPositionEvent *, const Image* segmentationResult);
266 
269  void WriteBackSegmentationResult(const PlaneGeometry *planeGeometry, const Image* segmentationResult, TimeStepType timeStep);
270 
273  void WriteBackSegmentationResults(const std::vector<SliceInformation> &sliceList, bool writeSliceToVolume = true);
274 
286  static void WriteBackSegmentationResults(const DataNode* workingNode, const std::vector<SliceInformation>& sliceList, bool writeSliceToVolume = true, bool allowUndo = true, const std::string& toolName = "");
287 
293 
301  static void WriteSliceToVolume(Image* workingImage, const SliceInformation &sliceInfo);
302 
308  int AddContourmarker(const PlaneGeometry* planeGeometry, unsigned int sliceIndex);
310 
311  void InteractiveSegmentationBugMessage(const std::string &message) const;
312 
315  static bool IsPositionEventInsideImageRegion(InteractionPositionEvent* positionEvent, const BaseData* data);
316 
317  BaseRenderer *m_LastEventSender = nullptr;
318  unsigned int m_LastEventSlice = 0;
319 
320  itkGetMacro(LastTimePointTriggered, TimePointType);
321 
323  void PushCursor();
324 
329  void PushCursor(us::ModuleResource cursorResource);
330 
335  void PopCursor(bool popFirstCursor = false);
336 
339 
340  private:
344  void OnTimePointChangedInternal();
345 
346  static void RemoveContourFromInterpolator(const SliceInformation& sliceInfo, MultiLabelSegmentation::LabelValueType labelValue);
347 
348  // The prefix of the contourmarkername. Suffix is a consecutive number
349  const std::string m_Contourmarkername;
350  bool m_EnableContourMarkers = true;
351  bool m_ShowMarkerNodes = false;
352  static bool m_SurfaceInterpolationEnabled;
353 
354  bool m_IsTimePointChangeAware = true;
355 
356  TimePointType m_LastTimePointTriggered = 0.;
357 
358  unsigned int m_NumPushedCursors = 0;
359  };
360 
361 } // namespace
362 
363 #endif
#define MITKSEGMENTATION_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Organizes the rendering process.
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
Base class for all interaction events in MITK.
Super class for all position-aware interaction events.
unsigned short PixelType
Pixel type used for label values (unsigned short).
Definition: mitkLabel.h:106
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
std::vector< LabelValueType > LabelValueVectorType
mitk::Label::PixelType LabelValueType
Describes the geometry of a plane object.
Abstract base class for segmentation tools.
Definition: mitkSegTool2D.h:57
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
Returns the reference data node.
void PushCursor()
Pushes the current tool cursor onto the cursor stack.
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 contours from the given slice.
void WriteBackSegmentationResult(const InteractionPositionEvent *, const Image *segmentationResult)
void PushCursor(us::ModuleResource cursorResource)
Pushes a custom cursor onto the cursor stack.
void WriteBackSegmentationResult(const PlaneGeometry *planeGeometry, const Image *segmentationResult, TimeStepType timeStep)
MultiLabelSegmentation * GetWorkingData() const
Returns the working data (multi-label segmentation image).
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)
Writes a provided slice into the passed working image.
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)
Extract the slice of an image cut by the given plane at a specified time point.
void PopCursor(bool popFirstCursor=false)
Pops the most recently pushed cursor from the stack.
void WriteBackSegmentationResults(const std::vector< SliceInformation > &sliceList, bool writeSliceToVolume=true)
static void WriteSliceToVolume(Image *workingImage, const SliceInformation &sliceInfo)
void SetShowMarkerNodes(bool show)
Sets whether contour marker nodes should be visible in the DataStorage.
void InteractiveSegmentationBugMessage(const std::string &message) const
DataNode * GetWorkingDataNode() const
Returns the segmentation node that should be modified by the tool.
virtual void OnTimePointChanged()
virtual MultiLabelSegmentation::LabelValueVectorType GetAffectedLabelValues() const
Returns the label value(s) whose pixels this tool's writeback actually modifies, so the provenance st...
Image::Pointer GetAffectedReferenceSlice(const PlaneGeometry *planeGeometry, TimeStepType timeStep) const
void PopAllCursors()
Pops all cursors from the stack, restoring the default cursor.
Image::Pointer GetAffectedReferenceSlice(const InteractionPositionEvent *) const
Extract the slice of the currently selected reference image that the user just scribbles on.
Image * GetReferenceData() const
Returns the reference image data.
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 contours from given slices.
void DisableContourMarkers()
void Deactivated() override
Called when the tool gets deactivated.
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:80
Represents a resource (text file, image, etc.) embedded in a CppMicroServices module.
Represents a CppMicroServices module.
Definition: usModule.h:70
Constants for most interaction classes, due to the generic StateMachines.
Find image slices visible on a given plane.
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
mitk::ScalarType TimePointType
Type for time point values in milliseconds (ms).
SliceInformation(const mitk::Image *aSlice, const mitk::PlaneGeometry *aPlane, mitk::TimeStepType aTimestep)
mitk::Image::ConstPointer slice