[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 |
|
---|
[1168] | 19 | int ObjectPvs::CountObjectsInPvs() const
|
---|
[1141] | 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
|
---|
[1168] | 33 | // the pvs is the number od different objects in the node leaves
|
---|
| 34 | // We eliminate already accounted kd nodes and objects using mailboxing.
|
---|
[1141] | 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 |
|
---|
[1168] | 48 | // already processed node (= objects in pvs)?
|
---|
| 49 | if (!node->Mailed())
|
---|
[1141] | 50 | {
|
---|
[1168] | 51 | node->Mail();
|
---|
[1141] | 52 |
|
---|
[1168] | 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());
|
---|
[1141] | 59 |
|
---|
[1168] | 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();
|
---|
[1141] | 63 |
|
---|
[1168] | 64 | for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit)
|
---|
[1141] | 65 | {
|
---|
[1168] | 66 | Intersectable *object = *oit;
|
---|
| 67 |
|
---|
| 68 | if (!object->Mailed())
|
---|
| 69 | {
|
---|
| 70 | object->Mail();
|
---|
| 71 | ++ pvs;
|
---|
| 72 | }
|
---|
[1141] | 73 | }
|
---|
| 74 | }
|
---|
[1168] | 75 | else // traverse tree
|
---|
| 76 | {
|
---|
| 77 | KdInterior *interior = dynamic_cast<KdInterior *>(node);
|
---|
[1141] | 78 |
|
---|
[1168] | 79 | tStack.push(interior->mFront);
|
---|
| 80 | tStack.push(interior->mBack);
|
---|
| 81 | }
|
---|
[1141] | 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | else
|
---|
| 86 | {
|
---|
| 87 | ++ pvs;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | return pvs;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[311] | 94 | } |
---|