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

Revision 2014, 8.4 KB checked in by bittner, 17 years ago (diff)

timer start

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