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 | using namespace std;
|
---|
10 |
|
---|
11 | namespace GtpVisibilityPreprocessor {
|
---|
12 |
|
---|
13 |
|
---|
14 | bool
|
---|
15 | SceneGraph::Export( const string filename )
|
---|
16 | {
|
---|
17 | if (strstr(filename.c_str(), ".x3d")) {
|
---|
18 | X3dExporter exporter(filename);
|
---|
19 | exporter.ExportScene(mRoot);
|
---|
20 | return true;
|
---|
21 | } else {
|
---|
22 | cerr<<"Error: Currently unsuported export format, filename "<<filename<<endl;
|
---|
23 |
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | return false;
|
---|
28 |
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | SceneGraphNode::~SceneGraphNode()
|
---|
33 | {
|
---|
34 | CLEAR_CONTAINER(mGeometry);
|
---|
35 | // recursivly delete all children
|
---|
36 | CLEAR_CONTAINER(mChildren);
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | /************************************************************/
|
---|
41 | /* SceneGraph implementation */
|
---|
42 | /************************************************************/
|
---|
43 |
|
---|
44 |
|
---|
45 | SceneGraph::SceneGraph():
|
---|
46 | mRoot(NULL)
|
---|
47 | {
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | SceneGraph::~SceneGraph()
|
---|
52 | {
|
---|
53 | DEL_PTR(mRoot);
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | SceneGraphNode *SceneGraph::GetRoot()
|
---|
58 | {
|
---|
59 | return mRoot;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | void SceneGraph::SetRoot(SceneGraphNode *root)
|
---|
64 | {
|
---|
65 | mRoot = root;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | int
|
---|
70 | SceneGraph::CollectObjects(ObjectContainer *instances)
|
---|
71 | {
|
---|
72 | instances->clear();
|
---|
73 | int number = 0;
|
---|
74 |
|
---|
75 | stack<SceneGraphNode *> nodeStack;
|
---|
76 | nodeStack.push(mRoot);
|
---|
77 |
|
---|
78 | while (!nodeStack.empty()) {
|
---|
79 | SceneGraphNode *node = nodeStack.top();
|
---|
80 | nodeStack.pop();
|
---|
81 |
|
---|
82 | ObjectContainer::const_iterator mi = node->mGeometry.begin();
|
---|
83 | for (; mi != node->mGeometry.end(); mi++)
|
---|
84 | {
|
---|
85 | instances->push_back(*mi);
|
---|
86 | }
|
---|
87 |
|
---|
88 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
89 | for (; ni != node->mChildren.end(); ni++) {
|
---|
90 | nodeStack.push(*ni);
|
---|
91 | number++;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | return number;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | int
|
---|
100 | SceneGraph::AssignObjectIds()
|
---|
101 | {
|
---|
102 | int id = 1;
|
---|
103 | stack<SceneGraphNode *> nodeStack;
|
---|
104 |
|
---|
105 | nodeStack.push(mRoot);
|
---|
106 |
|
---|
107 | while (!nodeStack.empty()) {
|
---|
108 | SceneGraphNode *node = nodeStack.top();
|
---|
109 | nodeStack.pop();
|
---|
110 |
|
---|
111 | ObjectContainer::iterator mi = node->mGeometry.begin();
|
---|
112 | for (; mi != node->mGeometry.end(); mi++) {
|
---|
113 | (*mi)->SetId(id++);
|
---|
114 | }
|
---|
115 |
|
---|
116 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
117 | for (; ni != node->mChildren.end(); ni++) {
|
---|
118 | nodeStack.push(*ni);
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | // return max id
|
---|
123 | return id;
|
---|
124 | }
|
---|
125 |
|
---|
126 | void
|
---|
127 | SceneGraph::GetStatistics(int &intersectables, int &faces) const
|
---|
128 | {
|
---|
129 | stack<SceneGraphNode *> nodeStack;
|
---|
130 |
|
---|
131 | nodeStack.push(mRoot);
|
---|
132 | faces = 0;
|
---|
133 | intersectables = 0;
|
---|
134 | while (!nodeStack.empty()) {
|
---|
135 | SceneGraphNode *node = nodeStack.top();
|
---|
136 | nodeStack.pop();
|
---|
137 |
|
---|
138 | ObjectContainer::const_iterator mi = node->mGeometry.begin();
|
---|
139 | for (; mi != node->mGeometry.end(); mi++) {
|
---|
140 | intersectables++;
|
---|
141 | faces += (*mi)->NumberOfFaces();
|
---|
142 | }
|
---|
143 |
|
---|
144 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
145 | for (; ni != node->mChildren.end(); ni++) {
|
---|
146 | nodeStack.push(*ni);
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | void
|
---|
154 | SceneGraphNode::UpdateBox()
|
---|
155 | {
|
---|
156 | AxisAlignedBox3 box;
|
---|
157 |
|
---|
158 | box.Initialize();
|
---|
159 |
|
---|
160 | ObjectContainer::const_iterator mi = mGeometry.begin();
|
---|
161 | for (; mi != mGeometry.end(); mi++)
|
---|
162 | box.Include((*mi)->GetBox());
|
---|
163 |
|
---|
164 | SceneGraphNodeContainer::iterator ni = mChildren.begin();
|
---|
165 | for (; ni != mChildren.end(); ni++) {
|
---|
166 | (*ni)->UpdateBox();
|
---|
167 | box.Include((*ni)->mBox);
|
---|
168 | }
|
---|
169 |
|
---|
170 | mBox = box;
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | void SceneGraph::ExportScene(const string filename)
|
---|
175 | {
|
---|
176 |
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | void SceneGraph::LoadScene(const string filename)
|
---|
181 | {
|
---|
182 | // load binary version of mesh
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | } |
---|