[177] | 1 | #include <iostream>
|
---|
[1141] | 2 | #include <stack>
|
---|
[177] | 3 | #include "Pvs.h"
|
---|
[1141] | 4 | #include "Intersectable.h"
|
---|
| 5 | #include "KdIntersectable.h"
|
---|
| 6 | #include "KdTree.h"
|
---|
| 7 | #include "common.h"
|
---|
[177] | 8 |
|
---|
[1141] | 9 |
|
---|
[863] | 10 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 11 |
|
---|
[1141] | 12 |
|
---|
| 13 | int KdPvs::Compress()
|
---|
[177] | 14 | {
|
---|
[311] | 15 | return 0; // TODO
|
---|
[860] | 16 | }
|
---|
| 17 |
|
---|
[1141] | 18 |
|
---|
| 19 | int ObjectPvs::CountPvs() 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 |
|
---|
[1143] | 32 | // found kd node
|
---|
| 33 | // the pvs is the sum of the objects in the leaves in the subtree
|
---|
| 34 | // We eliminate already accounted kd nodes and objects
|
---|
| 35 | // using mailboxing.
|
---|
[1141] | 36 | if (obj->Type() == Intersectable::KD_INTERSECTABLE)
|
---|
| 37 | {
|
---|
| 38 | KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj);
|
---|
| 39 |
|
---|
| 40 | stack<KdNode *> tStack;
|
---|
| 41 |
|
---|
| 42 | tStack.push(kdObj->GetNode());
|
---|
| 43 |
|
---|
| 44 | while (!tStack.empty())
|
---|
| 45 | {
|
---|
| 46 | KdNode *node = tStack.top();
|
---|
| 47 | tStack.pop();
|
---|
| 48 |
|
---|
| 49 | // already processed node (objects in pvs)
|
---|
| 50 | if (node->Mailed())
|
---|
| 51 | continue;
|
---|
| 52 |
|
---|
| 53 | node->Mail();
|
---|
| 54 |
|
---|
| 55 | if (node->IsLeaf())
|
---|
| 56 | {
|
---|
| 57 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
| 58 |
|
---|
| 59 | pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size());
|
---|
| 60 |
|
---|
[1143] | 61 | // Objects already accounted for can only be found among those
|
---|
| 62 | // which are referenced in more than one leaf
|
---|
| 63 | ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end();
|
---|
| 64 | for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit)
|
---|
[1141] | 65 | {
|
---|
[1143] | 66 | Intersectable *object = *oit;
|
---|
[1141] | 67 |
|
---|
| 68 | if (!object->Mailed())
|
---|
| 69 | {
|
---|
| 70 | object->Mail();
|
---|
| 71 | ++ pvs;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | else
|
---|
| 76 | {
|
---|
| 77 | KdInterior *interior = dynamic_cast<KdInterior *>(node);
|
---|
| 78 |
|
---|
| 79 | tStack.push(interior->mFront);
|
---|
| 80 | tStack.push(interior->mBack);
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | else
|
---|
| 85 | {
|
---|
| 86 | ++ pvs;
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return pvs;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[311] | 93 | } |
---|