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

Revision 1932, 2.5 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifndef _Plane3_H__
2#define _Plane3_H__
3
4#include "Vector3.h"
5
6namespace GtpVisibilityPreprocessor {
7
8struct SimpleRay;
9
10/** 3D Plane.
11*/
12class Plane3 {
13public:
14
15  Vector3 mNormal;
16  float mD;
17 
18  Plane3() {}
19 
20  Plane3(const Vector3 &a,
21                 const Vector3 &b,
22                 const Vector3 &c
23                 );
24
25  Plane3(const Vector3 &normal,
26                 const Vector3 &point
27                 );
28
29  void ReverseOrientation()
30  {
31          mNormal *= -1;
32          mD *= -1;
33  }
34
35  float Distance(const Vector3 &v) const
36  {
37          return DotProd(v, mNormal) + mD;
38  }
39
40  enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
41                 
42               
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;
46
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  */
53  Vector3 FindIntersection(const Vector3 &a,
54                                                   const Vector3 &b,
55                                                   float *t = NULL,
56                                                   bool *coplanar = NULL) const;
57 
58  /** Finds value of intersection parameter t on line segment from a to b.
59      @returns 0 if coplanar, else parameter t
60  */
61  float FindT(const Vector3 &a, const Vector3 &b) const;
62
63  float FindT(const SimpleRay &a) const;
64
65  friend bool
66  PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
67 
68  friend bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2);
69
70  friend SimpleRay GetPlaneIntersection(const Plane3 &plane1, const Plane3 &plane2);
71
72  friend ostream &operator<<(ostream &s, const Plane3 &p) {
73    s<<p.mNormal<<" "<<p.mD;
74    return s;
75  }
76
77 
78};
79 
80
81/** A definition for an axis aligned plane.
82*/
83struct AxisAlignedPlane
84{
85public:
86        AxisAlignedPlane(){}
87        AxisAlignedPlane(const int axis, const float position):
88          mAxis(axis), mPosition(position), mOrientation(false)
89          {
90          }
91        Plane3 GetPlane() const
92        {
93                Vector3 normal(0,0,0); normal[mAxis] = mOrientation ? 1.0f : -1.0f;
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;
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        }
111};
112}
113#endif
Note: See TracBrowser for help on using the repository browser.