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

Revision 2582, 4.8 KB checked in by bittner, 16 years ago (diff)

Havran Ray Caster compiles and links, but still does not work

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