Further work on Bound class/Node::getBound() and Drawable::getBound() and usage in OSG codebase

This commit is contained in:
Robert Osfield 2014-05-14 16:01:40 +00:00
parent ff21af2b0d
commit 74f91037a7
30 changed files with 239 additions and 213 deletions

View File

@ -303,7 +303,7 @@ bool DePee::createHUD()
osg::BoundingBox bb;
for(unsigned int i=0;i<geode->getNumDrawables();++i)
{
bb.expandBy(geode->getDrawable(i)->getBound());
bb.expandBy(geode->getDrawable(i)->getBoundingBox());
}
osg::Geometry* geom = new osg::Geometry;

View File

@ -151,7 +151,7 @@ osg::Camera* createHUD()
osg::BoundingBox bb;
for(unsigned int i=0;i<geode->getNumDrawables();++i)
{
bb.expandBy(geode->getDrawable(i)->getBound());
bb.expandBy(geode->getDrawable(i)->getBoundingBox());
}
osg::Geometry* geom = new osg::Geometry;

View File

@ -82,7 +82,11 @@ public:
// an attempt to return a reasonable bounding box. Still does not prevent clipping of the heat map.
virtual const osg::BoundingBox& getBoundingBox() const {return m_bounds;}
virtual osg::BoundingBox computeBoundingBox() const {return m_bounds;}
#ifdef OSG_USE_BOUND
virtual osg::Bound getBound() const { return osg::Bound(m_bounds, m_bounds); }
#else
virtual const osg::BoundingSphere& getBound() const {return m_bsphere;}
#endif
protected:
osg::BoundingBox m_bounds;

View File

@ -187,7 +187,7 @@ void PosterIntersector::reset()
void PosterIntersector::intersect( osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable )
{
if ( !_polytope.contains(drawable->getBound()) ) return;
if ( !_polytope.contains(drawable->getBoundingBox()) ) return;
if ( iv.getDoDummyTraversal() ) return;
// Find and collect all paged LODs in the node path

View File

@ -304,7 +304,7 @@ osg::Group* createHUDText()
text->setText("text->setFont(0); // inbuilt font.");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
{
@ -321,7 +321,7 @@ osg::Group* createHUDText()
"unable to load \"fonts/arial.ttf\"");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
{
@ -338,7 +338,7 @@ osg::Group* createHUDText()
"text->setFont(\"fonts/times.ttf\");":
"unable to load \"fonts/times.ttf\"");
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
cursor.x() = margin*2.0f;
@ -358,7 +358,7 @@ osg::Group* createHUDText()
"unable to load \"fonts/dirtydoz.ttf\"");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
{
@ -375,7 +375,7 @@ osg::Group* createHUDText()
"unable to load \"fonts/fudd.ttf\"");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
return rootNode;

View File

@ -300,7 +300,7 @@ osg::Group* createHUDText()
text->setText("text->setFont(0); // inbuilt font.");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
{
@ -317,7 +317,7 @@ osg::Group* createHUDText()
"unable to load \"fonts/arial.ttf\"");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
{
@ -334,7 +334,7 @@ osg::Group* createHUDText()
"text->setFont(\"fonts/times.ttf\");":
"unable to load \"fonts/times.ttf\"");
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
cursor.x() = margin*2.0f;
@ -354,7 +354,7 @@ osg::Group* createHUDText()
"unable to load \"fonts/dirtydoz.ttf\"");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
{
@ -371,7 +371,7 @@ osg::Group* createHUDText()
"unable to load \"fonts/fudd.ttf\"");
geode->addDrawable(text);
cursor.x() = text->getBound().xMax() + spacing ;
cursor.x() = text->getBoundingBox().xMax() + spacing ;
}
return rootNode;

View File

