Medical Imaging Interaction Toolkit  2021.02.99-540f9ce6
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 
52 #ifndef PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C
53 #define PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C
54 
55 #include "mitkBaseGeometry.h"
57 #include <MitkCoreExports.h>
58 
59 #include <vnl/vnl_cross.h>
60 
61 namespace mitk
62 {
63  template <class TCoordRep, unsigned int NPointDimension>
64  class Line;
65  typedef Line<ScalarType, 3> Line3D;
66 
70 
77  {
78  public:
80 
82  itkFactorylessNewMacro(Self);
83  itkCloneMacro(Self);
84 
88  Frontal, // also known as "Coronal" in mitk.
89  None // This defines the PlaneGeometry for the 3D renderWindow which
90  // curiously also needs a PlaneGeometry. This should be reconsidered some time.
91  };
92 
93  virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const;
94 
95  virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const;
96 
97  //##Documentation
98  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
99  //## \a vec_units to world coordinates (in mm)
100  //## @deprecated First parameter (Point2D) is not used. If possible, please use void IndexToWorld(const
101  // mitk::Vector2D& vec_units, mitk::Vector2D& vec_mm) const.
102  //## For further information about coordinates types, please see the Geometry documentation
103  virtual void IndexToWorld(const mitk::Point2D &atPt2d_untis,
104  const mitk::Vector2D &vec_units,
105  mitk::Vector2D &vec_mm) const;
106 
107  //##Documentation
108  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
109  //## \a vec_units to world coordinates (in mm)
110  //## For further information about coordinates types, please see the Geometry documentation
111  virtual void IndexToWorld(const mitk::Vector2D &vec_units, mitk::Vector2D &vec_mm) const;
112 
113  //##Documentation
114  //## @brief Convert world coordinates (in mm) of a \em vector
115  //## \a vec_mm to (continuous!) index coordinates.
116  //## @deprecated First parameter (Point2D) is not used. If possible, please use void WorldToIndex(const
117  // mitk::Vector2D& vec_mm, mitk::Vector2D& vec_units) const.
118  //## For further information about coordinates types, please see the Geometry documentation
119  virtual void WorldToIndex(const mitk::Point2D &atPt2d_mm,
120  const mitk::Vector2D &vec_mm,
121  mitk::Vector2D &vec_units) const;
122 
123  //##Documentation
124  //## @brief Convert world coordinates (in mm) of a \em vector
125  //## \a vec_mm to (continuous!) index coordinates.
126  //## For further information about coordinates types, please see the Geometry documentation
127  virtual void WorldToIndex(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units) const;
128 
146  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
147  PlaneOrientation planeorientation = Axial,
148  ScalarType zPosition = 0,
149  bool frontside = true,
150  bool rotated = false,
151  bool top = true);
152 
165  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
166  bool top,
167  PlaneOrientation planeorientation = Axial,
168  bool frontside = true,
169  bool rotated = false);
170 
189  virtual void InitializeStandardPlane(ScalarType width,
190  ScalarType height,
191  const AffineTransform3D *transform = nullptr,
192  PlaneOrientation planeorientation = Axial,
193  ScalarType zPosition = 0,
194  bool frontside = true,
195  bool rotated = false,
196  bool top = true);
197 
203  virtual void InitializeStandardPlane(ScalarType width,
204  ScalarType height,
205  const Vector3D &spacing,
206  PlaneOrientation planeorientation = Axial,
207  ScalarType zPosition = 0,
208  bool frontside = true,
209  bool rotated = false,
210  bool top = true);
211 
224  virtual void InitializeStandardPlane(ScalarType width,
225  ScalarType height,
226  const Vector3D &rightVector,
227  const Vector3D &downVector,
228  const Vector3D *spacing = nullptr);
229 
242  virtual void InitializeStandardPlane(ScalarType width,
243  ScalarType height,
244  const VnlVector &rightVector,
245  const VnlVector &downVector,
246  const Vector3D *spacing = nullptr);
247 
256  virtual void InitializeStandardPlane(const Vector3D &rightVector,
257  const Vector3D &downVector,
258  const Vector3D *spacing = nullptr);
259 
268  virtual void InitializeStandardPlane(const VnlVector &rightVector,
269  const VnlVector &downVector,
270  const Vector3D *spacing = nullptr);
271 
278  virtual void InitializePlane(const Point3D &origin, const Vector3D &normal);
279 
288  void SetMatrixByVectors(const VnlVector &rightVector, const VnlVector &downVector, ScalarType thickness = 1.0);
289 
296  static bool CheckRotationMatrix(AffineTransform3D *transform, double epsilon=1e-6);
297 
302  Vector3D GetNormal() const;
303 
308  VnlVector GetNormalVnl() const;
309 
310  virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const;
311 
316  virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox = false) const;
317 
323  ScalarType DistanceFromPlane(const Point3D &pt3d_mm) const;
324 
331  inline ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
332  {
333  ScalarType len = GetNormalVnl().two_norm();
334 
335  if (len == 0)
336  return 0;
337 
338  return (pt3d_mm - GetOrigin()) * GetNormal() / len;
339  }
340 
347  ScalarType DistanceFromPlane(const PlaneGeometry *plane) const { return fabs(SignedDistanceFromPlane(plane)); }
355  {
356  if (IsParallel(plane))
357  {
358  return SignedDistance(plane->GetOrigin());
359  }
360  return 0;
361  }
362 
369  bool IntersectionLine(const PlaneGeometry *plane, Line3D &crossline) const;
370 
377  unsigned int IntersectWithPlane2D(const PlaneGeometry *plane, Point2D &lineFrom, Point2D &lineTo) const;
378 
384  double Angle(const PlaneGeometry *plane) const;
385 
391  double Angle(const Line3D &line) const;
392 
401  bool IntersectionPoint(const Line3D &line, Point3D &intersectionPoint) const;
402 
413  bool IntersectionPointParam(const Line3D &line, double &t) const;
414 
420  bool IsParallel(const PlaneGeometry *plane) const;
421 
426  bool IsOnPlane(const Point3D &point) const;
427 
432  bool IsOnPlane(const Line3D &line) const;
433 
442  bool IsOnPlane(const PlaneGeometry *plane) const;
443 
447  Point3D ProjectPointOntoPlane(const Point3D &pt) const;
448 
449  itk::LightObject::Pointer InternalClone() const override;
450 
452  void ExecuteOperation(Operation *operation) override;
453 
465  virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const;
466 
476  virtual void Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const;
477 
486  virtual void SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height);
487 
494  virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const;
495 
508  virtual bool Map(const mitk::Point3D &atPt3d_mm, const mitk::Vector3D &vec3d_mm, mitk::Vector2D &vec2d_mm) const;
509 
519  virtual void Map(const mitk::Point2D &atPt2d_mm, const mitk::Vector2D &vec2d_mm, mitk::Vector3D &vec3d_mm) const;
520 
529  virtual bool Project(const mitk::Point3D &atPt3d_mm,
530  const mitk::Vector3D &vec3d_mm,
531  mitk::Vector3D &projectedVec3d_mm) const;
532 
539  virtual bool Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const;
540 
546  inline ScalarType Distance(const Point3D &pt3d_mm) const { return fabs(SignedDistance(pt3d_mm)); }
554  void SetReferenceGeometry(const mitk::BaseGeometry *geometry);
555 
559  const BaseGeometry *GetReferenceGeometry() const;
560  bool HasReferenceGeometry() const;
561 
562  static std::vector< int > CalculateDominantAxes(mitk::AffineTransform3D::MatrixType::InternalMatrixType& rotation_matrix);
563 
564  protected:
565  PlaneGeometry();
566 
567  PlaneGeometry(const PlaneGeometry &other);
568 
569  ~PlaneGeometry() override;
570 
571  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
572 
574 
575  //##Documentation
576  //## @brief PreSetSpacing
577  //##
578  //## These virtual function allows a different beahiour in subclasses.
579  //## Do implement them in every subclass of BaseGeometry. If not needed, use
580  //## {Superclass::PreSetSpacing();};
581  void PreSetSpacing(const mitk::Vector3D &aSpacing) override { Superclass::PreSetSpacing(aSpacing); };
582  //##Documentation
583  //## @brief CheckBounds
584  //##
585  //## This function is called in SetBounds. Assertions can be implemented in this function (see PlaneGeometry.cpp).
586  //## If you implement this function in a subclass, make sure, that all classes were your class inherits from
587  //## have an implementation of CheckBounds
588  //## (e.g. inheritance BaseGeometry <- A <- B. Implementation of CheckBounds in class B needs implementation in A as
589  // well!)
590  void CheckBounds(const BoundsArrayType &bounds) override;
591 
592  //##Documentation
593  //## @brief CheckIndexToWorldTransform
594  //##
595  //## This function is called in SetIndexToWorldTransform. Assertions can be implemented in this function (see
596  // PlaneGeometry.cpp).
597  //## In Subclasses of BaseGeometry, implement own conditions or call Superclass::CheckBounds(bounds);.
598  void CheckIndexToWorldTransform(mitk::AffineTransform3D *transform) override;
599 
600  private:
605  virtual bool operator==(const PlaneGeometry *) const { return false; };
610  virtual bool operator!=(const PlaneGeometry *) const { return false; };
611  };
612 } // namespace mitk
613 
614 #endif /* PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C */
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
ScalarType DistanceFromPlane(const PlaneGeometry *plane) const
Distance of the plane from another plane (bounding-box not considered)
#define MITKCORE_EXPORT
BoundingBoxType::BoundsArrayType BoundsArrayType
Base class of all Operation-classes.
Definition: mitkOperation.h:29
vnl_vector< ScalarType > VnlVector
Definition: mitkVector.h:141
double ScalarType
void PreSetSpacing(const mitk::Vector3D &aSpacing) override
PreSetSpacing.
Line< ScalarType, 3 > Line3D
Definition: mitkLine.h:409
DataCollection - Class to facilitate loading/accessing structured data.
const mitk::BaseGeometry * m_ReferenceGeometry
#define DEPRECATED(func)
Definition: mitkCommon.h:179
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
ScalarType SignedDistanceFromPlane(const PlaneGeometry *plane) const
Signed distance of the plane from another plane (bounding-box not considered)
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
Signed distance of the point from the plane (bounding-box not considered)
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
ScalarType Distance(const Point3D &pt3d_mm) const
Distance of the point from the geometry (bounding-box not considered)
Describes a two-dimensional, rectangular plane.
BaseGeometry Describes the geometry of a data object.