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

Revision 534, 3.5 KB checked in by bittner, 18 years ago (diff)

vss preprocessor void space identification fixed - by default it is off

  • Property svn:executable set to *
RevLine 
[504]1#include "VssRay.h"
[511]2#include "Beam.h"
[504]3
4
5
6void
[513]7Beam::Construct(const  AxisAlignedBox3 &box, const  AxisAlignedBox3 &dBox)
[504]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));
[534]17 
[504]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
[534]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));
[504]29
30
31  // now make sure all planes contain the spatial box
32  int i, j;
33  for (i=0; i < mPlanes.size(); i++) {
34        for (j=0; j < 8; j++) {
35          float dist = mPlanes[i].Distance(box.GetVertex(j));
36          if (dist > 0)
37                mPlanes[i].mD -= dist;
38        }
39  }
[507]40
41  mBox = box;
42  mDirBox = dBox;
43 
44  SetValid();
[504]45}
46
47// conservative frustum box intersection
48// returns
49// 0 - box intersects the frustum
50// -1 - box intersects the frustum and is fully inside
51// 1 - box does not intersect the frustum
52
53int
[512]54Beam::ComputeIntersection(const AxisAlignedBox3 &box)
[504]55{
56  int i;
57  int result = -1;
58  for (i=0; i < mPlanes.size(); i++) {
59        int side = box.Side(mPlanes[i]);
60        if (side == 1)
61          return 1;
62        if (side > result)
63          result = side;
64  }
65  return result;
[522]66}
67
68
[525]69void Beam::ComputeFrustum(float &left, float &right,
[522]70                                                  float &bottom, float &top,
[525]71                                                  float &near, float &far,
72                                                  const AxisAlignedBox3 &sceneBBox) const
[522]73{
74        const float xDirRange = mDirBox.Max().x - mDirBox.Min().x;
75        const float yDirRange = mDirBox.Max().y - mDirBox.Min().y;
76
[531]77        near = 0.1f; // NOTE: what is the best value for near and far plane?
[525]78        far = 2.0f * Magnitude(sceneBBox.Diagonal());
[522]79
[531]80        left = near / tan(xDirRange * 0.5f);
81        right = near / tan(xDirRange * 0.5f);
[522]82
[531]83        bottom = near / tan(yDirRange * 0.5f);
84        top = near / tan(yDirRange * 0.5f);
[525]85}
86
87Vector3 Beam::GetMainDirection() const
88{
89         Vector3 directions[4];
90         
[531]91         directions[0] = VssRay::GetDirection(mDirBox.Min().x, mDirBox.Min().y);
92         directions[1] = VssRay::GetDirection(mDirBox.Max().x, mDirBox.Min().y);
93         directions[2] = VssRay::GetDirection(mDirBox.Max().x, mDirBox.Max().y);
94         directions[3] = VssRay::GetDirection(mDirBox.Min().x, mDirBox.Max().y);
[530]95
[526]96        const Vector3 mainDir = directions[0] + directions[1] + directions[2] + directions[3];
97        return Normalize(mainDir);
[531]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
[534]123}
124
Note: See TracBrowser for help on using the repository browser.