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

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