source: GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp @ 1194

Revision 1194, 3.3 KB checked in by mattausch, 18 years ago (diff)
Line 
1//#include <boost/algorithm/string.hpp>
2
3#include <stack>
4#include "SceneGraph.h"
5#include "X3dExporter.h"
6#include "Intersectable.h"
7
8
9namespace GtpVisibilityPreprocessor {
10
11
12bool
13SceneGraph::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
30SceneGraph::~SceneGraph()
31{
32        DEL_PTR(mRoot);
33}
34
35
36SceneGraphNode::~SceneGraphNode()
37{
38        CLEAR_CONTAINER(mGeometry);
39        SceneGraphNodeContainer::iterator it, it_end = mChildren.end();
40
41        // recursivly delete all children
42        CLEAR_CONTAINER(mChildren);
43}
44
45
46int
47SceneGraph::CollectObjects(ObjectContainer *instances)
48{
49        instances->clear();
50  int number = 0;
51  stack<SceneGraphNode *> nodeStack;
52 
53  nodeStack.push(mRoot);
54 
55  while (!nodeStack.empty()) {
56    SceneGraphNode *node = nodeStack.top();
57    nodeStack.pop();
58
59    ObjectContainer::const_iterator mi = node->mGeometry.begin();
60    for (; mi != node->mGeometry.end(); mi++)
61          instances->push_back(*mi);
62       
63    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
64    for (; ni != node->mChildren.end(); ni++) {
65      nodeStack.push(*ni);
66      number++;
67    }
68   
69  }
70  return number;
71}
72
73
74int
75SceneGraph::AssignObjectIds()
76{
77  int id = 1;
78  stack<SceneGraphNode *> nodeStack;
79 
80  nodeStack.push(mRoot);
81 
82  while (!nodeStack.empty()) {
83    SceneGraphNode *node = nodeStack.top();
84    nodeStack.pop();
85               
86    ObjectContainer::iterator mi = node->mGeometry.begin();
87    for (; mi != node->mGeometry.end(); mi++) {
88          // $$ JB remove object id=2601 (for debugging purposes in atlanta scene)
89          if (1) //id != 2601)
90                (*mi)->SetId(id++);
91          else {
92                node->mGeometry.erase(mi);
93                --mi;
94                id++;
95          }
96        }
97   
98    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
99    for (; ni != node->mChildren.end(); ni++) {
100      nodeStack.push(*ni);
101    }
102  }
103        // return max id
104  return id;
105}
106
107void
108SceneGraph::GetStatistics(int &intersectables, int &faces) const
109{
110  stack<SceneGraphNode *> nodeStack;
111 
112  nodeStack.push(mRoot);
113  faces = 0;
114        intersectables = 0;
115  while (!nodeStack.empty()) {
116    SceneGraphNode *node = nodeStack.top();
117    nodeStack.pop();
118               
119    ObjectContainer::const_iterator mi = node->mGeometry.begin();
120    for (; mi != node->mGeometry.end(); mi++) {
121                        intersectables++;
122                        faces += (*mi)->NumberOfFaces();
123                }
124   
125    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
126    for (; ni != node->mChildren.end(); ni++) {
127      nodeStack.push(*ni);
128    }
129  }
130       
131}
132
133
134void
135SceneGraphNode::UpdateBox()
136{
137  AxisAlignedBox3 box;
138 
139  box.Initialize();
140 
141  ObjectContainer::const_iterator mi = mGeometry.begin();
142  for (; mi != mGeometry.end(); mi++)
143        box.Include((*mi)->GetBox());
144 
145  SceneGraphNodeContainer::iterator ni = mChildren.begin();
146  for (; ni != mChildren.end(); ni++) {
147        (*ni)->UpdateBox();
148        box.Include((*ni)->mBox);
149  }
150 
151  mBox = box;
152}
153
154
155void SceneGraph::ExportScene(const string filename)
156{
157       
158}
159
160
161void SceneGraph::LoadScene(const string filename)
162{
163        //  load binary version of mesh
164}
165
166}
Note: See TracBrowser for help on using the repository browser.