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

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

worked on triangle processing. logical units will be created by grouping objects
using their visibility definitions.

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        // 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
49SceneGraph::~SceneGraph()
50{
51        DEL_PTR(mRoot);
52}
53
54
55SceneGraphNode *SceneGraph::GetRoot()
56{
57        return mRoot;
58}
59
60
61void SceneGraph::SetRoot(SceneGraphNode *root)
62{
63        mRoot = root;
64}
65
66
67int
68SceneGraph::CollectObjects(ObjectContainer *instances)
69{
70        instances->clear();
71        int number = 0;
72
73        stack<SceneGraphNode *> nodeStack;
74        nodeStack.push(mRoot);
75
76        while (!nodeStack.empty()) {
77                SceneGraphNode *node = nodeStack.top();
78                nodeStack.pop();
79               
80                ObjectContainer::const_iterator mi = node->mGeometry.begin();
81                for (; mi != node->mGeometry.end(); mi++)
82                {
83                        instances->push_back(*mi);
84                }
85       
86                SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
87                for (; ni != node->mChildren.end(); ni++) {
88                        nodeStack.push(*ni);   
89                        number++;
90                }
91        }
92
93        return number;
94}
95
96
97int
98SceneGraph::AssignObjectIds()
99{
100  int id = 1;
101  stack<SceneGraphNode *> nodeStack;
102 
103  nodeStack.push(mRoot);
104
105  while (!nodeStack.empty()) {
106    SceneGraphNode *node = nodeStack.top();
107    nodeStack.pop();
108               
109    ObjectContainer::iterator mi = node->mGeometry.begin();
110    for (; mi != node->mGeometry.end(); mi++) {
111                (*mi)->SetId(id++);
112        }
113   
114    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
115    for (; ni != node->mChildren.end(); ni++) {
116      nodeStack.push(*ni);
117    }
118  }
119 
120  // return max id
121  return id;
122}
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}
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}
170
171
172void SceneGraph::ExportScene(const string filename)
173{
174       
175}
176
177
178void SceneGraph::LoadScene(const string filename)
179{
180        //  load binary version of mesh
181}
182
183}
Note: See TracBrowser for help on using the repository browser.