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

Revision 2583, 4.9 KB checked in by bittner, 16 years ago (diff)

Havran ray caster functional except enhanced features used by mutation and object based pvs

Line 
1#ifndef _RayCaster_H__
2#define _RayCaster_H__
3
4
5#include "Containers.h"
6#include <string>
7#include <iostream>
8#include "Vector3.h"
9#include "VssRay.h"
10
11using namespace std;
12
13//
14
15
16namespace GtpVisibilityPreprocessor {
17
18
19class Intersectable;
20class VssRay;
21class SimpleRayContainer;
22class AxisAlignedBox3;
23struct VssRayContainer;
24class Preprocessor;
25struct SimpleRay;
26class RayPacket2x2;
27
28/** This class provides an interface for ray casting.
29*/
30class RayCaster
31{
32
33public:
34       
35  enum {
36    INTERNAL_RAYCASTER = 0,
37    INTEL_RAYCASTER = 1,
38    HAVRAN_RAYCASTER = 2
39  };
40
41  RayCaster(const Preprocessor &preprocessor);
42
43  virtual ~RayCaster();
44 
45  virtual int Type() const = 0;
46
47  /** Wrapper for casting single ray.
48      @returns ray or NULL if invalid
49  */
50  VssRay *CastRay(const SimpleRay &simpleRay,
51                  const AxisAlignedBox3 &box,
52                  const bool castDoubleRay);
53
54  virtual int CastRay(const SimpleRay &simpleRay,
55                      VssRayContainer &vssRays,
56                      const AxisAlignedBox3 &box,
57                      const bool castDoubleRay,
58                      const bool pruneInvalidRays = true) = 0;
59
60  virtual void CastRays16(SimpleRayContainer &rays,
61                          VssRayContainer &vssRays,
62                          const AxisAlignedBox3 &sbox,
63                          const bool castDoubleRay,
64                          const bool pruneInvalidRays = true) = 0;
65 
66  virtual void CastRays(
67                        SimpleRayContainer &rays,
68                        VssRayContainer &vssRays,
69                        const AxisAlignedBox3 &sbox,
70                        const bool castDoubleRay,
71                        const bool pruneInvalidRays = true);
72
73  // Using packet of 4 rays supposing that these are coherent
74  virtual void CastRaysPacket4(Vector3 origin4[],
75                               Vector3 direction4[],
76                               int     result4[],
77                               float   dist4[]) {  }
78
79  // Using packet of 4 rays supposing that these are coherent
80  // We give a box to which each ray is clipped to before the
81  // ray shooting is computed !
82  virtual void CastRaysPacket4(const Vector3 &minBox,
83                                                           const Vector3 &maxBox,
84                                                           const Vector3 origin4[],
85                                                           const Vector3 direction4[],
86                                                           int result4[],
87                                                           float dist4[]) {  }
88 
89  // Just for testing concept
90  virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
91                                 bool castDoubleRay,
92                                 const bool pruneInvalidRays = true)
93  { }
94 
95  /*virtual void CastRaysEye4(SimpleRayContainer &rays,
96    VssRayContainer &vssRays,
97    const AxisAlignedBox3 &sbox,
98    const bool castDoubleRay,
99    const bool pruneInvalidRays = true) = 0;
100  */
101
102  virtual void
103  SortRays(SimpleRayContainer &rays);
104
105
106  // pool of vss rays to be used in one pass of the sampling
107  struct VssRayPool
108  {
109    VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)
110    {}
111   
112    ~VssRayPool()
113    {
114      delete []mRays;
115    }
116   
117    void Reserve(const int number)
118    {
119      DEL_PTR(mRays);
120      mRays = new VssRay[number];
121      mNumber = number;
122    }
123   
124    void Clear()
125    {
126      mIndex = 0;
127    }
128   
129    VssRay *Alloc()
130    {
131      // reset pool
132      if (mIndex == mNumber)
133        mIndex = 0;
134      return mRays + mIndex ++;
135    }
136  protected:
137    VssRay *mRays;
138    int mIndex;
139    int mNumber;
140  };
141
142
143  VssRayPool mVssRayPool;
144 
145  void ReserveVssRayPool(const int n)
146  {
147    mVssRayPool.Reserve(n);
148  }
149 
150  void InitPass()
151  {
152    mVssRayPool.Clear();
153  }
154 
155 
156protected:
157 
158  VssRay *RequestRay(const Vector3 &origin,
159                     const Vector3 &termination,
160                     Intersectable *originObject,
161                     Intersectable *terminationObject,
162                     const int pass,
163                     const float pdf);
164 
165  void _SortRays(SimpleRayContainer &rays,
166                 const int l,
167                 const int r,
168                 const int depth,
169                 float box[12]);
170 
171  struct Intersection
172  {
173    Intersection(): mObject(NULL), mFaceId(0)
174    {}
175   
176    Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
177      mPoint(p), mNormal(n), mObject(o), mFaceId(f)
178    {}
179   
180    Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
181    {}
182   
183   
184    ////////////
185   
186    Vector3 mPoint;
187    Vector3 mNormal;
188    Intersectable *mObject;
189    int mFaceId;
190  };
191
192
193  int ProcessRay(const SimpleRay &ray,
194                 Intersection &hitA,
195                 Intersection &hitB,
196                 VssRayContainer &vssRays,
197                 const AxisAlignedBox3 &box,
198                 const bool castDoubleRay,
199                 const bool pruneInvalidRays = true);
200 
201  /** Checks if ray is valid.
202      I.e., the ray is in valid view space.
203      @note: clamps the ray to valid view space.
204  */
205  bool ValidateRay(const Vector3 &origin,
206                   const Vector3 &direction,
207                   const AxisAlignedBox3 &box,
208                   Intersection &hit);
209 
210  bool ClipToViewSpaceBox(const Vector3 &origin,
211                          const Vector3 &termination,
212                          Vector3 &clippedOrigin,
213                          Vector3 &clippedTermination);
214 
215  const Preprocessor &mPreprocessor;
216#if 1
217public:
218  // Added by VH for debugging
219  Intersection intersect;
220#endif 
221};
222
223
224}
225
226#endif
Note: See TracBrowser for help on using the repository browser.