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