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

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