From d8482ef1ba2eb600b2915d0556131304103b0804 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 23 Jan 2014 16:48:29 +0000 Subject: [PATCH] From Kristofer Tingdahl,"we have a bunch of classes that inherit osg::Node, and they create their own, internal geometry which is passed into the render bucket at the cull-traversal. Last week, we realised that these classes are not accounted for when doing an ComputeBoundVisitor- traversal, as there is no specialization in ComputeBoundVisitor for them. One solution is naturally to create a new class that would inherit the osg::ComputeBoundVisitor, and use that. I don't like that idea as the ComputeBoundVisitor does actually have what I need - it is only hidden in a protected function. I am therefor suggesting a slight generalization of the ComputeBoundVisitor with the attached patch, which is tested. The patch has two parts: we add applyBBox() so that one can use that in a customized traverse-function and add a bbox to the visitor. I considered calling this function expandByBBox(), but I though applyBBox was better. The MatrixStack is made available to the outside world. That enables a traverse-function to do whatever it wishes. I do actually only need one of the two, as I can implement what I wish either way, but adding getMatrixStack() will make more generic expansions possible. " From Robert Osfield, changed the name of the new applyBBox(..) method to applyBoundingBox(..) to keep it's naming more consistent with the rest of the OSG. --- include/osg/ComputeBoundsVisitor | 5 ++++- src/osg/ComputeBoundsVisitor.cpp | 31 ++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/osg/ComputeBoundsVisitor b/include/osg/ComputeBoundsVisitor index 1efd859c2..c5b2cd6a8 100644 --- a/include/osg/ComputeBoundsVisitor +++ b/include/osg/ComputeBoundsVisitor @@ -48,10 +48,13 @@ public: void applyDrawable(osg::Drawable* drawable); -protected: + void applyBoundingBox(const osg::BoundingBox&); typedef std::vector MatrixStack; + const MatrixStack& getMatrixStack() const { return _matrixStack; } + +protected: MatrixStack _matrixStack; osg::BoundingBox _bb; }; diff --git a/src/osg/ComputeBoundsVisitor.cpp b/src/osg/ComputeBoundsVisitor.cpp index d9c1624cb..871a09ffb 100644 --- a/src/osg/ComputeBoundsVisitor.cpp +++ b/src/osg/ComputeBoundsVisitor.cpp @@ -77,21 +77,22 @@ void ComputeBoundsVisitor::apply(osg::Geode& geode) void ComputeBoundsVisitor::applyDrawable(osg::Drawable* drawable) { - if (_matrixStack.empty()) _bb.expandBy(drawable->getBound()); - else + applyBoundingBox(drawable->getBound()); +} + +void ComputeBoundsVisitor::applyBoundingBox(const osg::BoundingBox& bbox) +{ + if (_matrixStack.empty()) _bb.expandBy(bbox); + else if (bbox.valid()) { - osg::Matrix& matrix = _matrixStack.back(); - const osg::BoundingBox& dbb = drawable->getBound(); - if (dbb.valid()) - { - _bb.expandBy(dbb.corner(0) * matrix); - _bb.expandBy(dbb.corner(1) * matrix); - _bb.expandBy(dbb.corner(2) * matrix); - _bb.expandBy(dbb.corner(3) * matrix); - _bb.expandBy(dbb.corner(4) * matrix); - _bb.expandBy(dbb.corner(5) * matrix); - _bb.expandBy(dbb.corner(6) * matrix); - _bb.expandBy(dbb.corner(7) * matrix); - } + const osg::Matrix& matrix = _matrixStack.back(); + _bb.expandBy(bbox.corner(0) * matrix); + _bb.expandBy(bbox.corner(1) * matrix); + _bb.expandBy(bbox.corner(2) * matrix); + _bb.expandBy(bbox.corner(3) * matrix); + _bb.expandBy(bbox.corner(4) * matrix); + _bb.expandBy(bbox.corner(5) * matrix); + _bb.expandBy(bbox.corner(6) * matrix); + _bb.expandBy(bbox.corner(7) * matrix); } }