/* OpenSceneGraph example, osgintersection. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #ifndef VARIABLEDIVISION_H #define VARIABLEDIVISION_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace variabledivision { typedef int value_type; typedef std::vector< value_type > Indices; //#define VERBOSE_OUTPUT struct KDNode { KDNode(): first(0), second(0) {} KDNode(value_type f, value_type s): first(f), second(s) {} value_type first; value_type second; osg::BoundingBox bb; }; struct KDLeaf { KDLeaf(): first(0), second(0) {} KDLeaf(value_type f, value_type s): first(f), second(s) {} value_type first; value_type second; osg::BoundingBox bb; }; struct Triangle { Triangle(unsigned int p1, unsigned int p2, unsigned int p3): _p1(p1), _p2(p2), _p3(p3) {} bool operator < (const Triangle& rhs) const { if (_p1rhs._p1) return false; if (_p2rhs._p2) return false; return _p3 AxisStack; typedef std::vector< KDNode > KDNodeList; typedef std::vector< KDLeaf > KDLeafList; /// note, leafNum is negative to distinguish from nodeNum int addLeaf(const KDLeaf& leaf) { int num = _kdLeaves.size(); _kdLeaves.push_back(leaf); return -(num+1); } int replaceLeaf(int leafNum, const KDLeaf& leaf) { int num = -leafNum-1; if (num>_kdLeaves.size()-1) { osg::notify(osg::NOTICE)<<"Warning: replaceChild("<=0) { KDNode& node = tree._kdNodes[nodeIndex]; if (node.first) traverse(tree,node.first,level+1); else output(level+1)<<"empty left child()"<asGeometry(); if (geom) { geom->setShape(createKDTree(geom)); } } } KDTree* createKDTree(osg::Geometry* geometry); void computeDivisions(KDTree& kdTree); int divide(KDTree& kdTree, osg::BoundingBox& bb, int nodeIndex, unsigned int level); unsigned int _maxNumLevels; unsigned int _targetNumTrianglesPerLeaf; unsigned int _numVerticesProcessed; bool _processTriangles; }; } #endif