@ -271,12 +271,13 @@ class OSG_EXPORT CullingSet : public Referenced
return false;
}
#ifdef OSG_USE_BOUND
inline bool isCulled(const Bound& bound)
{
if (bound.bb) return isCulled(*bound.bb);
else return isCulled(*bound.bs);
}
#endif
inline void pushCurrentMask()
{
_frustum.pushCurrentMask();

View File

@ -128,6 +128,20 @@ class OSG_EXPORT Drawable : public Node
/** Set the initial bounding volume to use when computing the overall bounding volume.*/
const BoundingBox& getInitialBound() const { return _initialBound; }
#ifdef OSG_USE_BOUND
virtual Bound getBound() const
{
if(!_boundingSphereComputed) getBoundingBox();
return Bound(_boundingSphere, _boundingBox);
}
#else
inline const BoundingSphere& getBound() const
{
if(!_boundingSphereComputed) getBoundingBox();
return _boundingSphere;
}
#endif
/** Get BoundingBox of Drawable.
* If the BoundingBox is not up to date then its updated via an internal call to computeBond().
*/

View File

@ -437,7 +437,7 @@ class OSG_EXPORT Node : public Object
/** Get the bounding sphere of node.
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/
#ifdef OSG_USE_BOUND
inline Bound getBound() const
virtual Bound getBound() const
{
if(!_boundingSphereComputed)
{
@ -452,7 +452,7 @@ class OSG_EXPORT Node : public Object
return Bound(_boundingSphere);
}
#else
inline BoundingSphere getBound() const
inline const BoundingSphere& getBound() const
{
if(!_boundingSphereComputed)
{

View File

@ -317,7 +317,7 @@ BoundingSphere Billboard::computeBound() const
for( i = 0; i < ngsets; i++ )
{
const Drawable *gset = _drawables[i].get();
const BoundingBox& bbox = gset->getBound();
const BoundingBox& bbox = gset->getBoundingBox();
bsphere._center += bbox.center();
bsphere._center += _positionList[i];
@ -329,7 +329,7 @@ BoundingSphere Billboard::computeBound() const
for( i = 0; i < ngsets; ++i )
{
const Drawable *gset = _drawables[i].get();
const BoundingBox& bbox = gset->getBound();
const BoundingBox& bbox = gset->getBoundingBox();
Vec3 local_center = bsphere._center-_positionList[i];
for(unsigned int c=0;c<8;++c)
{

View File

@ -77,7 +77,7 @@ void ComputeBoundsVisitor::apply(osg::Geode& geode)
void ComputeBoundsVisitor::applyDrawable(osg::Drawable* drawable)
{
applyBoundingBox(drawable->getBound());
applyBoundingBox(drawable->getBoundingBox());
}
void ComputeBoundsVisitor::applyBoundingBox(const osg::BoundingBox& bbox)

View File

@ -204,7 +204,7 @@ BoundingSphere Geode::computeBound() const
itr!=_drawables.end();
++itr)
{
_bbox.expandBy((*itr)->getBound());
_bbox.expandBy((*itr)->getBoundingBox());
}
if (_bbox.valid())

View File

@ -369,7 +369,8 @@ BoundingSphere Group::computeBound() const
const osg::Transform* transform = (*itr)->asTransform();
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{
bb.expandBy((*itr)->getBound());
const osg::BoundingSphere& bs = (*itr)->getBound();
bb.expandBy(bs);
}
}

View File

@ -110,7 +110,7 @@ bool BuildKdTree::build(KdTree::BuildOptions& options, osg::Geometry* geometry)
if (vertices->size() <= options._targetNumTrianglesPerLeaf) return false;
_bb = geometry->getBound();
_bb = geometry->getBoundingBox();
_kdTree.setVertices(vertices);
unsigned int estimatedSize = (unsigned int)(2.0*float(vertices->size())/float(options._targetNumTrianglesPerLeaf));

View File

@ -196,7 +196,10 @@ BoundingSphere Switch::computeBound() const
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{
if( _values[pos] == true )
bb.expandBy(_children[pos]->getBound());
{
const osg::BoundingSphere& bs = _children[pos]->getBound();
bb.expandBy(bs);
}
}
}
@ -213,7 +216,10 @@ BoundingSphere Switch::computeBound() const
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{
if( _values[pos] == true )
bsphere.expandRadiusBy(static_cast<const BoundingSphere&>(_children[pos]->getBound()));
{
const osg::BoundingSphere& bs = _children[pos]->getBound();
bsphere.expandRadiusBy(bs);
}
}
}
return bsphere;

View File

@ -654,7 +654,7 @@ protected:
{
for (unsigned int i=0; i<billboard->getNumDrawables(); ++i)
{
osg::BoundingBox bb = billboard->getDrawable(i)->getBound();
const osg::BoundingBox& bb = billboard->getDrawable(i)->getBoundingBox();
billboard->setPosition(i,bb.center());
osgUtil::TransformAttributeFunctor tf(osg::Matrix::translate(-bb.center()));
@ -1168,7 +1168,7 @@ protected:
{
for (unsigned int i=0; i<billboard->getNumDrawables(); ++i)
{
osg::BoundingBox bb = billboard->getDrawable(i)->getBound();
const osg::BoundingBox& bb = billboard->getDrawable(i)->getBoundingBox();
billboard->setPosition(i,bb.center());
osgUtil::TransformAttributeFunctor tf(osg::Matrix::translate(-bb.center()));

View File

@ -4,7 +4,7 @@ WriterCompareTriangle::WriterCompareTriangle(const osg::Geode& geode,
unsigned int nbVertices)
: geode(geode)
{
cutscene(nbVertices, geode.getDrawable(0)->asGeometry()->getBound());
cutscene(nbVertices, geode.getDrawable(0)->asGeometry()->getBoundingBox());
}
bool

View File

@ -1074,7 +1074,7 @@ void* labelRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
{
osg::Group* group = new osg::Group;
osg::BoundingBox box = text->getBound();
const osg::BoundingBox& box = text->getBoundingBox();
float shift = box.radius()+1.f;
// front
@ -1518,8 +1518,8 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
case trpgBillboard::Individual:
{
// compute center of billboard geometry
const osg::BoundingBox& bbox = geometry->getBound();
osg::Vec3 center ((bbox._min + bbox._max) * 0.5f);
const osg::BoundingBox& bbox = geometry->getBoundingBox();
osg::Vec3 center (bbox.center());
// make billboard geometry coordinates relative to computed center
osg::Matrix matrix;

View File

@ -80,7 +80,7 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
cloned_ea->setTouchData(NULL);
// reproject mouse-coord
const osg::BoundingBox bb(hitr->drawable->getBound());
const osg::BoundingBox bb(hitr->drawable->getBoundingBox());
const osg::Vec3& p(hitr->localIntersectionPoint);
float transformed_x = (p.x() - bb.xMin()) / (bb.xMax() - bb.xMin());
@ -106,7 +106,7 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
// reproject touch-points
const osg::BoundingBox bb(hitr->drawable->getBound());
const osg::BoundingBox bb(hitr->drawable->getBoundingBox());
osg::Camera* camera = viewer->getCamera();
osg::Matrix matrix = osg::computeLocalToWorld(hitr->nodePath, false) * camera->getViewMatrix() * camera->getProjectionMatrix();

View File

@ -833,7 +833,7 @@ void SlideShowConstructor::addBullet(const std::string& bullet, PositionData& po
text->setText(bullet);
osg::BoundingBox bb = text->getBound();
const osg::BoundingBox& bb = text->getBoundingBox();
// note, this increment is only "correct" when text is on the plane of the slide..
// will need to make this more general later.
@ -882,7 +882,7 @@ void SlideShowConstructor::addParagraph(const std::string& paragraph, PositionDa
}
text->setText(paragraph);
osg::BoundingBox bb = text->getBound();
const osg::BoundingBox& bb = text->getBoundingBox();
// note, this increment is only "correct" when text is on the plane of the slide..
// will need to make this more general later.

View File

@ -264,7 +264,7 @@ osg::BoundingBox MinimalCullBoundsShadowMap::ViewData::ComputeRenderLeavesBounds
// Stay as long as possible in model space to minimize matrix ops
if( rl && rl->_modelview == modelview && rl->_projection == projection ){
bb.expandBy( rl->_drawable->getBound() );
bb.expandBy( rl->_drawable->getBoundingBox() );
} else {
if( bb.valid() ) {
// Conditions to avoid matrix multiplications
@ -292,7 +292,7 @@ osg::BoundingBox MinimalCullBoundsShadowMap::ViewData::ComputeRenderLeavesBounds
bbResult.expandBy( bb.corner( i ) * *ptrModelToWorld );
}
if( !rl ) break;
bb = rl->_drawable->getBound();
bb = rl->_drawable->getBoundingBox();
modelview = rl->_modelview;
projection = rl->_projection;
}
@ -331,7 +331,7 @@ osg::BoundingBox MinimalCullBoundsShadowMap::ViewData::ComputeRenderLeavesBounds
if(rl->_modelview == NULL )
rl->_drawable->dirtyBound();
bb = rl->_drawable->getBound();
bb = rl->_drawable->getBoundingBox();
if( !bb.valid() ) continue;
// Stay as long as possible in model space to minimize matrix ops

View File

@ -285,7 +285,7 @@ public:
{
if (node.getDrawable(i))
{
updateBound(node.getDrawable(i)->getBound());
updateBound(node.getDrawable(i)->getBoundingBox());
}
}
@ -1870,7 +1870,7 @@ struct RenderLeafBounds
// OSG_INFO<<"Reusing light_mvp "<<light_mvp<<std::endl;
}
const osg::BoundingBox& bb = renderLeaf->_drawable->getBound();
const osg::BoundingBox& bb = renderLeaf->_drawable->getBoundingBox();
if (bb.valid())
{
// OSG_NOTICE<<"checked extents of "<<renderLeaf->_drawable->getName()<<std::endl;

View File

@ -738,7 +738,7 @@ bool CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::B
bool CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::Drawable& drawable, bool isBillboard)
{
const osg::BoundingBox& bb = drawable.getBound();
const osg::BoundingBox& bb = drawable.getBoundingBox();
value_type d_near, d_far;
@ -981,7 +981,7 @@ void CullVisitor::apply(osg::Drawable& drawable)
{
RefMatrix& matrix = *getModelViewMatrix();
const BoundingBox &bb =drawable.getBound();
const BoundingBox &bb =drawable.getBoundingBox();
if( drawable.getCullCallback() )
{
@ -1085,7 +1085,7 @@ void CullVisitor::apply(Billboard& node)
node.computeMatrix(*billboard_matrix,eye_local,pos);
if (_computeNearFar && drawable->getBound().valid()) updateCalculatedNearFar(*billboard_matrix,*drawable,true);
if (_computeNearFar && drawable->getBoundingBox().valid()) updateCalculatedNearFar(*billboard_matrix,*drawable,true);
float depth = distance(pos,modelview);
/*
if (_computeNearFar)

View File

@ -590,7 +590,7 @@ bool IntersectVisitor::intersect(Drawable& drawable)
IntersectState* cis = _intersectStateStack.back().get();
const BoundingBox& bb = drawable.getBound();
const BoundingBox& bb = drawable.getBoundingBox();
for(IntersectState::LineSegmentList::iterator sitr=cis->_segList.begin();
sitr!=cis->_segList.end();

View File

@ -312,7 +312,7 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
if (reachedLimit()) return;
osg::Vec3d s(_start), e(_end);
if ( !intersectAndClip( s, e, drawable->getBound() ) ) return;
if ( !intersectAndClip( s, e, drawable->getBoundingBox() ) ) return;
if (iv.getDoDummyTraversal()) return;

View File

@ -2876,7 +2876,7 @@ bool Optimizer::SpatializeGroupsVisitor::divide(osg::Geode* geode, unsigned int
unsigned int i;
for(i=0; i<geode->getNumDrawables(); ++i)
{
bb.expandBy(geode->getDrawable(i)->getBound().center());
bb.expandBy(geode->getDrawable(i)->getBoundingBox().center());
}
float radius = bb.radius();

View File

@ -108,7 +108,7 @@ void RayIntersector::intersect(IntersectionVisitor& iv, Drawable* drawable)
// clip ray to finite line segment
Vec3d s(_start), e;
if (!intersectAndClip(s, _direction, e, drawable->getBound())) return;
if (!intersectAndClip(s, _direction, e, drawable->getBoundingBox())) return;
// dummy traversal
if (iv.getDoDummyTraversal()) return;

View File

@ -151,7 +151,7 @@ void HelpHandler::setUpScene(osgViewer::ViewerBase* viewer)
label->setPosition(pos);
label->setText(_applicationUsage->getDescription());
pos.x() = label->getBound().xMax();
pos.x() = label->getBoundingBox().xMax();
pos.y() -= characterSize*2.5f;
}

View File

@ -1149,7 +1149,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
frameRateLabel->setPosition(pos);
frameRateLabel->setText("Frame Rate: ");
pos.x() = frameRateLabel->getBound().xMax();
pos.x() = frameRateLabel->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> frameRateValue = new osgText::Text;
geode->addDrawable( frameRateValue.get() );
@ -1347,7 +1347,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
averageLabel->setPosition(pos);
averageLabel->setText("DatabasePager time to merge new tiles - average: ");
pos.x() = averageLabel->getBound().xMax();
pos.x() = averageLabel->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> averageValue = new osgText::Text;
_statsGeode->addDrawable( averageValue.get() );
@ -1358,7 +1358,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
averageValue->setPosition(pos);
averageValue->setText("1000");
pos.x() = averageValue->getBound().xMax() + 2.0f*_characterSize;
pos.x() = averageValue->getBoundingBox().xMax() + 2.0f*_characterSize;
osg::ref_ptr<osgText::Text> minLabel = new osgText::Text;
@ -1370,7 +1370,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
minLabel->setPosition(pos);
minLabel->setText("min: ");
pos.x() = minLabel->getBound().xMax();
pos.x() = minLabel->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> minValue = new osgText::Text;
_statsGeode->addDrawable( minValue.get() );
@ -1381,7 +1381,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
minValue->setPosition(pos);
minValue->setText("1000");
pos.x() = minValue->getBound().xMax() + 2.0f*_characterSize;
pos.x() = minValue->getBoundingBox().xMax() + 2.0f*_characterSize;
osg::ref_ptr<osgText::Text> maxLabel = new osgText::Text;
_statsGeode->addDrawable( maxLabel.get() );
@ -1392,7 +1392,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
maxLabel->setPosition(pos);
maxLabel->setText("max: ");
pos.x() = maxLabel->getBound().xMax();
pos.x() = maxLabel->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> maxValue = new osgText::Text;
_statsGeode->addDrawable( maxValue.get() );
@ -1403,7 +1403,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
maxValue->setPosition(pos);
maxValue->setText("1000");
pos.x() = maxValue->getBound().xMax();
pos.x() = maxValue->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> requestsLabel = new osgText::Text;
_statsGeode->addDrawable( requestsLabel.get() );
@ -1414,7 +1414,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
requestsLabel->setPosition(pos);
requestsLabel->setText("requests: ");
pos.x() = requestsLabel->getBound().xMax();
pos.x() = requestsLabel->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> requestList = new osgText::Text;
_statsGeode->addDrawable( requestList.get() );
@ -1425,7 +1425,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
requestList->setPosition(pos);
requestList->setText("0");
pos.x() = requestList->getBound().xMax() + 2.0f*_characterSize;;
pos.x() = requestList->getBoundingBox().xMax() + 2.0f*_characterSize;;
osg::ref_ptr<osgText::Text> compileLabel = new osgText::Text;
_statsGeode->addDrawable( compileLabel.get() );
@ -1436,7 +1436,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
compileLabel->setPosition(pos);
compileLabel->setText("tocompile: ");
pos.x() = compileLabel->getBound().xMax();
pos.x() = compileLabel->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> compileList = new osgText::Text;
_statsGeode->addDrawable( compileList.get() );
@ -1447,7 +1447,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
compileList->setPosition(pos);
compileList->setText("0");
pos.x() = maxLabel->getBound().xMax();
pos.x() = maxLabel->getBoundingBox().xMax();
_statsGeode->setCullCallback(new PagerCallback(dp, minValue.get(), maxValue.get(), averageValue.get(), requestList.get(), compileList.get(), 1000.0));
}
@ -1626,7 +1626,7 @@ void StatsHandler::createTimeStatsLine(const std::string& lineLabel,
label->setPosition(pos);
label->setText(lineLabel + ": ");
pos.x() = label->getBound().xMax();
pos.x() = label->getBoundingBox().xMax();
osg::ref_ptr<osgText::Text> value = new osgText::Text;
_statsGeode->addDrawable( value.get() );

View File

@ -141,7 +141,7 @@ void Label::setShadow(point_type offset) {
}
XYCoord Label::getTextSize() const {
osg::BoundingBox bb = _text->getBound();
const osg::BoundingBox& bb = _text->getBoundingBox();
return XYCoord(
osg::round(bb.xMax() - bb.xMin()),