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

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