Added osg::RefNodePath class for handling node paths.
This commit is contained in:
101
include/osg/RefNodePath
Normal file
101
include/osg/RefNodePath
Normal file
@@ -0,0 +1,101 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
||||
*/
|
||||
|
||||
#ifndef OSG_REFNODEPATH
|
||||
#define OSG_REFNODEPATH 1
|
||||
|
||||
#include <osg/Group>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class RefNodePath : public NodeList
|
||||
{
|
||||
public :
|
||||
|
||||
inline RefNodePath() {}
|
||||
|
||||
inline RefNodePath(const RefNodePath& refNodePath):
|
||||
NodeList(refNodePath) {}
|
||||
|
||||
inline explicit RefNodePath(const NodePath& nodePath)
|
||||
{
|
||||
for(osg::NodePath::const_iterator itr=nodePath.begin();
|
||||
itr != nodePath.end();
|
||||
++itr)
|
||||
{
|
||||
push_back(*itr);
|
||||
}
|
||||
}
|
||||
|
||||
inline operator NodePath () const
|
||||
{
|
||||
NodePath nodePath;
|
||||
for(NodeList::const_iterator itr=begin();
|
||||
itr != end();
|
||||
++itr)
|
||||
{
|
||||
nodePath.push_back(const_cast<Node*>(itr->get()));
|
||||
}
|
||||
|
||||
return nodePath;
|
||||
}
|
||||
|
||||
/** Check the validity of the RefNodePath to ensure that the parent path
|
||||
* matches those availble in the leaf node of the path.*/
|
||||
bool valid() const
|
||||
{
|
||||
// an empty NodePaath is invalid.
|
||||
if (empty()) return false;
|
||||
|
||||
// check to make sure that this RefNodeList isn't the only
|
||||
// place that the nodes are referenced, if one node has
|
||||
// a ref count of 1 then nodes must have been removed
|
||||
// from the scene graph elsewhere invalidating this RefNodePath.
|
||||
for(const_iterator itr=begin();
|
||||
itr != end();
|
||||
++itr)
|
||||
{
|
||||
if ((*itr)->referenceCount()<=1) return false;
|
||||
}
|
||||
|
||||
const_reverse_iterator ritr=rbegin();
|
||||
const osg::Node* node = ritr->get();
|
||||
++ritr;
|
||||
while (ritr!=rend())
|
||||
{
|
||||
const osg::Node* parent = ritr->get();
|
||||
// search of parent in current nodes parent list
|
||||
const osg::Node::ParentList& parents = node->getParents();
|
||||
osg::Node::ParentList::const_iterator pitr=parents.begin();
|
||||
for(; pitr!=parents.end() && parent!=*pitr; ++pitr) {}
|
||||
if (pitr==parents.end())
|
||||
{
|
||||
// original parent not found, so linkage must have changed
|
||||
// invalidating this RefNodePath.
|
||||
return false;
|
||||
}
|
||||
|
||||
node = parent;
|
||||
++ritr;
|
||||
}
|
||||
|
||||
// we've passed all the test that could invalidate this RefNodePath
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osg/ApplicationUsage>
|
||||
#include <osg/AnimationPath>
|
||||
#include <osg/RefNodePath>
|
||||
|
||||
#include <osgUtil/IntersectVisitor>
|
||||
|
||||
@@ -102,15 +103,13 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
|
||||
const osg::NodeVisitor* getUpdateVisitor() const { return _updateVisitor.get(); }
|
||||
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Node> > RefNodePath;
|
||||
|
||||
void computeActiveCoordindateSystemNodePath();
|
||||
|
||||
void setCoordindateSystemNodePath(const RefNodePath& nodePath) { _coordinateSystemNodePath = nodePath; }
|
||||
void setCoordindateSystemNodePath(const osg::RefNodePath& nodePath) { _coordinateSystemNodePath = nodePath; }
|
||||
|
||||
void setCoordindateSystemNodePath(const osg::NodePath& nodePath);
|
||||
|
||||
const RefNodePath& getCoordindateSystemNodePath() const { return _coordinateSystemNodePath; }
|
||||
const osg::RefNodePath& getCoordindateSystemNodePath() const { return _coordinateSystemNodePath; }
|
||||
|
||||
/** Dispatch the cull and draw for each of the Camera's for this frame.*/
|
||||
virtual void frame();
|
||||
@@ -194,7 +193,7 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
|
||||
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
|
||||
|
||||
|
||||
RefNodePath _coordinateSystemNodePath;
|
||||
osg::RefNodePath _coordinateSystemNodePath;
|
||||
|
||||
bool _recordingAnimationPath;
|
||||
double _recordingStartTime;
|
||||
|
||||
@@ -183,22 +183,13 @@ public:
|
||||
{
|
||||
osg::notify(osg::INFO)<<"getCoordinateFrame("<<position<<")"<<std::endl;
|
||||
|
||||
const Viewer::RefNodePath& refNodePath = _viewer->getCoordindateSystemNodePath();
|
||||
// do automatic conversion between RefNodePath and NodePath.
|
||||
osg::NodePath tmpPath = _viewer->getCoordindateSystemNodePath();
|
||||
|
||||
if (!refNodePath.empty())
|
||||
if (!tmpPath.empty())
|
||||
{
|
||||
osg::Matrixd coordinateFrame;
|
||||
|
||||
// have to create a copy of the RefNodePath to create an osg::NodePath
|
||||
// to allow it to be used along with the computeLocalToWorld call.
|
||||
osg::NodePath tmpPath;
|
||||
for(Viewer::RefNodePath::const_iterator itr=refNodePath.begin();
|
||||
itr!=refNodePath.end();
|
||||
++itr)
|
||||
{
|
||||
tmpPath.push_back(const_cast<osg::Node*>(itr->get()));
|
||||
}
|
||||
|
||||
osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(tmpPath.back());
|
||||
if (csn)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user