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

Revision 1958, 3.4 KB checked in by mattausch, 18 years ago (diff)

debug version of global lines renderer

RevLine 
[162]1//#include <boost/algorithm/string.hpp>
2
3#include <stack>
4#include "SceneGraph.h"
5#include "X3dExporter.h"
[339]6#include "Intersectable.h"
[162]7
8
[863]9namespace GtpVisibilityPreprocessor {
[860]10
11
[162]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
[1328]30SceneGraphNode::~SceneGraphNode()
31{
32        CLEAR_CONTAINER(mGeometry);
33        // recursivly delete all children
34        CLEAR_CONTAINER(mChildren);
35}
36
37
38/************************************************************/
39/*                 SceneGraph implementation                */
40/************************************************************/
41
42
43SceneGraph::SceneGraph():
44mRoot(NULL)
45{
46}
47
48
[1002]49SceneGraph::~SceneGraph()
50{
51        DEL_PTR(mRoot);
52}
53
54
[1328]55SceneGraphNode *SceneGraph::GetRoot()
[1002]56{
[1328]57        return mRoot;
58}
[1002]59
[1328]60
61void SceneGraph::SetRoot(SceneGraphNode *root)
62{
63        mRoot = root;
[1002]64}
65
66
[162]67int
[176]68SceneGraph::CollectObjects(ObjectContainer *instances)
[162]69{
[490]70        instances->clear();
[1328]71        int number = 0;
[162]72
[1328]73        stack<SceneGraphNode *> nodeStack;
74        nodeStack.push(mRoot);
75
76        while (!nodeStack.empty()) {
77                SceneGraphNode *node = nodeStack.top();
78                nodeStack.pop();
[1344]79               
80                ObjectContainer::const_iterator mi = node->mGeometry.begin();
[1328]81                for (; mi != node->mGeometry.end(); mi++)
82                {
83                        instances->push_back(*mi);
84                }
[1344]85       
[1328]86                SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
87                for (; ni != node->mChildren.end(); ni++) {
[1344]88                        nodeStack.push(*ni);   
[1328]89                        number++;
90                }
91        }
[1344]92
[1328]93        return number;
[162]94}
[339]95
96
97int
98SceneGraph::AssignObjectIds()
99{
100  int id = 1;
101  stack<SceneGraphNode *> nodeStack;
102 
103  nodeStack.push(mRoot);
[1344]104
[339]105  while (!nodeStack.empty()) {
106    SceneGraphNode *node = nodeStack.top();
107    nodeStack.pop();
108               
[576]109    ObjectContainer::iterator mi = node->mGeometry.begin();
110    for (; mi != node->mGeometry.end(); mi++) {
[1344]111                (*mi)->SetId(id++);
[576]112        }
[339]113   
114    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
115    for (; ni != node->mChildren.end(); ni++) {
116      nodeStack.push(*ni);
117    }
118  }
[1344]119 
120  // return max id
[339]121  return id;
122}
[387]123
124void
125SceneGraph::GetStatistics(int &intersectables, int &faces) const
126{
127  stack<SceneGraphNode *> nodeStack;
128 
129  nodeStack.push(mRoot);
130  faces = 0;
131        intersectables = 0;
132  while (!nodeStack.empty()) {
133    SceneGraphNode *node = nodeStack.top();
134    nodeStack.pop();
135               
136    ObjectContainer::const_iterator mi = node->mGeometry.begin();
137    for (; mi != node->mGeometry.end(); mi++) {
138                        intersectables++;
139                        faces += (*mi)->NumberOfFaces();
140                }
141   
142    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
143    for (; ni != node->mChildren.end(); ni++) {
144      nodeStack.push(*ni);
145    }
146  }
147       
148}
[492]149
150
151void
152SceneGraphNode::UpdateBox()
153{
154  AxisAlignedBox3 box;
155 
156  box.Initialize();
157 
158  ObjectContainer::const_iterator mi = mGeometry.begin();
159  for (; mi != mGeometry.end(); mi++)
160        box.Include((*mi)->GetBox());
161 
162  SceneGraphNodeContainer::iterator ni = mChildren.begin();
163  for (; ni != mChildren.end(); ni++) {
164        (*ni)->UpdateBox();
165        box.Include((*ni)->mBox);
166  }
167 
168  mBox = box;
169}
[860]170
[1166]171
172void SceneGraph::ExportScene(const string filename)
173{
[1194]174       
[1166]175}
176
[1194]177
[1166]178void SceneGraph::LoadScene(const string filename)
179{
180        //  load binary version of mesh
181}
182
[1958]183
[860]184}
Note: See TracBrowser for help on using the repository browser.