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 |
|
---|
10 | bool
|
---|
11 | SceneGraph::Export( const string filename )
|
---|
12 | {
|
---|
13 | if (strstr(filename.c_str(), ".x3d")) {
|
---|
14 | X3dExporter exporter(filename);
|
---|
15 | exporter.ExportScene(mRoot);
|
---|
16 | return true;
|
---|
17 | } else {
|
---|
18 | cerr<<"Error: Currently unsuported export format, filename "<<filename<<endl;
|
---|
19 |
|
---|
20 | }
|
---|
21 |
|
---|
22 |
|
---|
23 | return false;
|
---|
24 |
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | int
|
---|
29 | SceneGraph::CollectObjects(ObjectContainer *instances)
|
---|
30 | {
|
---|
31 | instances->clear();
|
---|
32 | int number = 0;
|
---|
33 | stack<SceneGraphNode *> nodeStack;
|
---|
34 |
|
---|
35 | nodeStack.push(mRoot);
|
---|
36 |
|
---|
37 | while (!nodeStack.empty()) {
|
---|
38 | SceneGraphNode *node = nodeStack.top();
|
---|
39 | nodeStack.pop();
|
---|
40 |
|
---|
41 | ObjectContainer::const_iterator mi = node->mGeometry.begin();
|
---|
42 | for (; mi != node->mGeometry.end(); mi++)
|
---|
43 | instances->push_back(*mi);
|
---|
44 |
|
---|
45 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
46 | for (; ni != node->mChildren.end(); ni++) {
|
---|
47 | nodeStack.push(*ni);
|
---|
48 | number++;
|
---|
49 | }
|
---|
50 |
|
---|
51 | }
|
---|
52 | return number;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | int
|
---|
57 | SceneGraph::AssignObjectIds()
|
---|
58 | {
|
---|
59 | int id = 1;
|
---|
60 | stack<SceneGraphNode *> nodeStack;
|
---|
61 |
|
---|
62 | nodeStack.push(mRoot);
|
---|
63 |
|
---|
64 | while (!nodeStack.empty()) {
|
---|
65 | SceneGraphNode *node = nodeStack.top();
|
---|
66 | nodeStack.pop();
|
---|
67 |
|
---|
68 | ObjectContainer::const_iterator mi = node->mGeometry.begin();
|
---|
69 | for (; mi != node->mGeometry.end(); mi++)
|
---|
70 | (*mi)->SetId(id++);
|
---|
71 |
|
---|
72 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
73 | for (; ni != node->mChildren.end(); ni++) {
|
---|
74 | nodeStack.push(*ni);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | // return max id
|
---|
78 | return id;
|
---|
79 | }
|
---|
80 |
|
---|
81 | void
|
---|
82 | SceneGraph::GetStatistics(int &intersectables, int &faces) const
|
---|
83 | {
|
---|
84 | stack<SceneGraphNode *> nodeStack;
|
---|
85 |
|
---|
86 | nodeStack.push(mRoot);
|
---|
87 | faces = 0;
|
---|
88 | intersectables = 0;
|
---|
89 | while (!nodeStack.empty()) {
|
---|
90 | SceneGraphNode *node = nodeStack.top();
|
---|
91 | nodeStack.pop();
|
---|
92 |
|
---|
93 | ObjectContainer::const_iterator mi = node->mGeometry.begin();
|
---|
94 | for (; mi != node->mGeometry.end(); mi++) {
|
---|
95 | intersectables++;
|
---|
96 | faces += (*mi)->NumberOfFaces();
|
---|
97 | }
|
---|
98 |
|
---|
99 | SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
|
---|
100 | for (; ni != node->mChildren.end(); ni++) {
|
---|
101 | nodeStack.push(*ni);
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|