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

Revision 2176, 2.5 KB checked in by mattausch, 17 years ago (diff)

removed using namespace std from .h

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
[2176]72  friend std::ostream &operator<<(std::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          }
[2176]91
[1047]92        Plane3 GetPlane() const
93        {
[1418]94                Vector3 normal(0,0,0); normal[mAxis] = mOrientation ? 1.0f : -1.0f;
[1047]95                Vector3 point(0,0,0); point[mAxis] = mPosition;
96
97        return Plane3(normal, point);
98        }
99
100        /// the split axis: one of 0=x, 1=y, 2=z
101        int mAxis;
102        /// the absolute position of the split axis
103        float mPosition;
[1418]104        /// the plane orientation
105        bool mOrientation;
106
[2176]107        friend std::ostream &operator<<(std::ostream &s, const AxisAlignedPlane &p)
[1418]108        {
109                s << "a: " << p.mAxis << " p: " << p.mPosition;
110                return s;
111        }
[1047]112};
[860]113}
[372]114#endif
Note: See TracBrowser for help on using the repository browser.