source: trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp @ 535

Revision 535, 3.2 KB checked in by mattausch, 18 years ago (diff)
  • Property svn:executable set to *
Line 
1#include "VssRay.h"
2#include "Beam.h"
3
4
5
6void
7Beam::Construct(const  AxisAlignedBox3 &box, const  AxisAlignedBox3 &dBox)
8{
9  // the frustum is defined by set of negative halfspace described by mPlanes
10 
11  // construct
12  Vector3 center = box.Center();
13  Vector3 dCenter = dBox.Center();
14
15  // "back plane"
16  mPlanes.push_back(Plane3(-VssRay::GetDirection(dCenter.x, dCenter.y), center));
17 
18  Vector3 directions[4];
19  directions[0] = VssRay::GetDirection(dBox.Min().x, dBox.Min().y);
20  directions[1] = VssRay::GetDirection(dBox.Max().x, dBox.Min().y);
21  directions[2] = VssRay::GetDirection(dBox.Max().x, dBox.Max().y);
22  directions[3] = VssRay::GetDirection(dBox.Min().x, dBox.Max().y);
23 
24  // side planes
25  mPlanes.push_back(Plane3(-CrossProd(directions[0], directions[1]), center));
26  mPlanes.push_back(Plane3(-CrossProd(directions[1], directions[2]), center));
27  mPlanes.push_back(Plane3(-CrossProd(directions[2], directions[3]), center));
28  mPlanes.push_back(Plane3(-CrossProd(directions[3], directions[0]), center));
29
30  // now make sure all planes contain the spatial box
31  int i, j;
32  for (i=0; i < mPlanes.size(); i++)
33  {
34          float maxDist = 0;
35         
36          for (j=0; j < 8; j++)
37          {
38                float dist = mPlanes[i].Distance(box.GetVertex(j));
39       
40                if (dist > maxDist)
41                        maxDist = dist;
42          }
43
44          mPlanes[i].mD -= maxDist;
45  }
46
47  mBox = box;
48  mDirBox = dBox;
49 
50  SetValid();
51}
52
53// conservative frustum box intersection
54// returns
55// 0 - box intersects the frustum
56// -1 - box intersects the frustum and is fully inside
57// 1 - box does not intersect the frustum
58
59int
60Beam::ComputeIntersection(const AxisAlignedBox3 &box)
61{
62  int i;
63  int result = -1;
64  for (i=0; i < mPlanes.size(); i++) {
65        int side = box.Side(mPlanes[i]);
66        if (side == 1)
67          return 1;
68        if (side > result)
69          result = side;
70  }
71  return result;
72}
73
74
75void Beam::ComputeFrustum(float &left, float &right,
76                                                  float &bottom, float &top,
77                                                  float &near, float &far,
78                                                  const AxisAlignedBox3 &sceneBBox) const
79{
80        const float xDirRange = mDirBox.Max().x - mDirBox.Min().x;
81        const float yDirRange = mDirBox.Max().y - mDirBox.Min().y;
82
83        near = 0.1f; // NOTE: what is the best value for near and far plane?
84        far = 2.0f * Magnitude(sceneBBox.Diagonal());
85
86        left = near / tan(xDirRange * 0.5f);
87        right = near / tan(xDirRange * 0.5f);
88
89        bottom = near / tan(yDirRange * 0.5f);
90        top = near / tan(yDirRange * 0.5f);
91}
92
93
94Vector3 Beam::GetMainDirection() const
95{
96        const Vector3 dCenter = mDirBox.Center();
97        return VssRay::GetDirection(dCenter.x, dCenter.y);
98}
99
100
101void BeamSampleStatistics::Print(ostream &app) const
102{
103  app << "===== Beam sample statistics ===============\n";
104
105  app << "#N_PVSSIZE ( size of pvs )\n" << pvsSize << "\n";
106
107  app << "#N_RAYS ( Number of rays )\n" << rays << "\n";
108
109  app << "#N_RAYCONTRIBUTIONS ( number of ray constributions )\n" <<
110    rayContributions << "\n";
111
112  app << "#N_RAYLENGHTENTROPY  ( Ray lenght entropy )\n" <<
113    rayLengthEntropy << "\n";
114
115  app << "#N_IMPORTANCE  ( importance )\n" <<
116    importance << "\n";
117
118  app << "#N_CTIME  ( Construction time [s] )\n"
119      << Time() << " \n";
120
121  app << "===== END OF KdTree statistics ==========\n";
122
123}
124
Note: See TracBrowser for help on using the repository browser.