Discussion:
How do I get a Bounding Box for a model - not one derived from Bounding Sphere?
Mark Hurry
2007-05-10 07:34:14 UTC
Permalink
Hi,



I’m trying to work out the best way to get a correct bounding box for a
complex model (terrain actually), not one based on a bounding sphere. My
model (openFlight) contains external references to other files and multiple
references to the same external files with transformation matrices. I have
tried walking the scenegraph nodes until I find a geode and then I expand my
bounding box with the results from the geode’s bounding box.



I am not getting the results I would expect. Do I need to maintain the
transform matrices and apply them to the geode’s bounding box before I
expand my resultant bounding box? Or is there an easier way?



Cheers



Mark



HYPERLINK "mailto:mark-y8BOj97i/***@public.gmane.org"mark-y8BOj97i/***@public.gmane.org

Tel +61 (0)89335 1239

Mob +61 (0)405 095 104




No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.6.5/793 - Release Date: 07-May-07
2:55 PM
Robert Osfield
2007-05-10 08:48:20 UTC
Permalink
Hi Mark,

The easist way would be to just on the culling
(Node::setCullingActive(false)) for that toplevel node (with the external
references) so all its children are alway traversed. Alternatively you
could compute the bounding sphere yourself by using a custom
Node::ComputeBoundingSphereCallback.
Hi,
I'm trying to work out the best way to get a correct bounding box for a
complex model (terrain actually), not one based on a bounding sphere. My
model (openFlight) contains external references to other files and multiple
references to the same external files with transformation matrices. I have
tried walking the scenegraph nodes until I find a geode and then I expand my
bounding box with the results from the geode's bounding box.
I am not getting the results I would expect. Do I need to maintain the
transform matrices and apply them to the geode's bounding box before I
expand my resultant bounding box? Or is there an easier way?
Cheers
Mark
Tel +61 (0)89335 1239
Mob +61 (0)405 095 104
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.6.5/793 - Release Date: 07-May-07
2:55 PM
_______________________________________________
osg-users mailing list
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
Paul Martz
2007-05-10 13:36:54 UTC
Permalink
Here's a bounding box NodeVisitor I've been using. It works well as long as
all your Transforms are MatrixTransforms and all your Drawables are
Geometry.
-Paul


class BoundingBoxVisitor : public osg::NodeVisitor
{
public:
BoundingBoxVisitor()
: osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN )
{
osg::Matrix m;
_m.push_back( m );
}
~BoundingBoxVisitor() {}

osg::BoundingBox getBound() { return _bb; }

virtual void apply( osg::Node& node )
{
traverse( node );
}
virtual void apply( osg::MatrixTransform& mt )
{
osg::Matrix m = mt.getMatrix();
pushTraversePop( m, (osg::Node&)mt );
}

virtual void apply( osg::Geode& geode )
{
unsigned int i;
for( i = 0; i < geode.getNumDrawables(); i++ )
{
osg::Geometry* geom = dynamic_cast<osg::Geometry
*>(geode.getDrawable(i));
if( !geom )
continue;

osg::BoundingBox bb = geom->getBound();
osg::Matrix c = _m.back();
osg::Vec3 v0 = bb._min * c;
osg::Vec3 v1 = bb._max * c;
_bb.expandBy( v0 );
_bb.expandBy( v1 );
}
}

protected:
void pushTraversePop( const osg::Matrix& m, osg::Node& node )
{
osg::Matrix c = _m.back();
_m.push_back( m*c );
traverse( node );
_m.pop_back();
}

osg::BoundingBox _bb;
std::vector<osg::Matrix> _m;
};
Robert Osfield
2007-05-10 14:34:47 UTC
Permalink
Hi Mark and Paul,
Post by Paul Martz
Here's a bounding box NodeVisitor I've been using. It works well as long as
all your Transforms are MatrixTransforms and all your Drawables are
Geometry.
Ooo difference type of answer to mine, looks like my speed reading to taking
me off on a different tangent...

BTW, there is now an osg::ComputeBoundsVisitor checked into SVN, see
include/osg/ComputeBoundsVisitor, its been there for a month or two. Its
addition came as part of the osgShadow work.

Robert.
Bradford, Chase
2007-05-10 15:57:36 UTC
Permalink
Robert and Paul



Have either of you found a good way of writing a visitor for computing
the bounding box that works on PagedLODs without children paged in? The
only mildly acceptable method I've found is forcing a read on the first
child then continuing traversal, but that's slow. I can also use the
center and radius information when its available, but then I get
bounding cubes.



Chase



________________________________

From: osg-users-bounces-O4jvQuzB+***@public.gmane.org
[mailto:osg-users-bounces-O4jvQuzB+***@public.gmane.org] On Behalf Of Robert
Osfield
Sent: Thursday, May 10, 2007 7:35 AM
To: osg users
Subject: Re: [osg-users] How do I get a Bounding Box for a model -
notonederived from Bounding Sphere?



Hi Mark and Paul,

On 5/10/07, Paul Martz <pmartz-kDTDvbsv3h0em74UV7g5/***@public.gmane.org> wrote:

Here's a bounding box NodeVisitor I've been using. It works well
as long as
all your Transforms are MatrixTransforms and all your Drawables
are
Geometry.


Ooo difference type of answer to mine, looks like my speed reading to
taking me off on a different tangent...

BTW, there is now an osg::ComputeBoundsVisitor checked into SVN, see
include/osg/ComputeBoundsVisitor, its been there for a month or two.
Its addition came as part of the osgShadow work.

Robert.
Robert Osfield
2007-05-10 16:23:32 UTC
Permalink
Have either of you found a good way of writing a visitor for computing the
bounding box that works on PagedLODs without children paged in? The only
mildly acceptable method I've found is forcing a read on the first child
then continuing traversal, but that's slow. I can also use the center and
radius information when its available, but then I get bounding cubes.
You can't know what isn't there, you have to load the subgraph if you
want its dimensions.

The only other way might be to use UserData to store a precompute bounding box.

Robert.

Loading...