1 | //#include <boost/algorithm/string.hpp>
|
---|
2 |
|
---|
3 | #include <stack>
|
---|
4 | #include "SceneGraph.h"
|
---|
5 | #include "X3dExporter.h"
|
---|
6 | #include "Intersectable.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 |
|
---|
12 | bool
|
---|
13 | SceneGraph::Export( const string filename )
|
---|
14 | {
|
---|
15 | if (strstr(filename.c_str(), ".x3d")) {
|
---|
16 | X3dExporter exporter(filename);
|
---|
17 | exporter.ExportScene(mRoot);
|
---|
18 | return true;
|
---|
19 | } else {
|
---|
20 | cerr<<"Error: Currently unsuported export format, filename "<<filename<<endl;
|
---|
21 |
|
---|
22 | }
|
---|
23 |
|
---|
24 |
|
---|
25 | return false;
|
---|
26 |
|
---|
27 | }
|
---|
28 |
|
---|
29 |
|
---|
30 | int
|
---|
31 | SceneGraph::CollectObjects(ObjectContainer *instances)
|
---|
32 | {
|
---|
33 | instances->clear();
|
---|
34 | int number = 0;
|
---|
35 | stack<SceneGraphNode *> nodeStack;
|
---|
36 |
|
---|
37 | nodeStack.push(mRoot);
|
---|
38 |
|
---|
39 | while (!nodeStack.empty()) {
|
---|
40 | SceneGraphNode *node = nodeStack.top();
|
---|
41 | nodeStack.pop();
|
---|
42 |
|
---|
43 | ObjectContainer::const_iterator mi = node->mGeometry.begin();
|
---|
44 | for (; mi != node->mGeometry.end(); mi++)
|
---|
45 | instances->push_back(*mi);
|
---|
46 |
|
---|
47 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
48 | for (; ni != node->mChildren.end(); ni++) {
|
---|
49 | nodeStack.push(*ni);
|
---|
50 | number++;
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|
54 | return number;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | int
|
---|
59 | SceneGraph::AssignObjectIds()
|
---|
60 | {
|
---|
61 | int id = 1;
|
---|
62 | stack<SceneGraphNode *> nodeStack;
|
---|
63 |
|
---|
64 | nodeStack.push(mRoot);
|
---|
65 |
|
---|
66 | while (!nodeStack.empty()) {
|
---|
67 | SceneGraphNode *node = nodeStack.top();
|
---|
68 | nodeStack.pop();
|
---|
69 |
|
---|
70 | ObjectContainer::iterator mi = node->mGeometry.begin();
|
---|
71 | for (; mi != node->mGeometry.end(); mi++) {
|
---|
72 | // $$ JB remove object id=2601 (for debugging purposes in atlanta scene)
|
---|
73 | if (1) //id != 2601)
|
---|
74 | (*mi)->SetId(id++);
|
---|
75 | else {
|
---|
76 | node->mGeometry.erase(mi);
|
---|
77 | --mi;
|
---|
78 | id++;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
83 | for (; ni != node->mChildren.end(); ni++) {
|
---|
84 | nodeStack.push(*ni);
|
---|
85 | }
|
---|
86 | }
|
---|
87 | // return max id
|
---|
88 | return id;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void
|
---|
92 | SceneGraph::GetStatistics(int &intersectables, int &faces) const
|
---|
93 | {
|
---|
94 | stack<SceneGraphNode *> nodeStack;
|
---|
95 |
|
---|
96 | nodeStack.push(mRoot);
|
---|
97 | faces = 0;
|
---|
98 | intersectables = 0;
|
---|
99 | while (!nodeStack.empty()) {
|
---|
100 | SceneGraphNode *node = nodeStack.top();
|
---|
101 | nodeStack.pop();
|
---|
102 |
|
---|
103 | ObjectContainer::const_iterator mi = node->mGeometry.begin();
|
---|
104 | for (; mi != node->mGeometry.end(); mi++) {
|
---|
105 | intersectables++;
|
---|
106 | faces += (*mi)->NumberOfFaces();
|
---|
107 | }
|
---|
108 |
|
---|
109 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
110 | for (; ni != node->mChildren.end(); ni++) {
|
---|
111 | nodeStack.push(*ni);
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | void
|
---|
119 | SceneGraphNode::UpdateBox()
|
---|
120 | {
|
---|
121 | AxisAlignedBox3 box;
|
---|
122 |
|
---|
123 | box.Initialize();
|
---|
124 |
|
---|
125 | ObjectContainer::const_iterator mi = mGeometry.begin();
|
---|
126 | for (; mi != mGeometry.end(); mi++)
|
---|
127 | box.Include((*mi)->GetBox());
|
---|
128 |
|
---|
129 | SceneGraphNodeContainer::iterator ni = mChildren.begin();
|
---|
130 | for (; ni != mChildren.end(); ni++) {
|
---|
131 | (*ni)->UpdateBox();
|
---|
132 | box.Include((*ni)->mBox);
|
---|
133 | }
|
---|
134 |
|
---|
135 | mBox = box;
|
---|
136 | }
|
---|
137 |
|
---|
138 | } |
---|