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

Revision 1002, 3.1 KB checked in by mattausch, 18 years ago (diff)

debug run: fixing memory holes

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
[1002]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
[162]46int
[176]47SceneGraph::CollectObjects(ObjectContainer *instances)
[162]48{
[490]49        instances->clear();
[162]50  int number = 0;
51  stack<SceneGraphNode *> nodeStack;
[176]52 
[162]53  nodeStack.push(mRoot);
54 
55  while (!nodeStack.empty()) {
56    SceneGraphNode *node = nodeStack.top();
57    nodeStack.pop();
58
[176]59    ObjectContainer::const_iterator mi = node->mGeometry.begin();
[162]60    for (; mi != node->mGeometry.end(); mi++)
[490]61          instances->push_back(*mi);
62       
[162]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}
[339]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               
[576]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        }
[339]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}
[387]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}
[492]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}
[860]153
154}
Note: See TracBrowser for help on using the repository browser.