Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
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) itkCloneMacro(Self)
83 
87  Frontal, // also known as "Coronal" in mitk.
88  None // This defines the PlaneGeometry for the 3D renderWindow which
89  // curiously also needs a PlaneGeometry. This should be reconsidered some time.
90  };
91 
92  virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const;
93 
94  virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const;
95 
96  //##Documentation
97  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
98  //## \a vec_units to world coordinates (in mm)
99  //## @deprecated First parameter (Point2D) is not used. If possible, please use void IndexToWorld(const
100  // mitk::Vector2D& vec_units, mitk::Vector2D& vec_mm) const.
101  //## For further information about coordinates types, please see the Geometry documentation
102  virtual void IndexToWorld(const mitk::Point2D &atPt2d_untis,
103  const mitk::Vector2D &vec_units,
104  mitk::Vector2D &vec_mm) const;
105 
106  //##Documentation
107  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
108  //## \a vec_units to world coordinates (in mm)
109  //## For further information about coordinates types, please see the Geometry documentation
110  virtual void IndexToWorld(const mitk::Vector2D &vec_units, mitk::Vector2D &vec_mm) const;
111 
112  //##Documentation
113  //## @brief Convert world coordinates (in mm) of a \em vector
114  //## \a vec_mm to (continuous!) index coordinates.
115  //## @deprecated First parameter (Point2D) is not used. If possible, please use void WorldToIndex(const
116  // mitk::Vector2D& vec_mm, mitk::Vector2D& vec_units) const.
117  //## For further information about coordinates types, please see the Geometry documentation
118  virtual void WorldToIndex(const mitk::Point2D &atPt2d_mm,
119  const mitk::Vector2D &vec_mm,
120  mitk::Vector2D &vec_units) const;
121 
122  //##Documentation
123  //## @brief Convert world coordinates (in mm) of a \em vector
124  //## \a vec_mm to (continuous!) index coordinates.
125  //## For further information about coordinates types, please see the Geometry documentation
126  virtual void WorldToIndex(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units) const;
127 
145  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
146  PlaneOrientation planeorientation = Axial,
147  ScalarType zPosition = 0,
148  bool frontside = true,
149  bool rotated = false,
150  bool top = true);
151 
160  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
161  bool top,
162  PlaneOrientation planeorientation = Axial,
163  bool frontside = true,
164  bool rotated = false);
165 
184  virtual void InitializeStandardPlane(ScalarType width,
185  ScalarType height,
186  const AffineTransform3D *transform = nullptr,
187  PlaneOrientation planeorientation = Axial,
188  ScalarType zPosition = 0,
189  bool frontside = true,
190  bool rotated = false,
191  bool top = true);
192 
198  virtual void InitializeStandardPlane(ScalarType width,
199  ScalarType height,
200  const Vector3D &spacing,
201  PlaneOrientation planeorientation = Axial,
202  ScalarType zPosition = 0,
203  bool frontside = true,
204  bool rotated = false,
205  bool top = true);
206 
219  virtual void InitializeStandardPlane(ScalarType width,
220  ScalarType height,
221  const Vector3D &rightVector,
222  const Vector3D &downVector,
223  const Vector3D *spacing = nullptr);
224 
237  virtual void InitializeStandardPlane(ScalarType width,
238  ScalarType height,
239  const VnlVector &rightVector,
240  const VnlVector &downVector,
241  const Vector3D *spacing = nullptr);
242 
251  virtual void InitializeStandardPlane(const Vector3D &rightVector,
252  const Vector3D &downVector,
253  const Vector3D *spacing = nullptr);
254 
263  virtual void InitializeStandardPlane(const VnlVector &rightVector,
264  const VnlVector &downVector,
265  const Vector3D *spacing = nullptr);
266 
273  virtual void InitializePlane(const Point3D &origin, const Vector3D &normal);
274 
283  void SetMatrixByVectors(const VnlVector &rightVector, const VnlVector &downVector, ScalarType thickness = 1.0);
284 
291  static bool CheckRotationMatrix(AffineTransform3D *transform, double epsilon=mitk::eps);
292 
297  Vector3D GetNormal() const;
298 
303  VnlVector GetNormalVnl() const;
304 
305  virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const;
306 
311  virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox = false) const;
312 
318  ScalarType DistanceFromPlane(const Point3D &pt3d_mm) const;
319 
326  inline ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
327  {
328  ScalarType len = GetNormalVnl().two_norm();
329 
330  if (len == 0)
331  return 0;
332 
333  return (pt3d_mm - GetOrigin()) * GetNormal() / len;
334  }
335 
342  ScalarType DistanceFromPlane(const PlaneGeometry *plane) const { return fabs(SignedDistanceFromPlane(plane)); }
350  {
351  if (IsParallel(plane))
352  {
353  return SignedDistance(plane->GetOrigin());
354  }
355  return 0;
356  }
357 
364  bool IntersectionLine(const PlaneGeometry *plane, Line3D &crossline) const;
365 
372  unsigned int IntersectWithPlane2D(const PlaneGeometry *plane, Point2D &lineFrom, Point2D &lineTo) const;
373 
379  double Angle(const PlaneGeometry *plane) const;
380 
386  double Angle(const Line3D &line) const;
387 
395  bool IntersectionPoint(const Line3D &line, Point3D &intersectionPoint) const;
396 
406  bool IntersectionPointParam(const Line3D &line, double &t) const;
407 
413  bool IsParallel(const PlaneGeometry *plane) const;
414 
419  bool IsOnPlane(const Point3D &point) const;
420 
425  bool IsOnPlane(const Line3D &line) const;
426 
435  bool IsOnPlane(const PlaneGeometry *plane) const;
436 
440  Point3D ProjectPointOntoPlane(const Point3D &pt) const;
441 
442  itk::LightObject::Pointer InternalClone() const override;
443 
445  void ExecuteOperation(Operation *operation) override;
446 
458  virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const;
459 
469  virtual void Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const;
470 
479  virtual void SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height);
480 
487  virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const;
488 
501  virtual bool Map(const mitk::Point3D &atPt3d_mm, const mitk::Vector3D &vec3d_mm, mitk::Vector2D &vec2d_mm) const;
502 
512  virtual void Map(const mitk::Point2D &atPt2d_mm, const mitk::Vector2D &vec2d_mm, mitk::Vector3D &vec3d_mm) const;
513 
522  virtual bool Project(const mitk::Point3D &atPt3d_mm,
523  const mitk::Vector3D &vec3d_mm,
524  mitk::Vector3D &projectedVec3d_mm) const;
525 
532  virtual bool Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const;
533 
539  inline ScalarType Distance(const Point3D &pt3d_mm) const { return fabs(SignedDistance(pt3d_mm)); }
547  void SetReferenceGeometry(const mitk::BaseGeometry *geometry);
548 
552  const BaseGeometry *GetReferenceGeometry() const;
553  bool HasReferenceGeometry() const;
554 
555  static std::vector< int > CalculateDominantAxes(mitk::AffineTransform3D::MatrixType::InternalMatrixType& rotation_matrix);
556 
557  protected:
558  PlaneGeometry();
559 
560  PlaneGeometry(const PlaneGeometry &other);
561 
562  ~PlaneGeometry() override;
563 
564  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
565 
567 
568  //##Documentation
569  //## @brief PreSetSpacing
570  //##
571  //## These virtual function allows a different beahiour in subclasses.
572  //## Do implement them in every subclass of BaseGeometry. If not needed, use
573  //## {Superclass::PreSetSpacing();};
574  void PreSetSpacing(const mitk::Vector3D &aSpacing) override { Superclass::PreSetSpacing(aSpacing); };
575  //##Documentation
576  //## @brief CheckBounds
577  //##
578  //## This function is called in SetBounds. Assertions can be implemented in this function (see PlaneGeometry.cpp).
579  //## If you implement this function in a subclass, make sure, that all classes were your class inherits from
580  //## have an implementation of CheckBounds
581  //## (e.g. inheritance BaseGeometry <- A <- B. Implementation of CheckBounds in class B needs implementation in A as
582  // well!)
583  void CheckBounds(const BoundsArrayType &bounds) override;
584 
585  //##Documentation
586  //## @brief CheckIndexToWorldTransform
587  //##
588  //## This function is called in SetIndexToWorldTransform. Assertions can be implemented in this function (see
589  // PlaneGeometry.cpp).
590  //## In Subclasses of BaseGeometry, implement own conditions or call Superclass::CheckBounds(bounds);.
591  void CheckIndexToWorldTransform(mitk::AffineTransform3D *transform) override;
592 
593  private:
598  virtual bool operator==(const PlaneGeometry *) const { return false; };
603  virtual bool operator!=(const PlaneGeometry *) const { return false; };
604  };
605 } // namespace mitk
606 
607 #endif /* PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C */
ScalarType DistanceFromPlane(const PlaneGeometry *plane) const
Distance of the plane from another plane (bounding-box not considered)
static char * line
Definition: svm.cpp:2870
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
#define MITKCORE_EXPORT
BoundingBoxType::BoundsArrayType BoundsArrayType
Base class of all Operation-classes.
Definition: mitkOperation.h:29
vnl_vector< ScalarType > VnlVector
Definition: mitkVector.h:134
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.
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
const mitk::BaseGeometry * m_ReferenceGeometry
#define DEPRECATED(func)
Definition: mitkCommon.h:179
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)
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
MITKCORE_EXPORT const ScalarType eps
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.