source: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp @ 1143

Revision 1143, 1.9 KB checked in by mattausch, 18 years ago (diff)

worked on vsp osp tree

Line 
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
10namespace GtpVisibilityPreprocessor {
11
12
13int KdPvs::Compress()
14{
15        return 0; // TODO
16}
17
18
19int 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
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.
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
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)
65                                        {
66                                                Intersectable *object = *oit;                                           
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
93}
Note: See TracBrowser for help on using the repository browser.