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

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