//#include #include #include "SceneGraph.h" #include "X3dExporter.h" #include "Intersectable.h" #include "IntersectableWrapper.h" //#include "ktball.h" using namespace std; namespace GtpVisibilityPreprocessor { bool SceneGraph::Export( const string filename ) { if (strstr(filename.c_str(), ".x3d")) { X3dExporter exporter(filename); exporter.ExportScene(mRoot); return true; } else { cerr<<"Error: Currently unsuported export format, filename "< nodeStack; nodeStack.push(mRoot); while (!nodeStack.empty()) { SceneGraphNode *node = nodeStack.top(); nodeStack.pop(); if (node->IsLeaf()) { SceneGraphLeaf *leaf = static_cast(node); ObjectContainer::const_iterator mi = leaf->mGeometry.begin(); for (; mi != leaf->mGeometry.end(); mi++) { instances.push_back(*mi); } } else { SceneGraphInterior *interior = static_cast(node); SceneGraphNodeContainer::iterator ni = interior->mChildren.begin(); for (; ni != interior->mChildren.end(); ++ ni) { nodeStack.push(*ni); number++; } } } return number; } int SceneGraph::AssignObjectIds() { // matt: rather start with id zero int id = 0; stack nodeStack; nodeStack.push(mRoot); while (!nodeStack.empty()) { SceneGraphNode *node = nodeStack.top(); nodeStack.pop(); if (node->IsLeaf()) { SceneGraphLeaf *leaf = static_cast(node); ObjectContainer::iterator mi = leaf->mGeometry.begin(); for (; mi != leaf->mGeometry.end(); mi ++) { (*mi)->SetId(id ++); } } else { SceneGraphInterior *interior = static_cast(node); SceneGraphNodeContainer::iterator ni = interior->mChildren.begin(); for (; ni != interior->mChildren.end(); ni ++) { nodeStack.push(*ni); } } } // return max id return id; } void SceneGraph::GetStatistics(int &intersectables, int &faces) const { stack nodeStack; nodeStack.push(mRoot); faces = 0; intersectables = 0; while (!nodeStack.empty()) { SceneGraphNode *node = nodeStack.top(); nodeStack.pop(); if (node->IsLeaf()) { SceneGraphLeaf *leaf = static_cast(node); ObjectContainer::const_iterator mi = leaf->mGeometry.begin(); for (; mi != leaf->mGeometry.end(); mi++) { intersectables++; faces += (*mi)->NumberOfFaces(); } } else { SceneGraphInterior *interior = static_cast(node); SceneGraphNodeContainer::iterator ni = interior->mChildren.begin(); for (; ni != interior->mChildren.end(); ni++) { nodeStack.push(*ni); } } } } void SceneGraphLeaf::UpdateBox() { AxisAlignedBox3 box; box.Initialize(); ObjectContainer::const_iterator mi = mGeometry.begin(); for (; mi != mGeometry.end(); mi++) box.Include((*mi)->GetBox()); mBox = box; } void SceneGraphInterior::UpdateBox() { AxisAlignedBox3 box; box.Initialize(); SceneGraphNodeContainer::iterator ni = mChildren.begin(); for (; ni != mChildren.end(); ++ ni) { (*ni)->UpdateBox(); box.Include((*ni)->GetBox()); } mBox = box; } void SceneGraph::ExportScene(const string filename) { } void SceneGraph::LoadScene(const string filename) { // load binary version of mesh } int SceneGraph::GetSize() const { stack nodeStack; nodeStack.push(mRoot); int size = 0; while (!nodeStack.empty()) { SceneGraphNode *node = nodeStack.top(); nodeStack.pop(); if (node->IsLeaf()) { SceneGraphLeaf *leaf = static_cast(node); size += (int)leaf->mGeometry.size(); } else { SceneGraphInterior *interior = static_cast(node); SceneGraphNodeContainer::iterator ni = interior->mChildren.begin(); for (; ni != interior->mChildren.end(); ni++) { nodeStack.push(*ni); } } } return size; } SceneGraphLeaf::SceneGraphLeaf(): mIsDynamic(false), mHasChanged(true), mDeleteGeometry(true) { mTrafo = IdentityMatrix(); mIntersectable = new SceneGraphLeafIntersectable(this, mBox); } SceneGraphLeaf::SceneGraphLeaf(bool isDynamic): mIsDynamic(isDynamic), mHasChanged(true), mDeleteGeometry(true) { mTrafo = IdentityMatrix(); mIntersectable = new SceneGraphLeafIntersectable(this, mBox); } void SceneGraphLeaf::ApplyTransform(const Matrix4x4 &trafo) { mHasChanged = true; mTrafo = trafo * mTrafo; } void SceneGraphLeaf::LoadTransform(const Matrix4x4 &m) { mHasChanged = true; mTrafo = m; } void SceneGraphLeaf::GetTransform(Matrix4x4 &m) const { m = mTrafo; } AxisAlignedBox3 SceneGraphLeaf::GetBox() const { return Transform(mBox, mTrafo); } AxisAlignedBox3 SceneGraphLeaf::GetOriginalBox() const { return mBox; } SceneGraphLeaf::SceneGraphLeaf(SceneGraphLeaf const& copy) { // hack: should just pass a IntersectableGroup as a whole // instead we duplicate the geometry vector mGeometry = copy.mGeometry; mBox = copy.mBox; mTrafo = copy.mTrafo; mIsDynamic = copy.mIsDynamic; mIntersectable = new SceneGraphLeafIntersectable(this, mBox); mHasChanged = true; // hack: the geometry should not be deleted here because this // is just a copy mDeleteGeometry = false; } }