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

Revision 1500, 2.5 KB checked in by mattausch, 18 years ago (diff)

worked on gvs sampling

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    return DotProd(v, mNormal) + mD;
37  }
38
39  enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
40                 
41               
42  /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane.
43  */
44  int Side(const Vector3 &v, const float threshold = 1e-6) const;
45
46  /** Finds intersection of line segment between points a and b with plane.
47          @param a start point
48          @param b end point
49          @param t if not NULL, returns parameter value of intersections
50          @param coplanar if not NULL, returns true if plane and line segments are coplanar.
51  */
52  Vector3 FindIntersection(const Vector3 &a,
53                                                   const Vector3 &b,
54                                                   float *t = NULL,
55                                                   bool *coplanar = NULL) const;
56 
57  /** Finds value of intersection parameter t on line segment from a to b.
58      @returns 0 if coplanar, else parameter t
59  */
60  float FindT(const Vector3 &a, const Vector3 &b) const;
61
62  float FindT(const SimpleRay &a) const;
63
64  friend bool
65  PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
66 
67  friend bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2);
68
69  friend SimpleRay GetPlaneIntersection(const Plane3 &plane1, const Plane3 &plane2);
70
71  friend ostream &operator<<(ostream &s, const Plane3 p) {
72    s<<p.mNormal<<" "<<p.mD;
73    return s;
74  }
75
76 
77};
78 
79
80/** A definition for an axis aligned plane.
81*/
82struct AxisAlignedPlane
83{
84public:
85        AxisAlignedPlane(){}
86        AxisAlignedPlane(const int axis, const float position):
87          mAxis(axis), mPosition(position), mOrientation(false)
88          {
89          }
90        Plane3 GetPlane() const
91        {
92                Vector3 normal(0,0,0); normal[mAxis] = mOrientation ? 1.0f : -1.0f;
93                Vector3 point(0,0,0); point[mAxis] = mPosition;
94
95        return Plane3(normal, point);
96        }
97
98        /// the split axis: one of 0=x, 1=y, 2=z
99        int mAxis;
100        /// the absolute position of the split axis
101        float mPosition;
102        /// the plane orientation
103        bool mOrientation;
104
105        friend ostream &operator<<(ostream &s, const AxisAlignedPlane &p)
106        {
107                s << "a: " << p.mAxis << " p: " << p.mPosition;
108                return s;
109        }
110};
111}
112#endif
Note: See TracBrowser for help on using the repository browser.