Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
56 #ifndef PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C
57 #define PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C
58 
59 #include "mitkBaseGeometry.h"
61 #include <MitkCoreExports.h>
62 
63 #include <vnl/vnl_cross.h>
64 
65 namespace mitk
66 {
67  template <class TCoordRep, unsigned int NPointDimension>
68  class Line;
69  typedef Line<ScalarType, 3> Line3D;
70 
74 
81  {
82  public:
84 
86  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
87 
91  Frontal, // also known as "Coronal" in mitk.
92  None // This defines the PlaneGeometry for the 3D renderWindow which
93  // curiously also needs a PlaneGeometry. This should be reconsidered some time.
94  };
95 
96  virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const;
97 
98  virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const;
99 
100  //##Documentation
101  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
102  //## \a vec_units to world coordinates (in mm)
103  //## @deprecated First parameter (Point2D) is not used. If possible, please use void IndexToWorld(const
104  // mitk::Vector2D& vec_units, mitk::Vector2D& vec_mm) const.
105  //## For further information about coordinates types, please see the Geometry documentation
106  virtual void IndexToWorld(const mitk::Point2D &atPt2d_untis,
107  const mitk::Vector2D &vec_units,
108  mitk::Vector2D &vec_mm) const;
109 
110  //##Documentation
111  //## @brief Convert (continuous or discrete) index coordinates of a \em vector
112  //## \a vec_units to world coordinates (in mm)
113  //## For further information about coordinates types, please see the Geometry documentation
114  virtual void IndexToWorld(const mitk::Vector2D &vec_units, mitk::Vector2D &vec_mm) const;
115 
116  //##Documentation
117  //## @brief Convert world coordinates (in mm) of a \em vector
118  //## \a vec_mm to (continuous!) index coordinates.
119  //## @deprecated First parameter (Point2D) is not used. If possible, please use void WorldToIndex(const
120  // mitk::Vector2D& vec_mm, mitk::Vector2D& vec_units) const.
121  //## For further information about coordinates types, please see the Geometry documentation
122  virtual void WorldToIndex(const mitk::Point2D &atPt2d_mm,
123  const mitk::Vector2D &vec_mm,
124  mitk::Vector2D &vec_units) const;
125 
126  //##Documentation
127  //## @brief Convert world coordinates (in mm) of a \em vector
128  //## \a vec_mm to (continuous!) index coordinates.
129  //## For further information about coordinates types, please see the Geometry documentation
130  virtual void WorldToIndex(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units) const;
131 
149  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
150  PlaneOrientation planeorientation = Axial,
151  ScalarType zPosition = 0,
152  bool frontside = true,
153  bool rotated = false,
154  bool top = true);
155 
164  virtual void InitializeStandardPlane(const BaseGeometry *geometry3D,
165  bool top,
166  PlaneOrientation planeorientation = Axial,
167  bool frontside = true,
168  bool rotated = false);
169 
188  virtual void InitializeStandardPlane(ScalarType width,
189  ScalarType height,
190  const AffineTransform3D *transform = nullptr,
191  PlaneOrientation planeorientation = Axial,
192  ScalarType zPosition = 0,
193  bool frontside = true,
194  bool rotated = false,
195  bool top = true);
196 
202  virtual void InitializeStandardPlane(ScalarType width,
203  ScalarType height,
204  const Vector3D &spacing,
205  PlaneOrientation planeorientation = Axial,
206  ScalarType zPosition = 0,
207  bool frontside = true,
208  bool rotated = false,
209  bool top = true);
210 
223  virtual void InitializeStandardPlane(ScalarType width,
224  ScalarType height,
225  const Vector3D &rightVector,
226  const Vector3D &downVector,
227  const Vector3D *spacing = nullptr);
228 
241  virtual void InitializeStandardPlane(ScalarType width,
242  ScalarType height,
243  const VnlVector &rightVector,
244  const VnlVector &downVector,
245  const Vector3D *spacing = nullptr);
246 
255  virtual void InitializeStandardPlane(const Vector3D &rightVector,
256  const Vector3D &downVector,
257  const Vector3D *spacing = nullptr);
258 
267  virtual void InitializeStandardPlane(const VnlVector &rightVector,
268  const VnlVector &downVector,
269  const Vector3D *spacing = nullptr);
270 
277  virtual void InitializePlane(const Point3D &origin, const Vector3D &normal);
278 
287  void SetMatrixByVectors(const VnlVector &rightVector, const VnlVector &downVector, ScalarType thickness = 1.0);
288 
294  static void EnsurePerpendicularNormal(AffineTransform3D *transform);
295 
300  Vector3D GetNormal() const;
301 
306  VnlVector GetNormalVnl() const;
307 
308  virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const;
309 
314  virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox = false) const;
315 
321  ScalarType DistanceFromPlane(const Point3D &pt3d_mm) const;
322 
329  inline ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
330  {
331  ScalarType len = GetNormalVnl().two_norm();
332 
333  if (len == 0)
334  return 0;
335 
336  return (pt3d_mm - GetOrigin()) * GetNormal() / len;
337  }
338 
345  ScalarType DistanceFromPlane(const PlaneGeometry *plane) const { return fabs(SignedDistanceFromPlane(plane)); }
353  {
354  if (IsParallel(plane))
355  {
356  return SignedDistance(plane->GetOrigin());
357  }
358  return 0;
359  }
360 
367  bool IntersectionLine(const PlaneGeometry *plane, Line3D &crossline) const;
368 
375  unsigned int IntersectWithPlane2D(const PlaneGeometry *plane, Point2D &lineFrom, Point2D &lineTo) const;
376 
382  double Angle(const PlaneGeometry *plane) const;
383 
389  double Angle(const Line3D &line) const;
390 
398  bool IntersectionPoint(const Line3D &line, Point3D &intersectionPoint) const;
399 
409  bool IntersectionPointParam(const Line3D &line, double &t) const;
410 
416  bool IsParallel(const PlaneGeometry *plane) const;
417 
422  bool IsOnPlane(const Point3D &point) const;
423 
428  bool IsOnPlane(const Line3D &line) const;
429 
438  bool IsOnPlane(const PlaneGeometry *plane) const;
439 
443  Point3D ProjectPointOntoPlane(const Point3D &pt) const;
444 
445  virtual itk::LightObject::Pointer InternalClone() const override;
446 
448  virtual void ExecuteOperation(Operation *operation) override;
449 
461  virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const;
462 
472  virtual void Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const;
473 
482  virtual void SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height);
483 
490  virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const;
491 
504  virtual bool Map(const mitk::Point3D &atPt3d_mm, const mitk::Vector3D &vec3d_mm, mitk::Vector2D &vec2d_mm) const;
505 
515  virtual void Map(const mitk::Point2D &atPt2d_mm, const mitk::Vector2D &vec2d_mm, mitk::Vector3D &vec3d_mm) const;
516 
525  virtual bool Project(const mitk::Point3D &atPt3d_mm,
526  const mitk::Vector3D &vec3d_mm,
527  mitk::Vector3D &projectedVec3d_mm) const;
528 
535  virtual bool Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const;
536 
542  inline ScalarType Distance(const Point3D &pt3d_mm) const { return fabs(SignedDistance(pt3d_mm)); }
550  void SetReferenceGeometry(const mitk::BaseGeometry *geometry);
551 
555  const BaseGeometry *GetReferenceGeometry() const;
556  bool HasReferenceGeometry() const;
557 
558  protected:
559  PlaneGeometry();
560 
561  PlaneGeometry(const PlaneGeometry &other);
562 
563  virtual ~PlaneGeometry();
564 
565  virtual 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  virtual 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  virtual 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  virtual 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 */
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
static char * line
Definition: svm.cpp:2884
itk::SmartPointer< Self > Pointer
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
#define MITKCORE_EXPORT
ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
Signed distance of the point from the plane (bounding-box not considered)
Base class of all Operation-classes.
Definition: mitkOperation.h:33
vnl_vector< ScalarType > VnlVector
Definition: mitkVector.h:138
double ScalarType
Line< ScalarType, 3 > Line3D
Definition: mitkLine.h:413
DataCollection - Class to facilitate loading/accessing structured data.
ScalarType Distance(const Point3D &pt3d_mm) const
Distance of the point from the geometry (bounding-box not considered)
ScalarType SignedDistanceFromPlane(const PlaneGeometry *plane) const
Signed distance of the plane from another plane (bounding-box not considered)
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
const mitk::BaseGeometry * m_ReferenceGeometry
#define DEPRECATED(func)
Definition: mitkCommon.h:183
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
Describes a two-dimensional, rectangular plane.
ScalarType DistanceFromPlane(const PlaneGeometry *plane) const
Distance of the plane from another plane (bounding-box not considered)
virtual void PreSetSpacing(const mitk::Vector3D &aSpacing) override
PreSetSpacing.
BaseGeometry Describes the geometry of a data object.
BoundingBoxType::BoundsArrayType BoundsArrayType