From e2ae39c8f69466d26ea4adccceefcc02b5cb5db8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 3 Jul 2008 17:18:14 +0000 Subject: [PATCH] Introduced bounding boxes to KDLeaf and KDNode structs --- examples/osgkdtree/variabledivision.cpp | 1 + examples/osgkdtree/variabledivision.h | 47 +++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/examples/osgkdtree/variabledivision.cpp b/examples/osgkdtree/variabledivision.cpp index ec3751d44..f8465b413 100644 --- a/examples/osgkdtree/variabledivision.cpp +++ b/examples/osgkdtree/variabledivision.cpp @@ -299,6 +299,7 @@ int KDTreeBuilder::divide(KDTree& kdTree, osg::BoundingBox& bb, int nodeIndex, u kdTree.getNode(nodeNum).first = leftChildIndex; kdTree.getNode(nodeNum).second = rightChildIndex; + return nodeNum; } diff --git a/examples/osgkdtree/variabledivision.h b/examples/osgkdtree/variabledivision.h index 7a8573918..72eccf48b 100644 --- a/examples/osgkdtree/variabledivision.h +++ b/examples/osgkdtree/variabledivision.h @@ -51,8 +51,38 @@ typedef std::vector< value_type > Indices; //#define VERBOSE_OUTPUT -typedef std::pair< value_type, value_type> KDNode; -typedef std::pair< value_type, value_type> KDLeaf; +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 { @@ -135,6 +165,19 @@ class KDTree : public osg::Shape } return _kdNodes[nodeNum]; } + + osg::BoundingBox& getBounindingBox(int nodeNum) + { + if (nodeNum<0) + { + int num = -nodeNum-1; + return _kdLeaves[num].bb; + } + else + { + return _kdNodes[nodeNum].bb; + } + } typedef std::vector< osg::BoundingBox > BoundingBoxList;