source: GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h @ 1785

Revision 1785, 8.1 KB checked in by bittner, 18 years ago (diff)

merge, filter update, renderebuffer made functional

RevLine 
[376]1#ifndef __VSS_RAY_H
2#define __VSS_RAY_H
[372]3
4#include <vector>
5using namespace std;
6#include "Vector3.h"
[410]7#include "Ray.h"
[492]8#include "Containers.h"
[372]9
[860]10namespace GtpVisibilityPreprocessor {
11
[372]12class AxisAlignedBox3;
13class Intersectable;
[1133]14class KdNode;
[372]15
[1785]16#define ABS_CONTRIBUTION_WEIGHT 0.8f
[1528]17
[372]18class VssRay {
19public:
[1528]20
21 // various flags
[372]22  enum {
[1566]23    FPosDirX = 1,    // the direction of ray in X-axis is positive
24    FPosDirY = 2,    // the direction of ray in Y-axis is positive
25    FPosDirZ = 4,    // the direction of ray in Z-axis is positive
26        BorderSample = 8,// if this ray is an adaptive border ray
[1771]27        ReverseSample = 16,  // if this ray is a reverse sample
28        Valid = 32  // this ray is a valid ray
29                   //(with respect to detect empty viewspace)
[372]30  };
31
[438]32  static int mailID;
[372]33  int mMailbox;
34       
[438]35  // side of the ray - used for the ray classification
36  //  char mSide;
[372]37       
[438]38  // computed t
[463]39  //  float mT;
[372]40
[438]41  // inverse of the ray size
42  float mInvSize;
43 
44  // counter of references to this ray
[372]45  short mRefCount;
[438]46 
47  // various flags
[372]48  char mFlags;
49       
50  Vector3 mOrigin;
51  Vector3 mTermination;
52       
[438]53  /// Termination object for the ray
54  /// only the termination object is actually used
55  Intersectable *mOriginObject;
56  Intersectable *mTerminationObject;
[464]57
[492]58  ViewCellContainer mViewCells;
59 
[1133]60
[464]61  ////////////////////////
62  // members related to importance sampling
63  // sampling pass in which this ray was generated
64  short mPass;
65
66  // number of cells where this ray made a contribution to the PVS
67  short mPvsContribution;
68 
69  // sum of relative ray contributions per object
70  float mRelativePvsContribution;
[492]71
72
73  // weighted contribution to the pvs (based on the pass the ray was casted at)
74  // computed by the prperocessor
75  float mWeightedPvsContribution;
[534]76
77  // probability of this ray
[556]78  float mPdf;
[464]79 
[438]80  //////////////////////////////
[1133]81
82 
83  /// the kd node holding the termination point
84  KdNode *mTerminationNode;
85  /// the kd node holding the origin point
86  KdNode *mOriginNode;
87
88
[464]89  VssRay(
90                 const Vector3 &origin,
[438]91                 const Vector3 &termination,
92                 Intersectable *originObject,
[464]93                 Intersectable *terminationObject,
[537]94                 const int pass = 0,
[556]95                 const float pdf = 1.0f
[1528]96                 );
[372]97       
[1528]98  VssRay(const Ray &ray);
[492]99       
100 
[1528]101  void Precompute();
[376]102
[372]103  void Mail() { mMailbox = mailID; }
104  static void NewMail() { mailID++; }
105  bool Mailed() const { return mMailbox == mailID; }
106
107  bool Mailed(const int mail) {
108    return mMailbox >= mailID + mail;
109  }
110
[438]111  int HitCount() const {
[386]112#if BIDIRECTIONAL_RAY
[438]113        if (mOriginObject && mTerminationObject)
114          return 2;
115        if (mOriginObject || mTerminationObject)
116          return 1;
117        return 0;
[386]118#else
[438]119        return (mTerminationObject) ? 1 : 0;
[386]120#endif
[438]121  }
[372]122       
[438]123  Vector3 GetOrigin() const { return mOrigin; }
[372]124  Vector3 GetTermination() const { return mTermination; }
125  Vector3 GetDir() const { return mTermination - mOrigin; }
126  //  Vector3 GetNormalizedDir() const { return Normalize(termination - mOrigin); }
127  Vector3 GetNormalizedDir() const { return (mTermination - mOrigin)*mInvSize; }
128
[448]129  float Length() const { return Distance(mOrigin, mTermination); }
130
[438]131  Vector3 Extrap(const float t) const {
132        return GetOrigin() + t * GetDir();
133  }
[434]134       
[438]135  float GetDirParametrization(const int axis) const;
[492]136  float GetOpositeDirParametrization(const int axis) const;
[438]137
138  static float VssRay::GetDirParam(const int axis, const Vector3 dir);
139
140  float GetSize() const { return  1.0f/mInvSize; }
141  float GetInvSize() const { return  mInvSize; }
[372]142  float GetOrigin(const int axis) const { return mOrigin[axis]; }
143  float GetTermination(const int axis) const { return mTermination[axis]; }
144  float GetDir(const int axis) const { return mTermination[axis] - mOrigin[axis]; }
145  float GetNormalizedDir(const int axis) const {
146    return (mTermination[axis] - mOrigin[axis])*mInvSize;
147  }
148       
149  bool
150  ComputeMinMaxT(const AxisAlignedBox3 &box,
[438]151                                 float &tmin,
152                                 float &tmax) const;
[372]153       
154  bool
155  Intersects(const AxisAlignedBox3 &box,
[438]156                         float &tmin,
157                         float &tmax) const;
[372]158       
159  bool
160  IntersectsSphere(const Vector3 &center,
[438]161                                   const float sqrRadius,
162                                   Vector3 &point,
163                                   float &t) const;
[372]164       
165  void
166  Translate(const Vector3 &translation) {
167    mOrigin += translation;
168    mTermination += translation;
169  }
[427]170
[438]171  void SetupEndPoints(const Vector3 &origin,
172                                          const Vector3 &termination)
173  {
174        mOrigin = origin;
175        mTermination = termination;
176        Precompute();
177  }
[427]178                                                                                       
[372]179  bool HasPosDir(const int axis) const { return mFlags & (1<<axis); }
180
[1112]181  char Flags() const { return mFlags;}  void SetFlags(char orFlag) { mFlags |= orFlag;}
[372]182 
183  bool IsActive() const { return mRefCount>0; }
184       
185  // reference counting for leaf nodes
186  int RefCount() const { return mRefCount; }
187  int Ref() { return mRefCount++; }
188       
189  void ScheduleForRemoval() { if (mRefCount>0) mRefCount = -mRefCount; }
190  bool ScheduledForRemoval() const { return mRefCount<0; }
191  void Unref() {
192    if (mRefCount > 0)
193      mRefCount--;
194    else
195      if (mRefCount < 0)
[438]196                mRefCount++;
[372]197      else {
[438]198                cerr<<"Trying to unref already deleted ray!"<<endl;
199                exit(1);
[372]200      }
201  }
[434]202
[438]203  static Vector3
204  GetDirection(const float a, const float b) {
205        return Vector3(sin(a), sin(b), cos(a));
206  }
[434]207
[492]208  friend bool GreaterWeightedPvsContribution(const VssRay * a,
209                                                                                         const VssRay *b) {
210        return a->mWeightedPvsContribution > b->mWeightedPvsContribution;
211  }
212
213  float SqrDistance(const Vector3 &point) const {
214        Vector3 diff = point - mOrigin;
215        float t = DotProd(diff, GetDir());
216       
217    if ( t <= 0.0f ) {
218          t = 0.0f;
219    } else {
220          if (t >= 1.0f) {
221                t = 1.0f;
222          } else {
223        t /= SqrMagnitude(GetDir());
224          }
225          diff -= t*GetDir();
226        }
227    return SqrMagnitude(diff);
228  }
[1259]229
[1528]230  /** Returns the data sampled on either the ray origin or termination.
231  */
[1259]232  void GetSampleData(
233          const bool isTerminaton,
234          Vector3 &pt,
235          Intersectable **obj,
236          KdNode **node) const;
237
[1221]238  friend ostream& operator<< (ostream &s, const VssRay &vssRay);
239   
[372]240};
241
[1528]242inline void VssRay::GetSampleData(const bool isTermination,
243                                                                  Vector3 &pt,
244                                                                  Intersectable **obj,
245                                                                  KdNode **node) const
246{
247        if (isTermination)
248        {
249                pt = mTermination;
250                *obj = mTerminationObject;
251                *node = mTerminationNode;
252        }
253        else
254        {
255                pt = mOrigin;
256                *obj = mOriginObject;
257                *node = mOriginNode;
258        }
259}
260
[446]261void
262GenerateExtendedConvexCombinationWeights(float &w1,
263                                                                                 float &w2,
264                                                                                 float &w3,
265                                                                                 const float overlap
266                                                                                 );
[372]267
[464]268void
269GenerateExtendedConvexCombinationWeights2(float &w1,
270                                                                                  float &w2,
271                                                                                  const float overlap
272                                                                                  );
273
[1221]274// Overload << operator for C++-style output
275inline ostream&
276operator<< (ostream &s, const VssRay &vssRay)
277{
278        return s
279                << "(" << vssRay.mPass << ", " << vssRay.mOrigin << ", " << vssRay.mTermination
280                << ", " << vssRay.mOriginObject << ", " << vssRay.mTerminationObject << ", " << vssRay.mPdf << ")";
281}
282
[446]283// --------------------------------------------------------------
284// For sorting rays
285// --------------------------------------------------------------
[1528]286struct SortableEntry
[446]287{
288  enum EType {
289    ERayMin,
290    ERayMax
291  };
[372]292
[446]293  int type;
294  float value;
295  void *data;
296 
297  SortableEntry() {}
298  SortableEntry(const int t, const float v, void *d):type(t),
299                                                                                                         value(v),
300                                                                                                         data(d) {}
301       
302  friend bool operator<(const SortableEntry &a, const SortableEntry &b) {
303    return a.value < b.value;
304  }
305};
306
[467]307struct VssRayContainer : public vector<VssRay *>
308{
309  void PrintStatistics(ostream &s);
[1112]310  int SelectRays(const int number, VssRayContainer &selected, const bool copy=false) const;
[492]311  int
312  GetContributingRays(VssRayContainer &selected,
313                                          const int minPass
314                                          ) const;
315 
[467]316};
[372]317
[1715]318/*
319struct VssRayDistribution {
320  VssRayDistribution() { mContribution = -1.0f; }
321  SimpleRayContainer mRays;
322  vector<VssRayContainer> mVssRays;
323  float mContribution;
324  float mTime;
[863]325};
[372]326
[1715]327struct VssRayDistributionMixture {
328  VssRayDistributionMixture() {}
329 
330  vector<VssRayDistribution> distributions;
331};
332*/
333
334};
335
[372]336#endif
Note: See TracBrowser for help on using the repository browser.