[osg-users] Correct Size of boundingBox

2011-03-06 Thread Heiko Thiel
Hi,

I currently try to get correct height of a model. So I use a boundingBox. But 
my problem: it return the size without checking for a PositionAttitudeTransform.

My current hack is:


Code:
float getHeight(osg::Node* model) //return 1.4 on my example
{
float zMax;
osg::PositionAttitudeTransform* pat = 
dynamic_castosg::PositionAttitudeTransform*(model);

osg::ComputeBoundsVisitor boundsVisitor;
boundsVisitor.apply(*model);
osg::BoundingBox boundingBox = boundsVisitor.getBoundingBox();
if (pat)
{
osg::Vec3d scaleVec = pat-getScale();
zMax = boundingBox.zMax()*scaleVec.z();
}
else
{
zMax = boundingBox.zMax();
}

return zMax;
}



Is there a way to get correct bounding box without checking for 
PositionAttitudeTransform? I tried to optimize model before I check to remove 
the PositionAttitudeTransform. But it seems to not help.


Code:
float getHeight(osg::Node* model) //return 7.3 on my example
{
float zMax;
osgUtil::Optimizer optimizer;
optimizer.optimize(model);

osg::ComputeBoundsVisitor boundsVisitor;
boundsVisitor.apply(*model);
osg::BoundingBox boundingBox = boundsVisitor.getBoundingBox();
zMax = boundingBox.zMax();

return zMax;
}



Is there a clean solution?

Thank you!

Cheers,
Heiko

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=37368#37368





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Correct Size of boundingBox

2011-03-06 Thread Paul Martz

On 3/6/2011 1:15 PM, Heiko Thiel wrote:

Is there a way to get correct bounding box without checking for 
PositionAttitudeTransform? I tried to optimize model before I check to remove 
the PositionAttitudeTransform. But it seems to not help.


OSG supports multiparenting, so the subgraph you're trying to get the bound for 
could be rendered multiple times with multiple different transformations. In 
order to transform the bounding box, you need the NodePath representing your 
subgraph location in the overall scene graph (which you can get with, for 
example, a NodeVisitor). Then you call osg::computeLocalToWorld(NodePath) to 
obtain the transformation matrix. If you need help with this, try searching the 
examples source for osg::computeLocalToWorld.


Then you can transform the bounding box extents by the matrix, but this has its 
own issues in the presence of rotation transforms, as has been discussed 
previously on this list (search the archives for transform bounding box). But 
if your transforms are scales and translates, this is not an issue.


Hope that helps,
   -Paul
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Correct Size of boundingBox

2011-03-06 Thread Paul Martz

On 3/6/2011 2:02 PM, Paul Martz wrote:

Then you can transform the bounding box extents by the matrix, but this has its
own issues in the presence of rotation transforms, as has been discussed
previously on this list (search the archives for transform bounding box). But
if your transforms are scales and translates, this is not an issue.


As an additional note, I've written my own code to transform a BoundingBox (as 
OSG doesn't have one to my knowledge, at least not on 2.8.3), and this function 
is available in osgWorks. You can use osgWorks (osgworks.googlecode.com), or you 
can borrow the following code:


osg::BoundingBox
transform( const osg::Matrix m, const osg::BoundingBox box )
{
osg::Vec3 p0( box._min );
osg::Vec3 p1( box._max.x(), box._min.y(), box._min.z() );
osg::Vec3 p2( box._max.x(), box._min.y(), box._max.z() );
osg::Vec3 p3( box._min.x(), box._min.y(), box._max.z() );
osg::Vec3 p4( box._max );
osg::Vec3 p5( box._min.x(), box._max.y(), box._max.z() );
osg::Vec3 p6( box._min.x(), box._max.y(), box._min.z() );
osg::Vec3 p7( box._max.x(), box._max.y(), box._min.z() );

osg::BoundingBox newBox( p0 * m, p1 * m );
newBox.expandBy( p2 * m );
newBox.expandBy( p3 * m );
newBox.expandBy( p4 * m );
newBox.expandBy( p5 * m );
newBox.expandBy( p6 * m );
newBox.expandBy( p7 * m );

return( newBox );
}
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org