Medical Imaging Interaction Toolkit  2018.4.99-b5518f0d
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 
161  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
162  bool top,
163  PlaneOrientation planeorientation = Axial,
164  bool frontside = true,
165  bool rotated = false);
166 
185  virtual void InitializeStandardPlane(ScalarType width,
186  ScalarType height,
187  const AffineTransform3D *transform = nullptr,
188  PlaneOrientation planeorientation = Axial,
189  ScalarType zPosition = 0,
190  bool frontside = true,
191  bool rotated = false,
192  bool top = true);
193 
199  virtual void InitializeStandardPlane(ScalarType width,
200  ScalarType height,
201  const Vector3D &spacing,
202  PlaneOrientation planeorientation = Axial,
203  ScalarType zPosition = 0,
204  bool frontside = true,
205  bool rotated = false,
206  bool top = true);
207 
220  virtual void InitializeStandardPlane(ScalarType width,
221  ScalarType height,
222  const Vector3D &rightVector,
223  const Vector3D &downVector,
224  const Vector3D *spacing = nullptr);
225 
238  virtual void InitializeStandardPlane(ScalarType width,
239  ScalarType height,
240  const VnlVector &rightVector,
241  const VnlVector &downVector,
242  const Vector3D *spacing = nullptr);
243 
252  virtual void InitializeStandardPlane(const Vector3D &rightVector,
253  const Vector3D &downVector,
254  const Vector3D *spacing = nullptr);
255 
264  virtual void InitializeStandardPlane(const VnlVector &rightVector,
265  const VnlVector &downVector,
266  const Vector3D *spacing = nullptr);
267 
274  virtual void InitializePlane(const Point3D &origin, const Vector3D &normal);
275 
284  void SetMatrixByVectors(const VnlVector &rightVector, const VnlVector &downVector, ScalarType thickness = 1.0);
285 
292  static bool CheckRotationMatrix(AffineTransform3D *transform, double epsilon=mitk::eps);
293 
298  Vector3D GetNormal() const;
299 
304  VnlVector GetNormalVnl() const;
305 
306  virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const;
307 
312  virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox = false) const;
313 
319  ScalarType DistanceFromPlane(const Point3D &pt3d_mm) const;
320 
327  inline ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
328  {
329  ScalarType len = GetNormalVnl().two_norm();
330 
331  if (len == 0)
332  return 0;
333 
334  return (pt3d_mm - GetOrigin()) * GetNormal() / len;
335  }
336 
343  ScalarType DistanceFromPlane(const PlaneGeometry *plane) const { return fabs(SignedDistanceFromPlane(plane)); }
351  {
352  if (IsParallel(plane))
353  {
354  return SignedDistance(plane->GetOrigin());
355  }
356  return 0;
357  }
358 
365  bool IntersectionLine(const PlaneGeometry *plane, Line3D &crossline) const;
366 
373  unsigned int IntersectWithPlane2D(const PlaneGeometry *plane, Point2D &lineFrom, Point2D &lineTo) const;
374 
380  double Angle(const PlaneGeometry *plane) const;
381 
387  double Angle(const Line3D &line) const;
388 
396  bool IntersectionPoint(const Line3D &line, Point3D &intersectionPoint) const;
397 
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  static std::vector< int > CalculateDominantAxes(mitk::AffineTransform3D::MatrixType::InternalMatrixType& rotation_matrix);
557 
558  protected:
559  PlaneGeometry();
560 
561  PlaneGeometry(const PlaneGeometry &other);
562 
563  ~PlaneGeometry() override;
564 
565  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
566 
568 
569  //##Documentation
570  //## @brief PreSetSpacing
571  //##
572  //## These virtual function allows a different beahiour in subclasses.
573  //## Do implement them in every subclass of BaseGeometry. If not needed, use
574  //## {Superclass::PreSetSpacing();};
575  void PreSetSpacing(const mitk::Vector3D &aSpacing) override { Superclass::PreSetSpacing(aSpacing); };
576  //##Documentation
577  //## @brief CheckBounds
578  //##
579  //## This function is called in SetBounds. Assertions can be implemented in this function (see PlaneGeometry.cpp).
580  //## If you implement this function in a subclass, make sure, that all classes were your class inherits from
581  //## have an implementation of CheckBounds
582  //## (e.g. inheritance BaseGeometry <- A <- B. Implementation of CheckBounds in class B needs implementation in A as
583  // well!)
584  void CheckBounds(const BoundsArrayType &bounds) override;
585 
586  //##Documentation
587  //## @brief CheckIndexToWorldTransform
588  //##
589  //## This function is called in SetIndexToWorldTransform. Assertions can be implemented in this function (see
590  // PlaneGeometry.cpp).
591  //## In Subclasses of BaseGeometry, implement own conditions or call Superclass::CheckBounds(bounds);.
592  void CheckIndexToWorldTransform(mitk::AffineTransform3D *transform) override;
593 
594  private:
599  virtual bool operator==(const PlaneGeometry *) const { return false; };
604  virtual bool operator!=(const PlaneGeometry *) const { return false; };
605  };
606 } // namespace mitk
607 
608 #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)
MITKCORE_EXPORT const ScalarType eps
#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.
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.