/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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. */ #include #include using namespace osg; using namespace osgVolume; ///////////////////////////////////////////////////////////////////////////////// // // VolumeTile // VolumeTile::VolumeTile(): _volume(0), _dirty(false), _hasBeenTraversal(false) { setThreadSafeRefUnref(true); } VolumeTile::VolumeTile(const VolumeTile& volumeTile,const osg::CopyOp& copyop): Group(volumeTile,copyop), _volume(0), _dirty(false), _hasBeenTraversal(false), _layer(volumeTile._layer) { if (volumeTile.getVolumeTechnique()) ; { setVolumeTechnique(osg::clone(volumeTile.getVolumeTechnique())); } } VolumeTile::~VolumeTile() { if (_volume) setVolume(0); } void VolumeTile::setVolume(Volume* volume) { if (_volume == volume) return; if (_volume) _volume->unregisterVolumeTile(this); _volume = volume; if (_volume) _volume->registerVolumeTile(this); } void VolumeTile::setTileID(const TileID& tileID) { if (_tileID == tileID) return; if (_volume) _volume->unregisterVolumeTile(this); _tileID = tileID; if (_volume) _volume->registerVolumeTile(this); } void VolumeTile::traverse(osg::NodeVisitor& nv) { 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(*itr); if (volume) { osg::notify(osg::INFO)<<"Assigning volume system "<traverse(nv); } else { osg::Group::traverse(nv); } } void VolumeTile::init() { if (_volumeTechnique.valid() && getDirty()) { _volumeTechnique->init(); setDirty(false); } } void VolumeTile::setVolumeTechnique(VolumeTechnique* volumeTechnique) { if (_volumeTechnique == volumeTechnique) return; int dirtyDelta = _dirty ? -1 : 0; if (_volumeTechnique.valid()) { _volumeTechnique->_volumeTile = 0; } _volumeTechnique = volumeTechnique; if (_volumeTechnique.valid()) { _volumeTechnique->_volumeTile = this; ++dirtyDelta; } if (dirtyDelta>0) setDirty(true); else if (dirtyDelta<0) setDirty(false); } void VolumeTile::setDirty(bool dirty) { if (_dirty==dirty) return; _dirty = dirty; if (_dirty) { setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1); } else if (getNumChildrenRequiringUpdateTraversal()>0) { setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1); } } osg::BoundingSphere VolumeTile::computeBound() const { if (_layer.valid()) return _layer->computeBound(); return osg::BoundingSphere(); }