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

Revision 2575, 4.2 KB checked in by bittner, 17 years ago (diff)

big merge: preparation for havran ray caster, check if everything works

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
[2575]69  // Just for testing concept
70  virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
71                                 bool castDoubleRay,
72                                 const bool pruneInvalidRays = true)
73  { }
74 
[2077]75  /*virtual void CastRaysEye4(SimpleRayContainer &rays,
[2575]76    VssRayContainer &vssRays,
77    const AxisAlignedBox3 &sbox,
78    const bool castDoubleRay,
79    const bool pruneInvalidRays = true) = 0;
80  */
[1974]81
[2575]82  virtual void
83  SortRays(SimpleRayContainer &rays);
[1974]84
[2161]85
[2575]86  // pool of vss rays to be used in one pass of the sampling
87  struct VssRayPool
88  {
89    VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)
90    {}
91   
92    ~VssRayPool()
93    {
94      delete []mRays;
95    }
96   
97    void Reserve(const int number)
98    {
99      DEL_PTR(mRays);
100      mRays = new VssRay[number];
101      mNumber = number;
102    }
103   
104    void Clear()
105    {
106      mIndex = 0;
107    }
108   
109    VssRay *Alloc()
110    {
111      // reset pool
112      if (mIndex == mNumber)
113        mIndex = 0;
114      return mRays + mIndex ++;
115    }
116  protected:
117    VssRay *mRays;
118    int mIndex;
119    int mNumber;
120  };
[2543]121
122
[2575]123  VssRayPool mVssRayPool;
124 
125  void ReserveVssRayPool(const int n)
126  {
127    mVssRayPool.Reserve(n);
128  }
129 
130  void InitPass()
131  {
132    mVssRayPool.Clear();
133  }
134 
135 
[1520]136protected:
[2575]137 
138  VssRay *RequestRay(const Vector3 &origin,
139                     const Vector3 &termination,
140                     Intersectable *originObject,
141                     Intersectable *terminationObject,
142                     const int pass,
143                     const float pdf);
144 
145  void _SortRays(SimpleRayContainer &rays,
146                 const int l,
147                 const int r,
148                 const int depth,
149                 float box[12]);
150 
151  struct Intersection
152  {
153    Intersection(): mObject(NULL), mFaceId(0)
154    {}
155   
156    Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
157      mPoint(p), mNormal(n), mObject(o), mFaceId(f)
158    {}
159   
160    Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
161    {}
162   
163   
164    ////////////
165   
166    Vector3 mPoint;
167    Vector3 mNormal;
168    Intersectable *mObject;
169    int mFaceId;
170  };
[2187]171
172
[2575]173  int ProcessRay(const SimpleRay &ray,
174                 Intersection &hitA,
175                 Intersection &hitB,
176                 VssRayContainer &vssRays,
177                 const AxisAlignedBox3 &box,
178                 const bool castDoubleRay,
179                 const bool pruneInvalidRays = true);
180 
181  /** Checks if ray is valid.
182      I.e., the ray is in valid view space.
183      @note: clamps the ray to valid view space.
184  */
185  bool ValidateRay(const Vector3 &origin,
186                   const Vector3 &direction,
187                   const AxisAlignedBox3 &box,
188                   Intersection &hit);
189 
190  bool ClipToViewSpaceBox(const Vector3 &origin,
191                          const Vector3 &termination,
192                          Vector3 &clippedOrigin,
193                          Vector3 &clippedTermination);
194 
195  const Preprocessor &mPreprocessor;
196#if 1
197public:
198  // Added by VH for debugging
199  Intersection intersect;
200#endif 
[1520]201};
202
203
204}
205
206#endif
Note: See TracBrowser for help on using the repository browser.