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

Revision 2729, 5.8 KB checked in by mattausch, 16 years ago (diff)

worked on gvs

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