2010-02-16 04:14:32 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 <osg/ObserverNodePath>
|
2010-02-17 18:09:31 +08:00
|
|
|
#include <osg/Notify>
|
2010-02-16 04:14:32 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2010-05-14 20:24:13 +08:00
|
|
|
ObserverNodePath::ObserverNodePath()
|
2010-02-16 04:14:32 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-14 20:24:13 +08:00
|
|
|
ObserverNodePath::ObserverNodePath(const ObserverNodePath& rhs)
|
2010-02-16 04:14:32 +08:00
|
|
|
{
|
2010-05-14 20:24:13 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock_rhs(_mutex);
|
|
|
|
_nodePath = rhs._nodePath;
|
2010-02-16 04:14:32 +08:00
|
|
|
}
|
|
|
|
|
2010-05-14 20:24:13 +08:00
|
|
|
ObserverNodePath::ObserverNodePath(const osg::NodePath& nodePath)
|
2010-02-16 04:14:32 +08:00
|
|
|
{
|
|
|
|
setNodePath(nodePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObserverNodePath::~ObserverNodePath()
|
|
|
|
{
|
|
|
|
clearNodePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObserverNodePath& ObserverNodePath::operator = (const ObserverNodePath& rhs)
|
|
|
|
{
|
|
|
|
if (&rhs==this) return *this;
|
|
|
|
|
2010-05-14 20:24:13 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock_rhs(rhs._mutex);
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock_lhs(_mutex);
|
|
|
|
_nodePath = rhs._nodePath;
|
2010-02-16 04:14:32 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-02-17 18:09:31 +08:00
|
|
|
void ObserverNodePath::setNodePathTo(osg::Node* node)
|
|
|
|
{
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
NodePathList nodePathList = node->getParentalNodePaths();
|
|
|
|
if (nodePathList.empty())
|
|
|
|
{
|
|
|
|
NodePath nodePath;
|
|
|
|
nodePath.push_back(node);
|
|
|
|
setNodePath(nodePath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nodePathList[0].empty())
|
|
|
|
{
|
|
|
|
nodePathList[0].push_back(node);
|
|
|
|
}
|
|
|
|
setNodePath(nodePathList[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clearNodePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-16 04:14:32 +08:00
|
|
|
void ObserverNodePath::setNodePath(const osg::NodePath& nodePath)
|
|
|
|
{
|
2010-05-14 20:24:13 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
2010-02-16 04:14:32 +08:00
|
|
|
_setNodePath(nodePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObserverNodePath::setNodePath(const osg::RefNodePath& refNodePath)
|
|
|
|
{
|
|
|
|
osg::NodePath nodePath;
|
|
|
|
for(RefNodePath::const_iterator itr = refNodePath.begin(); itr != refNodePath.end(); ++itr)
|
|
|
|
{
|
|
|
|
nodePath.push_back(itr->get());
|
|
|
|
}
|
|
|
|
setNodePath(nodePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObserverNodePath::clearNodePath()
|
|
|
|
{
|
2010-05-14 20:24:13 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
2010-02-16 04:14:32 +08:00
|
|
|
_clearNodePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObserverNodePath::getRefNodePath(RefNodePath& refNodePath) const
|
|
|
|
{
|
2010-05-14 20:24:13 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
|
|
|
refNodePath.resize(_nodePath.size());
|
|
|
|
for(unsigned int i=0; i<_nodePath.size(); ++i)
|
2010-02-16 04:14:32 +08:00
|
|
|
{
|
2010-05-28 16:57:48 +08:00
|
|
|
if (!_nodePath[i].lock(refNodePath[i]))
|
2010-05-14 20:24:13 +08:00
|
|
|
{
|
2010-05-25 20:05:13 +08:00
|
|
|
OSG_INFO<<"ObserverNodePath::getRefNodePath() node has been invalidated"<<std::endl;
|
2010-05-14 20:24:13 +08:00
|
|
|
refNodePath.clear();
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-16 04:14:32 +08:00
|
|
|
}
|
2010-02-17 18:09:31 +08:00
|
|
|
return true;
|
2010-02-16 04:14:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ObserverNodePath::getNodePath(NodePath& nodePath) const
|
|
|
|
{
|
2010-05-14 20:24:13 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
|
|
|
nodePath.resize(_nodePath.size());
|
|
|
|
for(unsigned int i=0; i<_nodePath.size(); ++i)
|
|
|
|
{
|
|
|
|
if (_nodePath[i].valid())
|
|
|
|
{
|
|
|
|
nodePath[i] = _nodePath[i].get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<"ObserverNodePath::getNodePath() node has been invalidated"<<std::endl;
|
|
|
|
nodePath.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 18:09:31 +08:00
|
|
|
return true;
|
2010-02-16 04:14:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath)
|
|
|
|
{
|
|
|
|
_clearNodePath();
|
|
|
|
|
2010-05-14 20:24:13 +08:00
|
|
|
// OSG_NOTICE<<"ObserverNodePath["<<this<<"]::_setNodePath() nodePath.size()="<<nodePath.size()<<std::endl;
|
2010-02-16 04:14:32 +08:00
|
|
|
|
2010-05-14 20:24:13 +08:00
|
|
|
_nodePath.resize(nodePath.size());
|
|
|
|
for(unsigned int i=0; i<nodePath.size(); ++i)
|
2010-02-16 04:14:32 +08:00
|
|
|
{
|
2010-05-14 20:24:13 +08:00
|
|
|
_nodePath[i] = nodePath[i];
|
2010-02-16 04:14:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObserverNodePath::_clearNodePath()
|
|
|
|
{
|
2010-05-14 20:24:13 +08:00
|
|
|
// OSG_NOTICE<<"ObserverNodePath["<<this<<"]::_clearNodePath() _nodePath.size()="<<_nodePath.size()<<std::endl;
|
2010-02-16 04:14:32 +08:00
|
|
|
_nodePath.clear();
|
|
|
|
}
|