Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkPlaneGeometry.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 mitkPlaneGeometry_h
14 #define mitkPlaneGeometry_h
15 
16 #include <MitkCoreExports.h>
17 
18 #include <mitkAnatomicalPlanes.h>
19 #include <mitkBaseGeometry.h>
21 
22 #include <vnl/vnl_cross.h>
23 
24 namespace mitk
25 {
26  template <class TCoordRep, unsigned int NPointDimension>
27  class Line;
28  typedef Line<ScalarType, 3> Line3D;
29 
75  {
76  public:
78 
80  itkFactorylessNewMacro(Self);
81  itkCloneMacro(Self);
82 
91  virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const;
92 
101  virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const;
102 
109  virtual void IndexToWorld(const mitk::Vector2D &vec_units, mitk::Vector2D &vec_mm) const;
110 
117  virtual void WorldToIndex(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units) const;
118 
136  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
137  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
138  ScalarType zPosition = 0,
139  bool frontside = true,
140  bool rotated = false,
141  bool top = true);
142 
155  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
156  bool top,
157  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
158  bool frontside = true,
159  bool rotated = false);
160 
180  ScalarType height,
181  const AffineTransform3D *transform = nullptr,
182  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
183  ScalarType zPosition = 0,
184  bool frontside = true,
185  bool rotated = false,
186  bool top = true);
187 
194  ScalarType height,
195  const Vector3D &spacing,
196  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
197  ScalarType zPosition = 0,
198  bool frontside = true,
199  bool rotated = false,
200  bool top = true);
201 
215  ScalarType height,
216  const Vector3D &rightVector,
217  const Vector3D &downVector,
218  const Vector3D *spacing = nullptr);
219 
233  ScalarType height,
234  const VnlVector &rightVector,
235  const VnlVector &downVector,
236  const Vector3D *spacing = nullptr);
237 
246  virtual void InitializeStandardPlane(const Vector3D &rightVector,
247  const Vector3D &downVector,
248  const Vector3D *spacing = nullptr);
249 
258  virtual void InitializeStandardPlane(const VnlVector &rightVector,
259  const VnlVector &downVector,
260  const Vector3D *spacing = nullptr);
261 
268  virtual void InitializePlane(const Point3D &origin, const Vector3D &normal);
269 
278  void SetMatrixByVectors(const VnlVector &rightVector, const VnlVector &downVector, ScalarType thickness = 1.0);
279 
286  static bool CheckRotationMatrix(AffineTransform3D *transform, double epsilon=1e-6);
287 
297 
305 
317  virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const;
318 
327  virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox = false) const;
328 
337  ScalarType DistanceFromPlane(const Point3D &pt3d_mm) const;
338 
345  inline ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
346  {
347  ScalarType len = GetNormalVnl().two_norm();
348 
349  if (len == 0)
350  return 0;
351 
352  return (pt3d_mm - GetOrigin()) * GetNormal() / len;
353  }
354 
361  ScalarType DistanceFromPlane(const PlaneGeometry *plane) const { return fabs(SignedDistanceFromPlane(plane)); }
369  {
370  if (IsParallel(plane))
371  {
372  return SignedDistance(plane->GetOrigin());
373  }
374  return 0;
375  }
376 
383  bool IntersectionLine(const PlaneGeometry *plane, Line3D &crossline) const;
384 
391  unsigned int IntersectWithPlane2D(const PlaneGeometry *plane, Point2D &lineFrom, Point2D &lineTo) const;
392 
398  double Angle(const PlaneGeometry *plane) const;
399 
405  double Angle(const Line3D &line) const;
406 
415  bool IntersectionPoint(const Line3D &line, Point3D &intersectionPoint) const;
416 
427  bool IntersectionPointParam(const Line3D &line, double &t) const;
428 
434  bool IsParallel(const PlaneGeometry *plane) const;
435 
440  bool IsOnPlane(const Point3D &point) const;
441 
446  bool IsOnPlane(const Line3D &line) const;
447 
456  bool IsOnPlane(const PlaneGeometry *plane) const;
457 
462 
472  void ExecuteOperation(Operation *operation) override;
473 
485  virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const;
486 
496  virtual void Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const;
497 
506  virtual void SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height);
507 
514  virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const;
515 
528  virtual bool Map(const mitk::Point3D &atPt3d_mm, const mitk::Vector3D &vec3d_mm, mitk::Vector2D &vec2d_mm) const;
529 
539  virtual void Map(const mitk::Point2D &atPt2d_mm, const mitk::Vector2D &vec2d_mm, mitk::Vector3D &vec3d_mm) const;
540 
547  virtual bool Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const;
548 
559  inline ScalarType Distance(const Point3D &pt3d_mm) const { return fabs(SignedDistance(pt3d_mm)); }
570 
577 
583  bool HasReferenceGeometry() const;
584 
585  protected:
587 
589 
590  ~PlaneGeometry() override;
591 
592  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
593 
595 
596  //##Documentation
597  //## @brief PreSetSpacing
598  //##
599  //## These virtual function allows a different beahiour in subclasses.
600  //## Do implement them in every subclass of BaseGeometry. If not needed, use
601  //## {Superclass::PreSetSpacing();};
602  void PreSetSpacing(const mitk::Vector3D &aSpacing) override { Superclass::PreSetSpacing(aSpacing); };
603  //##Documentation
604  //## @brief CheckBounds
605  //##
606  //## This function is called in SetBounds. Assertions can be implemented in this function (see PlaneGeometry.cpp).
607  //## If you implement this function in a subclass, make sure, that all classes were your class inherits from
608  //## have an implementation of CheckBounds
609  //## (e.g. inheritance BaseGeometry <- A <- B. Implementation of CheckBounds in class B needs implementation in A as
610  // well!)
611  void CheckBounds(const BoundsArrayType &bounds) override;
612 
613  //##Documentation
614  //## @brief CheckIndexToWorldTransform
615  //##
616  //## This function is called in SetIndexToWorldTransform. Assertions can be implemented in this function (see
617  // PlaneGeometry.cpp).
618  //## In Subclasses of BaseGeometry, implement own conditions or call Superclass::CheckBounds(bounds);.
620 
622 
623  private:
628  virtual bool operator==(const PlaneGeometry *) const { return false; };
633  virtual bool operator!=(const PlaneGeometry *) const { return false; };
634  };
635 } // namespace mitk
636 
637 #endif
std::tuple< double, double, double > GetOrigin(const mitk::TimeGeometry *tg, mitk::TimeStepType t)
Returns the origin (x, y, z) at the given time step.
#define MITKCORE_EXPORT
Abstract base class describing the geometry of a data object.
Point3D GetOrigin() const
Get the origin of the geometry in world coordinates (mm).
BoundingBoxType::BoundsArrayType BoundsArrayType
Fixed-size array of six ScalarType values representing axis-aligned bounds [xmin,xmax,...
Describes a line in N-dimensional space.
Definition: mitkLine.h:37
Base class for all operations in the undo/redo framework.
Definition: mitkOperation.h:38
Describes the geometry of a plane object.
virtual void InitializeStandardPlane(ScalarType width, ScalarType height, const VnlVector &rightVector, const VnlVector &downVector, const Vector3D *spacing=nullptr)
Initialize plane by width and height in pixels, right-/down-vector (vnl) to describe orientation in w...
static bool CheckRotationMatrix(AffineTransform3D *transform, double epsilon=1e-6)
Check if matrix is a rotation matrix:
virtual void IndexToWorld(const mitk::Vector2D &vec_units, mitk::Vector2D &vec_mm) const
Convert 2D index coordinates of a vector to world coordinates (mm).
virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const
Convert 2D world coordinates (mm) to 2D index coordinates (units).
bool IsParallel(const PlaneGeometry *plane) const
Returns whether the plane is parallel to another plane.
ScalarType DistanceFromPlane(const PlaneGeometry *plane) const
Distance of the plane from another plane (bounding-box not considered)
void CheckIndexToWorldTransform(mitk::AffineTransform3D *transform) override
CheckIndexToWorldTransform.
void ExecuteOperation(Operation *operation) override
Execute an operation to re-orient or reposition the plane.
virtual void InitializeStandardPlane(ScalarType width, ScalarType height, const Vector3D &rightVector, const Vector3D &downVector, const Vector3D *spacing=nullptr)
Initialize plane by width and height in pixels, right-/down-vector (itk) to describe orientation in w...
virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox=false) const
Determine whether a point is above (in the normal direction of) the plane.
virtual void InitializePlane(const Point3D &origin, const Vector3D &normal)
Initialize plane by origin and normal (size is 1.0 mm in all directions, direction of right-/down-vec...
mitkClassMacro(PlaneGeometry, BaseGeometry)
double Angle(const PlaneGeometry *plane) const
Calculate the angle between two planes.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void SetMatrixByVectors(const VnlVector &rightVector, const VnlVector &downVector, ScalarType thickness=1.0)
Initialize plane by right-/down-vector.
bool IntersectionPointParam(const Line3D &line, double &t) const
Calculate line parameter of intersection point between the plane and a line.
virtual void SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height)
Set the width and height of this 2D-geometry in units by calling SetBounds. This does not change the ...
ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
Signed distance of the point from the plane (bounding-box not considered)
void PreSetSpacing(const mitk::Vector3D &aSpacing) override
PreSetSpacing.
PlaneGeometry(const PlaneGeometry &other)
bool IsOnPlane(const PlaneGeometry *plane) const
Returns whether the plane is on the plane (bounding-box not considered)
unsigned int IntersectWithPlane2D(const PlaneGeometry *plane, Point2D &lineFrom, Point2D &lineTo) const
Calculate two points where another plane intersects the border of this plane.
double Angle(const Line3D &line) const
Calculate the angle between the plane and a line.
bool HasReferenceGeometry() const
Check whether a reference geometry has been set.
ScalarType DistanceFromPlane(const Point3D &pt3d_mm) const
Unsigned distance of a point from the infinite plane.
virtual bool Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const
Project a 3D vector given in mm (vec3d_mm) onto the 2D geometry. The result is a 3D vector in mm (pro...
VnlVector GetNormalVnl() const
Get the normal vector of the plane as a VnlVector.
const BaseGeometry * GetReferenceGeometry() const
Get the geometrical frame of reference for this PlaneGeometry.
virtual void InitializeStandardPlane(ScalarType width, ScalarType height, const Vector3D &spacing, AnatomicalPlane planeorientation=AnatomicalPlane::Axial, ScalarType zPosition=0, bool frontside=true, bool rotated=false, bool top=true)
Initialize plane with orientation AnatomicalPlane (default: axial) given width, height and spacing.
virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const
Convert 2D index coordinates (units) to 2D world coordinates (mm).
ScalarType SignedDistanceFromPlane(const PlaneGeometry *plane) const
Signed distance of the plane from another plane (bounding-box not considered)
virtual bool Map(const mitk::Point3D &atPt3d_mm, const mitk::Vector3D &vec3d_mm, mitk::Vector2D &vec2d_mm) const
Project a 3D vector given in mm (vec3d_mm) onto the 2D geometry. The result is a 2D vector in mm (vec...
bool IsOnPlane(const Point3D &point) const
Returns whether the point is on the plane (bounding-box not considered)
virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 3D point in mm (projec...
virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const
Compute the signed distance of a point from the plane.
virtual void WorldToIndex(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units) const
Convert world coordinates (mm) of a 2D vector to continuous index coordinates.
void CheckBounds(const BoundsArrayType &bounds) override
CheckBounds.
virtual void InitializeStandardPlane(const Vector3D &rightVector, const Vector3D &downVector, const Vector3D *spacing=nullptr)
Initialize plane by right-/down-vector (itk) and spacing (default: 1.0 mm in all directions).
Point3D ProjectPointOntoPlane(const Point3D &pt) const
Returns the lot from the point to the plane.
virtual void InitializeStandardPlane(const VnlVector &rightVector, const VnlVector &downVector, const Vector3D *spacing=nullptr)
Initialize plane by right-/down-vector (vnl) and spacing (default: 1.0 mm in all directions).
virtual void InitializeStandardPlane(const BaseGeometry *geometry3D, AnatomicalPlane planeorientation=AnatomicalPlane::Axial, ScalarType zPosition=0, bool frontside=true, bool rotated=false, bool top=true)
Initialize a plane with orientation AnatomicalPlane (default: axial) with respect to BaseGeometry (de...
void SetReferenceGeometry(const mitk::BaseGeometry *geometry)
Set the geometrical frame of reference in which this PlaneGeometry is placed.
const mitk::BaseGeometry * m_ReferenceGeometry
~PlaneGeometry() override
virtual void InitializeStandardPlane(ScalarType width, ScalarType height, const AffineTransform3D *transform=nullptr, AnatomicalPlane planeorientation=AnatomicalPlane::Axial, ScalarType zPosition=0, bool frontside=true, bool rotated=false, bool top=true)
Initialize a plane with orientation AnatomicalPlane (default: axial) with respect to transform (defau...
virtual void Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const
Converts a 2D point given in mm (pt2d_mm) relative to the upper-left corner of the geometry into the ...
ScalarType Distance(const Point3D &pt3d_mm) const
Unsigned distance of a point from the geometry.
virtual void Map(const mitk::Point2D &atPt2d_mm, const mitk::Vector2D &vec2d_mm, mitk::Vector3D &vec3d_mm) const
Converts a 2D vector given in mm (vec2d_mm) relative to the upper-left corner of the geometry into th...
bool IntersectionLine(const PlaneGeometry *plane, Line3D &crossline) const
Calculate the intersecting line of two planes.
bool IntersectionPoint(const Line3D &line, Point3D &intersectionPoint) const
Calculate intersection point between the plane and a line.
virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 2D point in mm (pt2d_m...
Vector3D GetNormal() const
Get the normal vector of the plane.
virtual void InitializeStandardPlane(const BaseGeometry *geometry3D, bool top, AnatomicalPlane planeorientation=AnatomicalPlane::Axial, bool frontside=true, bool rotated=false)
Initialize a plane with orientation AnatomicalPlane (default: axial) with respect to BaseGeometry (de...
bool IsOnPlane(const Line3D &line) const
Returns whether the line is on the plane (bounding-box not considered)
Find image slices visible on a given plane.
Line< ScalarType, 3 > Line3D
Definition: mitkLine.h:490
itk::ScalableAffineTransform< ScalarType, 3 > AffineTransform3D
3D affine transform type used throughout MITK.
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
AnatomicalPlane
Enumeration of standard anatomical image planes.
@ Axial
Transverse plane (top-down view, perpendicular to body's long axis).
vnl_vector< ScalarType > VnlVector
Definition: mitkVector.h:176
double ScalarType
Scalar type used throughout MITK for geometric computations.