[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();
|
---|
[1176] | 24 | KdLeaf::NewMail();
|
---|
[1141] | 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)?
|
---|
[1184] | 49 | if (0 ||!node->Mailed())
|
---|
[1141] | 50 | {
|
---|
[1168] | 51 | node->Mail();
|
---|
[1141] | 52 |
|
---|
[1168] | 53 | if (node->IsLeaf())
|
---|
| 54 | {
|
---|
| 55 | KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
|
---|
[1184] | 56 | #if 1
|
---|
[1168] | 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 | }
|
---|
[1184] | 74 | #else
|
---|
| 75 | ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
|
---|
| 76 |
|
---|
| 77 | for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
|
---|
| 78 | {
|
---|
| 79 | Intersectable *object = *oit;
|
---|
| 80 |
|
---|
| 81 | if (!object->Mailed())
|
---|
| 82 | {
|
---|
| 83 | object->Mail();
|
---|
| 84 | ++ pvs;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | #endif
|
---|
[1141] | 88 | }
|
---|
[1168] | 89 | else // traverse tree
|
---|
| 90 | {
|
---|
| 91 | KdInterior *interior = dynamic_cast<KdInterior *>(node);
|
---|
[1141] | 92 |
|
---|
[1168] | 93 | tStack.push(interior->mFront);
|
---|
| 94 | tStack.push(interior->mBack);
|
---|
| 95 | }
|
---|
[1141] | 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | else
|
---|
| 100 | {
|
---|
| 101 | ++ pvs;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | return pvs;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[311] | 108 | } |
---|