source: trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp @ 492

Revision 492, 2.7 KB checked in by bittner, 19 years ago (diff)

Large merge - viewcells seem not functional now

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