2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/LOD>
|
2004-07-01 03:07:05 +08:00
|
|
|
#include <osg/CullStack>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2003-07-10 22:53:07 +08:00
|
|
|
LOD::LOD():
|
2004-07-05 15:42:46 +08:00
|
|
|
_centerMode(USE_BOUNDING_SPHERE_CENTER),
|
|
|
|
_radius(-1.0f),
|
|
|
|
_rangeMode(DISTANCE_FROM_EYE_POINT)
|
2003-07-10 22:53:07 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
LOD::LOD(const LOD& lod,const CopyOp& copyop):
|
|
|
|
Group(lod,copyop),
|
2002-10-07 04:33:13 +08:00
|
|
|
_centerMode(lod._centerMode),
|
|
|
|
_userDefinedCenter(lod._userDefinedCenter),
|
2004-07-01 21:53:30 +08:00
|
|
|
_radius(lod._radius),
|
2004-07-05 15:42:46 +08:00
|
|
|
_rangeMode(lod._rangeMode),
|
2002-10-07 04:33:13 +08:00
|
|
|
_rangeList(lod._rangeList)
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
void LOD::traverse(NodeVisitor& nv)
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
switch(nv.getTraversalMode())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
case(NodeVisitor::TRAVERSE_ALL_CHILDREN):
|
|
|
|
std::for_each(_children.begin(),_children.end(),NodeAcceptOp(nv));
|
|
|
|
break;
|
|
|
|
case(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN):
|
2002-10-07 04:33:13 +08:00
|
|
|
{
|
2004-07-01 03:07:05 +08:00
|
|
|
float required_range = 0;
|
|
|
|
if (_rangeMode==DISTANCE_FROM_EYE_POINT)
|
|
|
|
{
|
|
|
|
required_range = nv.getDistanceToEyePoint(getCenter(),true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::CullStack* cullStack = dynamic_cast<osg::CullStack*>(&nv);
|
|
|
|
if (cullStack)
|
|
|
|
{
|
|
|
|
required_range = cullStack->pixelSize(getBound());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// fallback to selecting the highest res tile by
|
|
|
|
// finding out the max range
|
|
|
|
for(unsigned int i=0;i<_rangeList.size();++i)
|
|
|
|
{
|
|
|
|
required_range = osg::minimum(required_range,_rangeList[i].first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-07 04:33:13 +08:00
|
|
|
unsigned int numChildren = _children.size();
|
|
|
|
if (_rangeList.size()<numChildren) numChildren=_rangeList.size();
|
2004-07-01 03:07:05 +08:00
|
|
|
|
2002-10-07 04:33:13 +08:00
|
|
|
for(unsigned int i=0;i<numChildren;++i)
|
|
|
|
{
|
2004-07-01 03:07:05 +08:00
|
|
|
if (_rangeList[i].first<=required_range && required_range<_rangeList[i].second)
|
2002-10-07 04:33:13 +08:00
|
|
|
{
|
|
|
|
_children[i]->accept(nv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
default:
|
|
|
|
break;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-01 21:53:30 +08:00
|
|
|
bool LOD::computeBound() const
|
|
|
|
{
|
|
|
|
if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f)
|
|
|
|
{
|
|
|
|
_bsphere._center = _userDefinedCenter;
|
|
|
|
_bsphere._radius = _radius;
|
|
|
|
_bsphere_computed = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Group::computeBound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-07 04:33:13 +08:00
|
|
|
bool LOD::addChild( Node *child )
|
2002-10-08 05:23:37 +08:00
|
|
|
{
|
2002-10-09 00:02:09 +08:00
|
|
|
if (Group::addChild(child))
|
|
|
|
{
|
|
|
|
|
2004-01-06 04:45:28 +08:00
|
|
|
if (_children.size()>_rangeList.size())
|
|
|
|
{
|
|
|
|
float maxRange = !_rangeList.empty()?
|
|
|
|
maxRange=_rangeList.back().second : 0.0f;
|
|
|
|
|
|
|
|
_rangeList.resize(_children.size(),MinMaxPair(maxRange,maxRange));
|
|
|
|
}
|
2002-10-09 00:02:09 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2002-10-08 05:23:37 +08:00
|
|
|
}
|
|
|
|
|
2004-01-06 04:45:28 +08:00
|
|
|
void LOD::childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/)
|
|
|
|
{
|
|
|
|
//std::cout<<"LOD::childRemoved("<<pos<<","<<numChildrenToRemove<<")"<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LOD::childInserted(unsigned int /*pos*/)
|
|
|
|
{
|
|
|
|
//std::cout<<"LOD::childInserted("<<pos<<")"<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-08 05:23:37 +08:00
|
|
|
bool LOD::addChild(Node *child, float min, float max)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-10-07 04:33:13 +08:00
|
|
|
if (Group::addChild(child))
|
|
|
|
{
|
2002-10-08 05:23:37 +08:00
|
|
|
if (_children.size()>_rangeList.size()) _rangeList.resize(_children.size(),MinMaxPair(min,min));
|
|
|
|
_rangeList[_children.size()-1].first = min;
|
|
|
|
_rangeList[_children.size()-1].second = max;
|
2002-10-07 04:33:13 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2002-10-07 04:33:13 +08:00
|
|
|
bool LOD::removeChild( Node *child )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-10-07 04:33:13 +08:00
|
|
|
// find the child's position.
|
2002-11-21 17:07:11 +08:00
|
|
|
unsigned int pos=getChildIndex(child);
|
2002-10-07 04:33:13 +08:00
|
|
|
if (pos==_children.size()) return false;
|
|
|
|
|
|
|
|
_rangeList.erase(_rangeList.begin()+pos);
|
|
|
|
|
|
|
|
return Group::removeChild(child);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2002-10-07 04:33:13 +08:00
|
|
|
void LOD::setRange(unsigned int childNo, float min,float max)
|
|
|
|
{
|
|
|
|
if (childNo>=_rangeList.size()) _rangeList.resize(childNo+1,MinMaxPair(min,min));
|
|
|
|
_rangeList[childNo].first=min;
|
|
|
|
_rangeList[childNo].second=max;
|
|
|
|
}
|