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

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