Medical Imaging Interaction Toolkit  2023.12.99-b826bd4b
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 
72 
79  {
80  public:
82 
84  itkFactorylessNewMacro(Self);
85  itkCloneMacro(Self);
86 
87  virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const;
88 
89  virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const;
90 
91  //##Documentation
92  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
93  //## \a vec_units to world coordinates (in mm)
94  //## @deprecated First parameter (Point2D) is not used. If possible, please use void IndexToWorld(const
95  // mitk::Vector2D& vec_units, mitk::Vector2D& vec_mm) const.
96  //## For further information about coordinates types, please see the Geometry documentation
97  virtual void IndexToWorld(const mitk::Point2D &atPt2d_untis,
98  const mitk::Vector2D &vec_units,
99  mitk::Vector2D &vec_mm) const;
100 
101  //##Documentation
102  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
103  //## \a vec_units to world coordinates (in mm)
104  //## For further information about coordinates types, please see the Geometry documentation
105  virtual void IndexToWorld(const mitk::Vector2D &vec_units, mitk::Vector2D &vec_mm) const;
106 
107  //##Documentation
108  //## @brief Convert world coordinates (in mm) of a \em vector
109  //## \a vec_mm to (continuous!) index coordinates.
110  //## @deprecated First parameter (Point2D) is not used. If possible, please use void WorldToIndex(const
111  // mitk::Vector2D& vec_mm, mitk::Vector2D& vec_units) const.
112  //## For further information about coordinates types, please see the Geometry documentation
113  virtual void WorldToIndex(const mitk::Point2D &atPt2d_mm,
114  const mitk::Vector2D &vec_mm,
115  mitk::Vector2D &vec_units) const;
116 
117  //##Documentation
118  //## @brief Convert world coordinates (in mm) of a \em vector
119  //## \a vec_mm to (continuous!) index coordinates.
120  //## For further information about coordinates types, please see the Geometry documentation
121  virtual void WorldToIndex(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units) const;
122 
140  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
141  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
142  ScalarType zPosition = 0,
143  bool frontside = true,
144  bool rotated = false,
145  bool top = true);
146 
159  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
160  bool top,
161  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
162  bool frontside = true,
163  bool rotated = false);
164 
183  virtual void InitializeStandardPlane(ScalarType width,
184  ScalarType height,
185  const AffineTransform3D *transform = nullptr,
186  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
187  ScalarType zPosition = 0,
188  bool frontside = true,
189  bool rotated = false,
190  bool top = true);
191 
197  virtual void InitializeStandardPlane(ScalarType width,
198  ScalarType height,
199  const Vector3D &spacing,
200  AnatomicalPlane planeorientation = AnatomicalPlane::Axial,
201  ScalarType zPosition = 0,
202  bool frontside = true,
203  bool rotated = false,
204  bool top = true);
205 
218  virtual void InitializeStandardPlane(ScalarType width,
219  ScalarType height,
220  const Vector3D &rightVector,
221  const Vector3D &downVector,
222  const Vector3D *spacing = nullptr);
223 
236  virtual void InitializeStandardPlane(ScalarType width,
237  ScalarType height,
238  const VnlVector &rightVector,
239  const VnlVector &downVector,
240  const Vector3D *spacing = nullptr);
241 
250  virtual void InitializeStandardPlane(const Vector3D &rightVector,
251  const Vector3D &downVector,
252  const Vector3D *spacing = nullptr);
253 
262  virtual void InitializeStandardPlane(const VnlVector &rightVector,
263  const VnlVector &downVector,
264  const Vector3D *spacing = nullptr);
265 
272  virtual void InitializePlane(const Point3D &origin, const Vector3D &normal);
273 
282  void SetMatrixByVectors(const VnlVector &rightVector, const VnlVector &downVector, ScalarType thickness = 1.0);
283 
290  static bool CheckRotationMatrix(AffineTransform3D *transform, double epsilon=1e-6);
291 
296  Vector3D GetNormal() const;
297 
302  VnlVector GetNormalVnl() const;
303 
304  virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const;
305 
310  virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox = false) const;
311 
317  ScalarType DistanceFromPlane(const Point3D &pt3d_mm) const;
318 
325  inline ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
326  {
327  ScalarType len = GetNormalVnl().two_norm();
328 
329  if (len == 0)
330  return 0;
331 
332  return (pt3d_mm - GetOrigin()) * GetNormal() / len;
333  }
334 
341  ScalarType DistanceFromPlane(const PlaneGeometry *plane) const { return fabs(SignedDistanceFromPlane(plane)); }
349  {
350  if (IsParallel(plane))
351  {
352  return SignedDistance(plane->GetOrigin());
353  }
354  return 0;
355  }
356 
363  bool IntersectionLine(const PlaneGeometry *plane, Line3D &crossline) const;
364 
371  unsigned int IntersectWithPlane2D(const PlaneGeometry *plane, Point2D &lineFrom, Point2D &lineTo) const;
372 
378  double Angle(const PlaneGeometry *plane) const;
379 
385  double Angle(const Line3D &line) const;
386 
395  bool IntersectionPoint(const Line3D &line, Point3D &intersectionPoint) const;
396 
407  bool IntersectionPointParam(const Line3D &line, double &t) const;
408 
414  bool IsParallel(const PlaneGeometry *plane) const;
415 
420  bool IsOnPlane(const Point3D &point) const;
421 
426  bool IsOnPlane(const Line3D &line) const;
427 
436  bool IsOnPlane(const PlaneGeometry *plane) const;
437 
441  Point3D ProjectPointOntoPlane(const Point3D &pt) const;
442 
443  itk::LightObject::Pointer InternalClone() const override;
444 
446  void ExecuteOperation(Operation *operation) override;
447 
459  virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const;
460 
470  virtual void Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const;
471 
480  virtual void SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height);
481 
488  virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const;
489 
502  virtual bool Map(const mitk::Point3D &atPt3d_mm, const mitk::Vector3D &vec3d_mm, mitk::Vector2D &vec2d_mm) const;
503 
513  virtual void Map(const mitk::Point2D &atPt2d_mm, const mitk::Vector2D &vec2d_mm, mitk::Vector3D &vec3d_mm) const;
514 
523  virtual bool Project(const mitk::Point3D &atPt3d_mm,
524  const mitk::Vector3D &vec3d_mm,
525  mitk::Vector3D &projectedVec3d_mm) const;
526 
533  virtual bool Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const;
534 
540  inline ScalarType Distance(const Point3D &pt3d_mm) const { return fabs(SignedDistance(pt3d_mm)); }
548  void SetReferenceGeometry(const mitk::BaseGeometry *geometry);
549 
553  const BaseGeometry *GetReferenceGeometry() const;
554  bool HasReferenceGeometry() const;
555 
556  protected:
557  PlaneGeometry();
558 
559  PlaneGeometry(const PlaneGeometry &other);
560 
561  ~PlaneGeometry() override;
562 
563  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
564 
566 
567  //##Documentation
568  //## @brief PreSetSpacing
569  //##
570  //## These virtual function allows a different beahiour in subclasses.
571  //## Do implement them in every subclass of BaseGeometry. If not needed, use
572  //## {Superclass::PreSetSpacing();};
573  void PreSetSpacing(const mitk::Vector3D &aSpacing) override { Superclass::PreSetSpacing(aSpacing); };
574  //##Documentation
575  //## @brief CheckBounds
576  //##
577  //## This function is called in SetBounds. Assertions can be implemented in this function (see PlaneGeometry.cpp).
578  //## If you implement this function in a subclass, make sure, that all classes were your class inherits from
579  //## have an implementation of CheckBounds
580  //## (e.g. inheritance BaseGeometry <- A <- B. Implementation of CheckBounds in class B needs implementation in A as
581  // well!)
582  void CheckBounds(const BoundsArrayType &bounds) override;
583 
584  //##Documentation
585  //## @brief CheckIndexToWorldTransform
586  //##
587  //## This function is called in SetIndexToWorldTransform. Assertions can be implemented in this function (see
588  // PlaneGeometry.cpp).
589  //## In Subclasses of BaseGeometry, implement own conditions or call Superclass::CheckBounds(bounds);.
590  void CheckIndexToWorldTransform(mitk::AffineTransform3D *transform) override;
591 
592  private:
597  virtual bool operator==(const PlaneGeometry *) const { return false; };
602  virtual bool operator!=(const PlaneGeometry *) const { return false; };
603  };
604 } // namespace mitk
605 
606 #endif
mitk::PlaneGeometry::Distance
ScalarType Distance(const Point3D &pt3d_mm) const
Distance of the point from the geometry (bounding-box not considered)
Definition: mitkPlaneGeometry.h:540
mitk::PlaneGeometry
Describes a two-dimensional, rectangular plane.
Definition: mitkPlaneGeometry.h:78
mitkAnatomicalPlanes.h
mitk::Operation
Base class of all Operation-classes.
Definition: mitkOperation.h:29
mitk::BaseGeometry::GetOrigin
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
mitk::PlaneGeometry::m_ReferenceGeometry
const mitk::BaseGeometry * m_ReferenceGeometry
Definition: mitkPlaneGeometry.h:565
mitkRestorePlanePositionOperation.h
DEPRECATED
#define DEPRECATED(func)
Definition: mitkCommon.h:175
mitk::PlaneGeometry::SignedDistanceFromPlane
ScalarType SignedDistanceFromPlane(const PlaneGeometry *plane) const
Signed distance of the plane from another plane (bounding-box not considered)
Definition: mitkPlaneGeometry.h:348
mitk::AffineTransform3D
itk::ScalableAffineTransform< ScalarType, 3 > AffineTransform3D
Definition: mitkAffineTransform3D.h:21
mitk::VnlVector
vnl_vector< ScalarType > VnlVector
Definition: mitkVector.h:159
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::PlaneGeometry::DistanceFromPlane
ScalarType DistanceFromPlane(const PlaneGeometry *plane) const
Distance of the plane from another plane (bounding-box not considered)
Definition: mitkPlaneGeometry.h:341
mitk::operator!=
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
mitk::Line
Describes a line.
Definition: mitkLine.h:28
mitk::AnatomicalPlane::Axial
@ Axial
mitk::operator==
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
mitk::AnatomicalPlane
AnatomicalPlane
Definition: mitkAnatomicalPlanes.h:18
mitk::Vector< ScalarType, 2 >
MitkCoreExports.h
mitk::BaseGeometry
BaseGeometry Describes the geometry of a data object.
Definition: mitkBaseGeometry.h:94
mitk::Point< ScalarType, 2 >
mitk::PlaneGeometry::SignedDistanceFromPlane
ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
Signed distance of the point from the plane (bounding-box not considered)
Definition: mitkPlaneGeometry.h:325
mitk::Line3D
Line< ScalarType, 3 > Line3D
Definition: mitkLine.h:409
mitkBaseGeometry.h
mitk::PlaneGeometry::PreSetSpacing
void PreSetSpacing(const mitk::Vector3D &aSpacing) override
PreSetSpacing.
Definition: mitkPlaneGeometry.h:573
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::ScalarType
double ScalarType
Definition: mitkNumericConstants.h:20