2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2006-12-16 01:27:18 +08:00
|
|
|
required_range = nv.getDistanceToViewPoint(getCenter(),true);
|
2004-07-01 03:07:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::CullStack* cullStack = dynamic_cast<osg::CullStack*>(&nv);
|
2005-11-22 18:26:27 +08:00
|
|
|
if (cullStack && cullStack->getLODScale())
|
2004-07-01 03:07:05 +08:00
|
|
|
{
|
2005-11-22 18:08:00 +08:00
|
|
|
required_range = cullStack->clampedPixelSize(getBound()) / cullStack->getLODScale();
|
2004-07-01 03:07:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// fallback to selecting the highest res tile by
|
|
|
|
// finding out the max range
|
|
|
|
for(unsigned int i=0;i<_rangeList.size();++i)
|
|
|
|
{
|
2005-11-22 18:26:27 +08:00
|
|
|
required_range = osg::maximum(required_range,_rangeList[i].first);
|
2004-07-01 03:07:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
BoundingSphere LOD::computeBound() const
|
2004-07-01 21:53:30 +08:00
|
|
|
{
|
|
|
|
if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f)
|
|
|
|
{
|
2005-05-12 22:03:22 +08:00
|
|
|
return BoundingSphere(_userDefinedCenter,_radius);
|
2004-07-01 21:53:30 +08:00
|
|
|
}
|
|
|
|
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())
|
|
|
|
{
|
2005-11-10 17:42:34 +08:00
|
|
|
float maxRange = !_rangeList.empty() ? _rangeList.back().second : 0.0f;
|
2004-01-06 04:45:28 +08:00
|
|
|
|
|
|
|
_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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-05-02 17:45:31 +08:00
|
|
|
bool LOD::removeChildren( unsigned int pos,unsigned int numChildrenToRemove)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2006-05-02 17:45:31 +08:00
|
|
|
if (pos<_rangeList.size()) _rangeList.erase(_rangeList.begin()+pos, osg::minimum(_rangeList.begin()+(pos+numChildrenToRemove), _rangeList.end()) );
|
|
|
|
|
|
|
|
return Group::removeChildren(pos,numChildrenToRemove);
|
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;
|
|
|
|
}
|