2009-01-14 23:16:29 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
|
2008-09-21 19:05:03 +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.
|
|
|
|
*/
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
#include <osgVolume/VolumeTile>
|
2008-09-21 19:05:03 +08:00
|
|
|
#include <osgVolume/Volume>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
using namespace osgVolume;
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2008-12-21 04:55:21 +08:00
|
|
|
// VolumeTile
|
2008-09-21 19:05:03 +08:00
|
|
|
//
|
2008-12-21 04:55:21 +08:00
|
|
|
VolumeTile::VolumeTile():
|
2008-09-21 19:05:03 +08:00
|
|
|
_volume(0),
|
2008-12-18 19:54:34 +08:00
|
|
|
_dirty(false),
|
|
|
|
_hasBeenTraversal(false)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
setThreadSafeRefUnref(true);
|
|
|
|
}
|
|
|
|
|
2008-12-22 04:42:29 +08:00
|
|
|
VolumeTile::VolumeTile(const VolumeTile& volumeTile,const osg::CopyOp& copyop):
|
|
|
|
Group(volumeTile,copyop),
|
2008-09-21 19:05:03 +08:00
|
|
|
_volume(0),
|
2008-12-18 19:54:34 +08:00
|
|
|
_dirty(false),
|
2008-09-21 19:05:03 +08:00
|
|
|
_hasBeenTraversal(false),
|
2009-01-14 23:16:29 +08:00
|
|
|
_layer(volumeTile._layer)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
2009-01-09 23:19:25 +08:00
|
|
|
if (volumeTile.getVolumeTechnique()) ;
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
2008-12-22 04:42:29 +08:00
|
|
|
setVolumeTechnique(osg::clone(volumeTile.getVolumeTechnique()));
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
VolumeTile::~VolumeTile()
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
if (_volume) setVolume(0);
|
|
|
|
}
|
2009-01-09 23:19:25 +08:00
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
void VolumeTile::setVolume(Volume* volume)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
if (_volume == volume) return;
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volume) _volume->unregisterVolumeTile(this);
|
2008-09-21 19:05:03 +08:00
|
|
|
|
|
|
|
_volume = volume;
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volume) _volume->registerVolumeTile(this);
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
void VolumeTile::setTileID(const TileID& tileID)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_tileID == tileID) return;
|
2008-09-21 19:05:03 +08:00
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volume) _volume->unregisterVolumeTile(this);
|
2008-09-21 19:05:03 +08:00
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
_tileID = tileID;
|
2008-09-21 19:05:03 +08:00
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volume) _volume->registerVolumeTile(this);
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
void VolumeTile::traverse(osg::NodeVisitor& nv)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
if (!_hasBeenTraversal)
|
|
|
|
{
|
|
|
|
if (!_volume)
|
|
|
|
{
|
|
|
|
osg::NodePath& nodePath = nv.getNodePath();
|
|
|
|
if (!nodePath.empty())
|
|
|
|
{
|
|
|
|
for(osg::NodePath::reverse_iterator itr = nodePath.rbegin();
|
|
|
|
itr != nodePath.rend() && !_volume;
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osgVolume::Volume* volume = dynamic_cast<Volume*>(*itr);
|
|
|
|
if (volume)
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"Assigning volume system "<<volume<<std::endl;
|
|
|
|
setVolume(volume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_hasBeenTraversal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_volumeTechnique.valid())
|
|
|
|
{
|
|
|
|
_volumeTechnique->traverse(nv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::Group::traverse(nv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
void VolumeTile::init()
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
if (_volumeTechnique.valid() && getDirty())
|
|
|
|
{
|
|
|
|
_volumeTechnique->init();
|
|
|
|
|
|
|
|
setDirty(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
void VolumeTile::setVolumeTechnique(VolumeTechnique* volumeTechnique)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
if (_volumeTechnique == volumeTechnique) return;
|
|
|
|
|
|
|
|
int dirtyDelta = _dirty ? -1 : 0;
|
|
|
|
|
|
|
|
if (_volumeTechnique.valid())
|
|
|
|
{
|
2008-12-21 04:55:21 +08:00
|
|
|
_volumeTechnique->_volumeTile = 0;
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_volumeTechnique = volumeTechnique;
|
|
|
|
|
|
|
|
if (_volumeTechnique.valid())
|
|
|
|
{
|
2008-12-21 04:55:21 +08:00
|
|
|
_volumeTechnique->_volumeTile = this;
|
2008-09-21 19:05:03 +08:00
|
|
|
++dirtyDelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirtyDelta>0) setDirty(true);
|
|
|
|
else if (dirtyDelta<0) setDirty(false);
|
|
|
|
}
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
void VolumeTile::setDirty(bool dirty)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
if (_dirty==dirty) return;
|
|
|
|
|
|
|
|
_dirty = dirty;
|
|
|
|
|
|
|
|
if (_dirty)
|
|
|
|
{
|
|
|
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
|
|
|
}
|
|
|
|
else if (getNumChildrenRequiringUpdateTraversal()>0)
|
|
|
|
{
|
|
|
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
osg::BoundingSphere VolumeTile::computeBound() const
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
2009-01-14 23:16:29 +08:00
|
|
|
if (_layer.valid()) return _layer->computeBound();
|
2009-01-14 01:20:32 +08:00
|
|
|
|
2009-01-14 23:16:29 +08:00
|
|
|
return osg::BoundingSphere();
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|