source: GTP/trunk/Lib/Vis/Preprocessing/src/SimpleRay.h @ 2726

Revision 2726, 2.9 KB checked in by mattausch, 16 years ago (diff)

worked on gvs efficiency

Line 
1#ifndef __SIMPLERAY_H__
2#define __SIMPLERAY_H__
3
4#include <vector>
5using namespace std;
6#include "Vector3.h"
7#include "Ray.h"
8
9namespace GtpVisibilityPreprocessor {
10
11class Intersectable;
12
13// This is the result of ray tracing with a simple ray
14struct IntersectionStr {
15  Intersectable *intersectable;
16  float          tdist;
17  float          maxt;
18  int            pad1; // aligned to 16 bytes
19};
20 
21struct SimpleRay
22{
23  // This is stored result for the rays in the container
24  // having 16 rays - shooting rays in both directions
25  static IntersectionStr IntersectionRes[32];
26 
27  Vector3 mOrigin;
28  Vector3 mDirection;
29  // 6*4 = 24B
30
31  Intersectable *mOriginObject;
32  Intersectable *mTerminationObject;
33  // 2*4 = 8B
34
35  enum {F_BIDIRECTIONAL = 1};
36  unsigned short mFlags;
37  unsigned char mType;
38  unsigned char mDistribution;
39  // 4B
40
41  // generator Id -> relative to the generating distribution!
42  int mGeneratorId;
43  // 4B
44
45  // TOTAL = 40B - aligned by 8 Bytes only! - it might be
46  // padding to 48 Bytes here !
47
48
49  //float mWeight;
50 
51  SimpleRay(): mType(Ray::LOCAL_RAY)
52  {
53  }
54 
55  SimpleRay(const Vector3 &o,
56                        const Vector3 &d,
57                        unsigned char distribution,
58                        float weight,
59                        unsigned char flags = F_BIDIRECTIONAL
60                        ):
61    mOrigin(o),
62    mDirection(d),
63    mFlags(flags),
64    mType(Ray::LOCAL_RAY),
65    mDistribution(distribution)
66    //  , mWeight(weight)
67  {     
68    //  mId = sSimpleRayId++;
69  }
70
71  void
72  Set(const Vector3 &o,
73      const Vector3 &d,
74      const unsigned char distribution,
75      const float weight,
76      const unsigned char flags = F_BIDIRECTIONAL
77      )
78  {
79    mOrigin = o;
80    mDirection = d,
81    mFlags = flags;
82    mType = Ray::LOCAL_RAY;
83    mDistribution = distribution;
84    //  , mWeight(weight)
85    //  mId = sSimpleRayId++;
86  }
87 
88  bool IsBidirectional() const { return mFlags & F_BIDIRECTIONAL; }
89
90  void SetBidirectional(const bool b) {
91    if (b)
92      mFlags |= F_BIDIRECTIONAL;
93    else
94      mFlags &= ~F_BIDIRECTIONAL;
95  }
96 
97  float GetParam(const int axis) const {
98    if (axis < 3)
99      return mOrigin[axis];
100    else
101      return mDirection[axis-3];
102  }
103 
104  Vector3 Extrap(const float t) const {
105    return mOrigin + mDirection * t;
106  }
107
108  friend std::ostream &operator<<(std::ostream &s, const SimpleRay &r)
109  {
110    return s << "origin=" << r.mOrigin << " dir=" << r.mDirection;
111  };
112};
113
114class SimpleRayContainer : public vector<SimpleRay>
115{
116public:
117   
118  SimpleRayContainer():vector<SimpleRay>() {}
119 
120#if 0
121  void NormalizePdf(float scale = 1.0f) {
122        iterator it = begin();
123        float sumPdf = 0.0f;
124        for (; it != end(); it++)
125          sumPdf += (*it).mPdf;
126       
127        float c = scale/sumPdf;
128       
129        for (it = begin(); it != end(); it++) {
130          (*it).mPdf*=c;
131  }
132  }
133#endif
134 
135  void AddRay(const SimpleRay &ray) {
136        push_back(ray);
137  }
138};
139
140
141
142}
143
144#endif
145
Note: See TracBrowser for help on using the repository browser.