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

Revision 2069, 3.4 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 CastRaysEye4(SimpleRayContainer &rays,
63                                                          VssRayContainer &vssRays,
64                                                          const AxisAlignedBox3 &sbox,
65                                                          const bool castDoubleRay,
66                                                          const bool pruneInvalidRays = true) = 0;
67*/
68        virtual void
69        SortRays(SimpleRayContainer &rays);
70
71
72
73  // pool of vss rays to be used in one pass of the sampling
74  struct VssRayPool {
75        VssRayPool():mRays(NULL), mIndex(0), mNumber(0) {}
76        ~VssRayPool() {
77          if (mRays)
78                delete mRays;
79        }
80       
81        void Reserve(const int number) {
82          if (mRays)
83                delete mRays;
84          cout << "here4" << endl;
85          mRays = new VssRay[number];
86          mNumber = number;
87        }
88       
89        void Clear() {
90          mIndex = 0;
91        }
92        VssRay *Alloc() {
93                // reset pool
94                if (mIndex == mNumber)
95                        mIndex = 0;
96          return mRays + mIndex ++;
97        }
98
99        VssRay *mRays;
100        int mIndex;
101        int mNumber;
102  };
103
104 
105  VssRayPool mVssRayPool;
106
107  void ReserveVssRayPool(const int n) {
108        mVssRayPool.Reserve(n);
109  }
110 
111  void InitPass() {
112        mVssRayPool.Clear();
113  }
114
115
116protected:
117  void _SortRays(SimpleRayContainer &rays,
118                                 const int l,
119                                 const int r,
120                                 const int depth,
121                                 float box[12]);
122       
123  struct Intersection
124  {
125          Intersection(): mObject(NULL), mFaceId(0)
126          {}
127
128          Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
129          mPoint(p), mNormal(n), mObject(o), mFaceId(f)
130          {}
131
132          Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
133          {}
134          Vector3 mPoint;
135          Vector3 mNormal;
136          Intersectable *mObject;
137          int mFaceId;
138  };
139
140
141  int ProcessRay(const SimpleRay &ray,
142          Intersection &hitA,
143          Intersection &hitB,
144          VssRayContainer &vssRays,
145          const AxisAlignedBox3 &box,
146          const bool castDoubleRay,
147          const bool pruneInvalidRays = true);
148
149  /** Checks if ray is valid.
150  I.e., the ray is in valid view space.
151  @note: clamps the ray to valid view space.
152  */
153  bool ValidateRay(const Vector3 &origin,
154          const Vector3 &direction,
155          const AxisAlignedBox3 &box,
156          Intersection &hit);
157
158  bool
159          ClipToViewSpaceBox(const Vector3 &origin,
160          const Vector3 &termination,
161          Vector3 &clippedOrigin,
162          Vector3 &clippedTermination);
163
164
165
166
167
168
169  const Preprocessor &mPreprocessor;
170};
171
172
173}
174
175#endif
Note: See TracBrowser for help on using the repository browser.