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

Line 
1#ifndef _RayCaster_H__
2#define _RayCaster_H__
3
4#include "Containers.h"
5#include <string>
6#include "Vector3.h"
7#include "VssRay.h"
8
9//
10
11
12namespace GtpVisibilityPreprocessor {
13
14
15class Intersectable;
16class VssRay;
17class SimpleRayContainer;
18class AxisAlignedBox3;
19struct VssRayContainer;
20class Preprocessor;
21struct SimpleRay;
22class RayPacket2x2;
23
24/** This class provides an interface for ray casting.
25*/
26class RayCaster
27{
28
29public:
30       
31  enum {
32    INTERNAL_RAYCASTER = 0,
33    INTEL_RAYCASTER = 1,
34    HAVRAN_RAYCASTER = 2
35  };
36
37  RayCaster(const Preprocessor &preprocessor);
38
39  virtual ~RayCaster();
40 
41  virtual int Type() const = 0;
42
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);
49
50  virtual int CastRay(const SimpleRay &simpleRay,
51                      VssRayContainer &vssRays,
52                      const AxisAlignedBox3 &box,
53                      const bool castDoubleRay,
54                      const bool pruneInvalidRays = true) = 0;
55
56  virtual void CastRays16(SimpleRayContainer &rays,
57                          VssRayContainer &vssRays,
58                          const AxisAlignedBox3 &sbox,
59                          const bool castDoubleRay,
60                          const bool pruneInvalidRays = true) = 0;
61 
62  virtual void CastRays(
63                        SimpleRayContainer &rays,
64                        VssRayContainer &vssRays,
65                        const AxisAlignedBox3 &sbox,
66                        const bool castDoubleRay,
67                        const bool pruneInvalidRays = true);
68
69  // Just for testing concept
70  virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
71                                 bool castDoubleRay,
72                                 const bool pruneInvalidRays = true)
73  { }
74 
75  /*virtual void CastRaysEye4(SimpleRayContainer &rays,
76    VssRayContainer &vssRays,
77    const AxisAlignedBox3 &sbox,
78    const bool castDoubleRay,
79    const bool pruneInvalidRays = true) = 0;
80  */
81
82  virtual void
83  SortRays(SimpleRayContainer &rays);
84
85
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  };
121
122
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 
136protected:
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  };
171
172
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 
201};
202
203
204}
205
206#endif
Note: See TracBrowser for help on using the repository browser.