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

Revision 2014, 3.1 KB checked in by bittner, 17 years ago (diff)

timer start

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