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

Revision 2063, 3.4 KB checked in by mattausch, 17 years ago (diff)

warning: the mutation contains bugs now as internal
ray casting support is not implemented

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