source: GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h @ 1932

Revision 1932, 2.5 KB checked in by mattausch, 17 years ago (diff)
RevLine 
[372]1#ifndef _Plane3_H__
2#define _Plane3_H__
3
4#include "Vector3.h"
5
[860]6namespace GtpVisibilityPreprocessor {
7
[1500]8struct SimpleRay;
9
10/** 3D Plane.
11*/
[372]12class Plane3 {
13public:
14
15  Vector3 mNormal;
16  float mD;
17 
18  Plane3() {}
19 
20  Plane3(const Vector3 &a,
[437]21                 const Vector3 &b,
22                 const Vector3 &c
[1932]23                 );
[372]24
25  Plane3(const Vector3 &normal,
[504]26                 const Vector3 &point
[1076]27                 );
[372]28
[396]29  void ReverseOrientation()
30  {
31          mNormal *= -1;
32          mD *= -1;
33  }
[372]34
[1932]35  float Distance(const Vector3 &v) const
36  {
37          return DotProd(v, mNormal) + mD;
[372]38  }
39
[697]40  enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
41                 
42               
[639]43  /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane.
44  */
45  int Side(const Vector3 &v, const float threshold = 1e-6) const;
[372]46
[437]47  /** Finds intersection of line segment between points a and b with plane.
48          @param a start point
49          @param b end point
50          @param t if not NULL, returns parameter value of intersections
51          @param coplanar if not NULL, returns true if plane and line segments are coplanar.
52  */
[372]53  Vector3 FindIntersection(const Vector3 &a,
[448]54                                                   const Vector3 &b,
55                                                   float *t = NULL,
[639]56                                                   bool *coplanar = NULL) const;
[372]57 
[437]58  /** Finds value of intersection parameter t on line segment from a to b.
[639]59      @returns 0 if coplanar, else parameter t
[437]60  */
[639]61  float FindT(const Vector3 &a, const Vector3 &b) const;
[372]62
[1500]63  float FindT(const SimpleRay &a) const;
64
[372]65  friend bool
66  PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
67 
[1500]68  friend bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2);
69
70  friend SimpleRay GetPlaneIntersection(const Plane3 &plane1, const Plane3 &plane2);
71
[1842]72  friend ostream &operator<<(ostream &s, const Plane3 &p) {
[372]73    s<<p.mNormal<<" "<<p.mD;
74    return s;
75  }
76
77 
78};
79 
80
[1047]81/** A definition for an axis aligned plane.
82*/
83struct AxisAlignedPlane
84{
85public:
86        AxisAlignedPlane(){}
87        AxisAlignedPlane(const int axis, const float position):
[1418]88          mAxis(axis), mPosition(position), mOrientation(false)
[1047]89          {
90          }
91        Plane3 GetPlane() const
92        {
[1418]93                Vector3 normal(0,0,0); normal[mAxis] = mOrientation ? 1.0f : -1.0f;
[1047]94                Vector3 point(0,0,0); point[mAxis] = mPosition;
95
96        return Plane3(normal, point);
97        }
98
99        /// the split axis: one of 0=x, 1=y, 2=z
100        int mAxis;
101        /// the absolute position of the split axis
102        float mPosition;
[1418]103        /// the plane orientation
104        bool mOrientation;
105
106        friend ostream &operator<<(ostream &s, const AxisAlignedPlane &p)
107        {
108                s << "a: " << p.mAxis << " p: " << p.mPosition;
109                return s;
110        }
[1047]111};
[860]112}
[372]113#endif
Note: See TracBrowser for help on using the repository browser.