1 | #include <iostream>
|
---|
2 | #include <stack>
|
---|
3 | #include "Pvs.h"
|
---|
4 | #include "Intersectable.h"
|
---|
5 | #include "KdIntersectable.h"
|
---|
6 | #include "KdTree.h"
|
---|
7 | #include "common.h"
|
---|
8 |
|
---|
9 |
|
---|
10 | namespace GtpVisibilityPreprocessor {
|
---|
11 |
|
---|
12 |
|
---|
13 | int KdPvs::Compress()
|
---|
14 | {
|
---|
15 | return 0; // TODO
|
---|
16 | }
|
---|
17 |
|
---|
18 |
|
---|
19 | int ObjectPvs::CountObjectsInPvs() const
|
---|
20 | {
|
---|
21 | int pvs = 0;
|
---|
22 |
|
---|
23 | Intersectable::NewMail();
|
---|
24 | KdNode::NewMail();
|
---|
25 |
|
---|
26 | ObjectPvsMap::const_iterator it, it_end = mEntries.end();
|
---|
27 |
|
---|
28 | for (it = mEntries.begin(); it != it_end; ++ it)
|
---|
29 | {
|
---|
30 | Intersectable *obj = (*it).first;
|
---|
31 |
|
---|
32 | // found kd node
|
---|
33 | // the pvs is the number od different objects in the node leaves
|
---|
34 | // We eliminate already accounted kd nodes and objects using mailboxing.
|
---|
35 | if (obj->Type() == Intersectable::KD_INTERSECTABLE)
|
---|
36 | {
|
---|
37 | KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj);
|
---|
38 |
|
---|
39 | stack<KdNode *> tStack;
|
---|
40 |
|
---|
41 | tStack.push(kdObj->GetNode());
|
---|
42 |
|
---|
43 | while (!tStack.empty())
|
---|
44 | {
|
---|
45 | KdNode *node = tStack.top();
|
---|
46 | tStack.pop();
|
---|
47 |
|
---|
48 | // already processed node (= objects in pvs)?
|
---|
49 | if (!node->Mailed())
|
---|
50 | {
|
---|
51 | node->Mail();
|
---|
52 |
|
---|
53 | if (node->IsLeaf())
|
---|
54 | {
|
---|
55 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
56 |
|
---|
57 | // add #objects exclusivly in this node
|
---|
58 | pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size());
|
---|
59 |
|
---|
60 | // Objects already accounted for can only be found among those
|
---|
61 | // which are referenced in more than one leaf
|
---|
62 | ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end();
|
---|
63 |
|
---|
64 | for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit)
|
---|
65 | {
|
---|
66 | Intersectable *object = *oit;
|
---|
67 |
|
---|
68 | if (!object->Mailed())
|
---|
69 | {
|
---|
70 | object->Mail();
|
---|
71 | ++ pvs;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | else // traverse tree
|
---|
76 | {
|
---|
77 | KdInterior *interior = dynamic_cast<KdInterior *>(node);
|
---|
78 |
|
---|
79 | tStack.push(interior->mFront);
|
---|
80 | tStack.push(interior->mBack);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | else
|
---|
86 | {
|
---|
87 | ++ pvs;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | return pvs;
|
---|
92 | }
|
---|
93 |
|
---|
94 | } |
---|