source: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h @ 2164

Revision 2164, 3.6 KB checked in by mattausch, 17 years ago (diff)
RevLine 
[1520]1#ifndef _RayCaster_H__
2#define _RayCaster_H__
3
4#include "Containers.h"
5#include <string>
[1528]6#include "Vector3.h"
[2014]7#include "VssRay.h"
[1528]8
[1520]9using namespace std;
10
11
12namespace GtpVisibilityPreprocessor {
13
14
15class Intersectable;
16class VssRay;
17class SimpleRayContainer;
18class AxisAlignedBox3;
[1528]19//class Vector3;
[1520]20struct VssRayContainer;
21class Preprocessor;
[1528]22struct SimpleRay;
[1520]23
[1528]24
[1520]25/** This class provides an interface for ray casting.
26*/
27class RayCaster
28{
[1528]29
[1520]30public:
31       
32        enum {
33          INTERNAL_RAYCASTER = 0,
34          INTEL_RAYCASTER
35        };
36
37        RayCaster(const Preprocessor &preprocessor);
38
[1521]39        virtual ~RayCaster();
[1520]40
41        virtual int Type() const = 0;
42
[1521]43        /** Wrapper for casting single ray.
[1545]44                @returns ray or NULL if invalid
[1521]45        */
[1932]46        VssRay *CastRay(const SimpleRay &simpleRay,
[1990]47                                        const AxisAlignedBox3 &box,
[1996]48                                        const bool castDoubleRay);
[1521]49
[1932]50        virtual int CastRay(const SimpleRay &simpleRay,
51                                                VssRayContainer &vssRays,
52                                                const AxisAlignedBox3 &box,
53                                                const bool castDoubleRay,
[1996]54                                                const bool pruneInvalidRays = true) = 0;
[1520]55
[2063]56        virtual void CastRays16(SimpleRayContainer &rays,
57                                                        VssRayContainer &vssRays,
58                                                        const AxisAlignedBox3 &sbox,
59                                                        const bool castDoubleRay,
60                                                        const bool pruneInvalidRays = true) = 0;
[1974]61
[2076]62  virtual void CastRays(
63                                                SimpleRayContainer &rays,
64                                                VssRayContainer &vssRays,
65                                                const AxisAlignedBox3 &sbox,
66                                                const bool castDoubleRay,
67                                                const bool pruneInvalidRays = true);
[2077]68
69  /*virtual void CastRaysEye4(SimpleRayContainer &rays,
[2063]70                                                          VssRayContainer &vssRays,
71                                                          const AxisAlignedBox3 &sbox,
72                                                          const bool castDoubleRay,
73                                                          const bool pruneInvalidRays = true) = 0;
74*/
75        virtual void
76        SortRays(SimpleRayContainer &rays);
[1974]77
78
[2012]79  // pool of vss rays to be used in one pass of the sampling
80  struct VssRayPool {
[2161]81        VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)
82        {}
83
84        ~VssRayPool()
85        {
86                DEL_PTR(mRays);
[2014]87        }
88       
[2012]89        void Reserve(const int number) {
[2164]90                DEL_PTR(mRays);
91                mRays = new VssRay[number];
92                mNumber = number;
[2012]93        }
[2014]94       
[2012]95        void Clear() {
96          mIndex = 0;
97        }
98        VssRay *Alloc() {
[2048]99                // reset pool
100                if (mIndex == mNumber)
101                        mIndex = 0;
[2069]102          return mRays + mIndex ++;
[2012]103        }
[2161]104  protected:
[2014]105        VssRay *mRays;
[2012]106        int mIndex;
[2048]107        int mNumber;
[2012]108  };
109
110 
111  VssRayPool mVssRayPool;
112
113  void ReserveVssRayPool(const int n) {
114        mVssRayPool.Reserve(n);
115  }
116 
117  void InitPass() {
118        mVssRayPool.Clear();
119  }
120
121
[1520]122protected:
[1984]123  void _SortRays(SimpleRayContainer &rays,
124                                 const int l,
125                                 const int r,
126                                 const int depth,
127                                 float box[12]);
128       
[1974]129  struct Intersection
[2069]130  {
131          Intersection(): mObject(NULL), mFaceId(0)
132          {}
[1520]133
[2069]134          Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
135          mPoint(p), mNormal(n), mObject(o), mFaceId(f)
136          {}
[1528]137
[2069]138          Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
139          {}
140          Vector3 mPoint;
141          Vector3 mNormal;
142          Intersectable *mObject;
143          int mFaceId;
144  };
[1528]145
[1824]146
[2069]147  int ProcessRay(const SimpleRay &ray,
148          Intersection &hitA,
149          Intersection &hitB,
150          VssRayContainer &vssRays,
151          const AxisAlignedBox3 &box,
152          const bool castDoubleRay,
153          const bool pruneInvalidRays = true);
[1520]154
[2069]155  /** Checks if ray is valid.
[2161]156          I.e., the ray is in valid view space.
157          @note: clamps the ray to valid view space.
[2069]158  */
159  bool ValidateRay(const Vector3 &origin,
160          const Vector3 &direction,
161          const AxisAlignedBox3 &box,
162          Intersection &hit);
[1942]163
[2069]164  bool
165          ClipToViewSpaceBox(const Vector3 &origin,
166          const Vector3 &termination,
167          Vector3 &clippedOrigin,
168          Vector3 &clippedTermination);
[2012]169
170
171
172
[2069]173
174
[2012]175  const Preprocessor &mPreprocessor;
[1520]176};
177
178
179}
180
181#endif
Note: See TracBrowser for help on using the repository browser.