00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C
00020 #define PLANEGEOMETRY_H_HEADER_INCLUDED_C1C68A2C
00021
00022 #include "mitkCommon.h"
00023 #include "mitkGeometry2D.h"
00024
00025 #include <vnl/vnl_cross.h>
00026
00027 namespace mitk {
00028
00029 template < class TCoordRep, unsigned int NPointDimension > class Line;
00030 typedef Line<ScalarType, 3> Line3D;
00031
00032
00033
00039 class MITK_CORE_EXPORT PlaneGeometry : public Geometry2D
00040 {
00041 public:
00042 mitkClassMacro(PlaneGeometry,Geometry2D);
00043
00045 itkNewMacro(Self);
00046
00047 enum PlaneOrientation { Transversal, Sagittal, Frontal };
00048
00049 virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const;
00050
00051 virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const;
00052
00053 virtual void IndexToWorld(const Point2D &atPt2d_units,
00054 const Vector2D &vec_units, Vector2D &vec_mm) const;
00055
00056 virtual void WorldToIndex(const Point2D &atPt2d_mm,
00057 const Vector2D &vec_mm, Vector2D &vec_units) const;
00058
00059 virtual void Initialize();
00060
00078 virtual void InitializeStandardPlane( const Geometry3D* geometry3D,
00079 PlaneOrientation planeorientation = Transversal, ScalarType zPosition = 0,
00080 bool frontside=true, bool rotated=false );
00081
00082
00091 virtual void InitializeStandardPlane( const Geometry3D* geometry3D, bool top,
00092 PlaneOrientation planeorientation = Transversal,
00093 bool frontside=true, bool rotated=false );
00094
00095
00102 virtual void InitializeStandardPlane( ScalarType width, ScalarType height,
00103 const AffineTransform3D* transform = NULL,
00104 PlaneOrientation planeorientation = Transversal,
00105 ScalarType zPosition = 0, bool frontside=true, bool rotated=false );
00106
00107
00113 virtual void InitializeStandardPlane( ScalarType width, ScalarType height,
00114 const Vector3D & spacing, PlaneOrientation planeorientation = Transversal,
00115 ScalarType zPosition = 0, bool frontside = true, bool rotated = false );
00116
00125 virtual void InitializeStandardPlane( ScalarType width, ScalarType height,
00126 const Vector3D& rightVector, const Vector3D& downVector,
00127 const Vector3D *spacing = NULL );
00128
00129
00138 virtual void InitializeStandardPlane( ScalarType width, ScalarType height,
00139 const VnlVector& rightVector, const VnlVector& downVector,
00140 const Vector3D * spacing = NULL );
00141
00142
00151 virtual void InitializeStandardPlane( const Vector3D& rightVector,
00152 const Vector3D& downVector, const Vector3D * spacing = NULL );
00153
00154
00163 virtual void InitializeStandardPlane( const VnlVector& rightVector,
00164 const VnlVector& downVector, const Vector3D * spacing = NULL );
00165
00172 virtual void InitializePlane( const Point3D& origin, const Vector3D& normal);
00173
00180 void SetMatrixByVectors( const VnlVector& rightVector,
00181 const VnlVector& downVector, ScalarType thickness=1.0 );
00182
00183
00189 static void EnsurePerpendicularNormal( AffineTransform3D* transform );
00190
00191
00196 Vector3D GetNormal() const;
00197
00198
00203 VnlVector GetNormalVnl() const;
00204
00205
00206 virtual ScalarType SignedDistance( const Point3D& pt3d_mm ) const;
00207
00208
00209 virtual bool IsAbove( const Point3D& pt3d_mm ) const;
00210
00211
00217 ScalarType DistanceFromPlane( const Point3D& pt3d_mm ) const ;
00218
00219
00226 inline ScalarType SignedDistanceFromPlane( const Point3D& pt3d_mm ) const
00227 {
00228 ScalarType len = GetNormalVnl().two_norm();
00229
00230 if( len == 0 )
00231 return 0;
00232
00233 return (pt3d_mm-GetOrigin())*GetNormal() / len;
00234 }
00235
00236
00243 ScalarType DistanceFromPlane(const PlaneGeometry* plane) const
00244 {
00245 return fabs(SignedDistanceFromPlane(plane));
00246 }
00247
00248
00255 inline ScalarType SignedDistanceFromPlane( const PlaneGeometry *plane ) const
00256 {
00257 if(IsParallel(plane))
00258 {
00259 return SignedDistance(plane->GetOrigin());
00260 }
00261 return 0;
00262 }
00263
00264
00271 bool IntersectionLine( const PlaneGeometry *plane, Line3D &crossline ) const;
00272
00273
00280 unsigned int IntersectWithPlane2D(const PlaneGeometry *plane,
00281 Point2D &lineFrom, Point2D &lineTo ) const ;
00282
00283
00289 double Angle( const PlaneGeometry *plane ) const;
00290
00291
00297 double Angle( const Line3D &line ) const;
00298
00299
00307 bool IntersectionPoint( const Line3D &line,
00308 Point3D &intersectionPoint ) const;
00309
00310
00320 bool IntersectionPointParam( const Line3D &line, double &t ) const;
00321
00322
00328 bool IsParallel( const PlaneGeometry *plane ) const;
00329
00330
00335 bool IsOnPlane( const Point3D &point ) const;
00336
00337
00342 bool IsOnPlane( const Line3D &line ) const;
00343
00344
00353 bool IsOnPlane( const PlaneGeometry *plane ) const;
00354
00355
00359 Point3D ProjectPointOntoPlane( const Point3D &pt ) const;
00360
00361
00362 virtual void SetIndexToWorldTransform( AffineTransform3D *transform);
00363
00364
00365 virtual void SetBounds( const BoundingBox::BoundsArrayType &bounds );
00366
00367
00368 AffineGeometryFrame3D::Pointer Clone() const;
00369
00370
00372 virtual void ExecuteOperation( Operation *operation );
00373
00374
00375 protected:
00376 PlaneGeometry();
00377
00378 virtual ~PlaneGeometry();
00379
00380 virtual void InitializeGeometry( Self *newGeometry ) const;
00381
00382 virtual void PrintSelf( std::ostream &os, itk::Indent indent ) const;
00383
00384 private:
00389 virtual bool operator==( const PlaneGeometry * ) const { return false; };
00390
00395 virtual bool operator!=( const PlaneGeometry * ) const { return false; };
00396
00397 };
00398
00399 }
00400
00401
00402 #endif