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

Revision 1328, 3.8 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
30SceneGraphNode::~SceneGraphNode()
31{
32        CLEAR_CONTAINER(mGeometry);
33       
34        // recursivly delete all children
35        CLEAR_CONTAINER(mChildren);
36}
37
38
39/************************************************************/
40/*                 SceneGraph implementation                */
41/************************************************************/
42
43
44SceneGraph::SceneGraph():
45mRoot(NULL)
46{
47}
48
49
50SceneGraph::~SceneGraph()
51{
52        DEL_PTR(mRoot);
53}
54
55
56SceneGraphNode *SceneGraph::GetRoot()
57{
58        return mRoot;
59}
60
61
62void SceneGraph::SetRoot(SceneGraphNode *root)
63{
64        mRoot = root;
65}
66
67
68int
69SceneGraph::CollectObjects(ObjectContainer *instances)
70{
71        instances->clear();
72        int number = 0;
73
74        stack<SceneGraphNode *> nodeStack;
75        nodeStack.push(mRoot);
76
77        while (!nodeStack.empty()) {
78                SceneGraphNode *node = nodeStack.top();
79                nodeStack.pop();
80                cout << "here3.958" << endl;cout << "here3.9587654" << endl;
81                ObjectContainer::const_iterator mi = node->mGeometry.begin();   cout << "here3.958" << endl;
82                for (; mi != node->mGeometry.end(); mi++)
83                {
84                        cout << "here3.9886" << endl;
85                        instances->push_back(*mi);
86                }
87                cout << "here3.969999" << endl;
88                SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
89                for (; ni != node->mChildren.end(); ni++) {
90                        nodeStack.push(*ni);    cout << "here3.959" << endl;
91                        number++;
92                }
93                cout << "here3.96" << endl;
94        }
95        return number;
96}
97
98
99int
100SceneGraph::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          // $$ JB remove object id=2601 (for debugging purposes in atlanta scene)
114          if (1) //id != 2601)
115                (*mi)->SetId(id++);
116          else {
117                node->mGeometry.erase(mi);
118                --mi;
119                id++;
120          }
121        }
122   
123    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
124    for (; ni != node->mChildren.end(); ni++) {
125      nodeStack.push(*ni);
126    }
127  }
128        // return max id
129  return id;
130}
131
132void
133SceneGraph::GetStatistics(int &intersectables, int &faces) const
134{
135  stack<SceneGraphNode *> nodeStack;
136 
137  nodeStack.push(mRoot);
138  faces = 0;
139        intersectables = 0;
140  while (!nodeStack.empty()) {
141    SceneGraphNode *node = nodeStack.top();
142    nodeStack.pop();
143               
144    ObjectContainer::const_iterator mi = node->mGeometry.begin();
145    for (; mi != node->mGeometry.end(); mi++) {
146                        intersectables++;
147                        faces += (*mi)->NumberOfFaces();
148                }
149   
150    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
151    for (; ni != node->mChildren.end(); ni++) {
152      nodeStack.push(*ni);
153    }
154  }
155       
156}
157
158
159void
160SceneGraphNode::UpdateBox()
161{
162  AxisAlignedBox3 box;
163 
164  box.Initialize();
165 
166  ObjectContainer::const_iterator mi = mGeometry.begin();
167  for (; mi != mGeometry.end(); mi++)
168        box.Include((*mi)->GetBox());
169 
170  SceneGraphNodeContainer::iterator ni = mChildren.begin();
171  for (; ni != mChildren.end(); ni++) {
172        (*ni)->UpdateBox();
173        box.Include((*ni)->mBox);
174  }
175 
176  mBox = box;
177}
178
179
180void SceneGraph::ExportScene(const string filename)
181{
182       
183}
184
185
186void SceneGraph::LoadScene(const string filename)
187{
188        //  load binary version of mesh
189}
190
191}
Note: See TracBrowser for help on using the repository browser.