2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
|
2008-09-21 19:05:03 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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
|
2008-09-21 19:05:03 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2008-09-21 19:05:03 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-09-21 19:05:03 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgVolume/VolumeTechnique>
|
2008-12-21 04:55:21 +08:00
|
|
|
#include <osgVolume/VolumeTile>
|
2008-09-21 19:05:03 +08:00
|
|
|
|
|
|
|
using namespace osgVolume;
|
|
|
|
|
|
|
|
VolumeTechnique::VolumeTechnique():
|
2008-12-21 04:55:21 +08:00
|
|
|
_volumeTile(0)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
setThreadSafeRefUnref(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
VolumeTechnique::VolumeTechnique(const VolumeTechnique& rhs,const osg::CopyOp& copyop):
|
|
|
|
osg::Object(rhs,copyop),
|
2008-12-21 04:55:21 +08:00
|
|
|
_volumeTile(0)
|
2008-09-21 19:05:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VolumeTechnique::~VolumeTechnique()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeTechnique::init()
|
|
|
|
{
|
2018-04-21 00:18:22 +08:00
|
|
|
OSG_NOTICE<<className()<<"::initialize(..) not implemented yet"<<std::endl;
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeTechnique::update(osgUtil::UpdateVisitor* uv)
|
|
|
|
{
|
2018-04-21 00:18:22 +08:00
|
|
|
OSG_NOTICE<<className()<<"::update(..) not implemented yet"<<std::endl;
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volumeTile) _volumeTile->osg::Group::traverse(*uv);
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeTechnique::cull(osgUtil::CullVisitor* cv)
|
|
|
|
{
|
2018-04-21 00:18:22 +08:00
|
|
|
OSG_NOTICE<<className()<<"::cull(..) not implemented yet"<<std::endl;
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volumeTile) _volumeTile->osg::Group::traverse(*cv);
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeTechnique::cleanSceneGraph()
|
|
|
|
{
|
2018-04-21 00:18:22 +08:00
|
|
|
OSG_NOTICE<<className()<<"::cleanSceneGraph(..) not implemented yet"<<std::endl;
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeTechnique::traverse(osg::NodeVisitor& nv)
|
|
|
|
{
|
2008-12-21 04:55:21 +08:00
|
|
|
if (!_volumeTile) return;
|
2008-09-21 19:05:03 +08:00
|
|
|
|
|
|
|
// if app traversal update the frame count.
|
|
|
|
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
|
|
|
{
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volumeTile->getDirty()) _volumeTile->init();
|
2008-09-21 19:05:03 +08:00
|
|
|
|
2016-01-21 01:49:10 +08:00
|
|
|
osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
|
2008-09-21 19:05:03 +08:00
|
|
|
if (uv)
|
|
|
|
{
|
|
|
|
update(uv);
|
|
|
|
return;
|
2012-03-22 01:36:20 +08:00
|
|
|
}
|
|
|
|
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
|
|
|
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
|
|
|
|
{
|
2016-01-21 01:49:10 +08:00
|
|
|
osgUtil::CullVisitor* cv = nv.asCullVisitor();
|
2008-09-21 19:05:03 +08:00
|
|
|
if (cv)
|
|
|
|
{
|
|
|
|
cull(cv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 04:55:21 +08:00
|
|
|
if (_volumeTile->getDirty()) _volumeTile->init();
|
2008-09-21 19:05:03 +08:00
|
|
|
|
|
|
|
// otherwise fallback to the Group::traverse()
|
2008-12-21 04:55:21 +08:00
|
|
|
_volumeTile->osg::Group::traverse(nv);
|
2008-09-21 19:05:03 +08:00
|
|
|
}
|
2013-12-12 17:53:24 +08:00
|
|
|
|
|
|
|
bool VolumeTechnique::isMoving(osgUtil::CullVisitor* cv)
|
|
|
|
{
|
|
|
|
bool moving = false;
|
|
|
|
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
|
|
|
|
|
|
|
ModelViewMatrixMap::iterator itr = _modelViewMatrixMap.find(cv->getIdentifier());
|
|
|
|
if (itr!=_modelViewMatrixMap.end())
|
|
|
|
{
|
|
|
|
osg::Matrix newModelViewMatrix = *(cv->getModelViewMatrix());
|
|
|
|
osg::Matrix& previousModelViewMatrix = itr->second;
|
|
|
|
moving = (newModelViewMatrix != previousModelViewMatrix);
|
|
|
|
|
|
|
|
previousModelViewMatrix = newModelViewMatrix;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_modelViewMatrixMap[cv->getIdentifier()] = *(cv->getModelViewMatrix());
|
|
|
|
}
|
|
|
|
return moving;
|
|
|
|
}
|