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

Revision 576, 2.8 KB checked in by bittner, 19 years ago (diff)

rss preprocessor debugging + merge

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::iterator mi = node->mGeometry.begin();
68    for (; mi != node->mGeometry.end(); mi++) {
69          // $$ JB remove object id=2601 (for debugging purposes in atlanta scene)
70          if (1) //id != 2601)
71                (*mi)->SetId(id++);
72          else {
73                node->mGeometry.erase(mi);
74                --mi;
75                id++;
76          }
77        }
78   
79    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
80    for (; ni != node->mChildren.end(); ni++) {
81      nodeStack.push(*ni);
82    }
83  }
84        // return max id
85  return id;
86}
87
88void
89SceneGraph::GetStatistics(int &intersectables, int &faces) const
90{
91  stack<SceneGraphNode *> nodeStack;
92 
93  nodeStack.push(mRoot);
94  faces = 0;
95        intersectables = 0;
96  while (!nodeStack.empty()) {
97    SceneGraphNode *node = nodeStack.top();
98    nodeStack.pop();
99               
100    ObjectContainer::const_iterator mi = node->mGeometry.begin();
101    for (; mi != node->mGeometry.end(); mi++) {
102                        intersectables++;
103                        faces += (*mi)->NumberOfFaces();
104                }
105   
106    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
107    for (; ni != node->mChildren.end(); ni++) {
108      nodeStack.push(*ni);
109    }
110  }
111       
112}
113
114
115void
116SceneGraphNode::UpdateBox()
117{
118  AxisAlignedBox3 box;
119 
120  box.Initialize();
121 
122  ObjectContainer::const_iterator mi = mGeometry.begin();
123  for (; mi != mGeometry.end(); mi++)
124        box.Include((*mi)->GetBox());
125 
126  SceneGraphNodeContainer::iterator ni = mChildren.begin();
127  for (; ni != mChildren.end(); ni++) {
128        (*ni)->UpdateBox();
129        box.Include((*ni)->mBox);
130  }
131 
132  mBox = box;
133}
Note: See TracBrowser for help on using the repository browser.