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

Revision 1076, 2.1 KB checked in by mattausch, 18 years ago (diff)

version for performance testing

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