Introduce NodeVisitor::className and libraryName()
This commit is contained in:
@@ -31,6 +31,8 @@ class OSG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::
|
||||
CollectOccludersVisitor();
|
||||
virtual ~CollectOccludersVisitor();
|
||||
|
||||
META_NodeVisitor("osg","CollectOccludersVisitor")
|
||||
|
||||
virtual CollectOccludersVisitor* cloneType() const { return new CollectOccludersVisitor(); }
|
||||
|
||||
virtual void reset();
|
||||
|
||||
@@ -26,6 +26,8 @@ public:
|
||||
|
||||
ComputeBoundsVisitor(TraversalMode traversalMode = TRAVERSE_ALL_CHILDREN);
|
||||
|
||||
META_NodeVisitor("osg","ComputeBoundsVisitor")
|
||||
|
||||
virtual void reset();
|
||||
|
||||
osg::BoundingBox& getBoundingBox() { return _bb; }
|
||||
|
||||
@@ -175,6 +175,8 @@ class OSG_EXPORT KdTreeBuilder : public osg::NodeVisitor
|
||||
|
||||
KdTreeBuilder(const KdTreeBuilder& rhs);
|
||||
|
||||
META_NodeVisitor("osg","KdTreeBuilder")
|
||||
|
||||
virtual KdTreeBuilder* clone() { return new KdTreeBuilder(*this); }
|
||||
|
||||
void apply(osg::Geode& geode);
|
||||
|
||||
@@ -42,6 +42,10 @@ class Transform;
|
||||
class Camera;
|
||||
class CameraView;
|
||||
|
||||
#define META_NodeVisitor(library,name) \
|
||||
virtual const char* libraryName() const { return #library; }\
|
||||
virtual const char* className() const { return #name; }
|
||||
|
||||
/** Visitor for type safe operations on osg::Nodes.
|
||||
Based on GOF's Visitor pattern. The NodeVisitor
|
||||
is useful for developing type safe operations to nodes
|
||||
@@ -82,6 +86,12 @@ class OSG_EXPORT NodeVisitor : public virtual Referenced
|
||||
NodeVisitor(VisitorType type,TraversalMode tm=TRAVERSE_NONE);
|
||||
|
||||
virtual ~NodeVisitor();
|
||||
|
||||
/** return the library name/namespapce of the visitor's. Should be defined by derived classes.*/
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
|
||||
/** return the name of the visitor's class type. Should be defined by derived classes.*/
|
||||
virtual const char* className() const { return "NodeVisitor"; }
|
||||
|
||||
/** Method to call to reset visitor. Useful if your visitor accumulates
|
||||
state during a traversal, and you plan to reuse the visitor.
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace osgAnimation
|
||||
BoneMap _map;
|
||||
BoneMapVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
|
||||
META_NodeVisitor("osgAnimation","BoneMapVisitor")
|
||||
|
||||
void apply(osg::Node& node) { return; }
|
||||
void apply(osg::Transform& node)
|
||||
{
|
||||
|
||||
@@ -26,8 +26,12 @@ namespace osgAnimation
|
||||
{
|
||||
AnimationList _animations;
|
||||
unsigned int _nbLinkedTarget;
|
||||
|
||||
LinkVisitor(Animation* animation) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _animations.push_back(animation); _nbLinkedTarget = 0;}
|
||||
LinkVisitor(const AnimationList& animations) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _animations = animations; _nbLinkedTarget = 0;}
|
||||
|
||||
META_NodeVisitor("osgAnimation","LinkVisitor")
|
||||
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(node.getUpdateCallback());
|
||||
|
||||
@@ -77,6 +77,9 @@ namespace osgAnimation
|
||||
{
|
||||
osg::ref_ptr<Skeleton> _root;
|
||||
BuildVertexTransformerVisitor(Skeleton* root): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _root = root;}
|
||||
|
||||
META_NodeVisitor("osgAnimation","BuildVertexTransformerVisitor")
|
||||
|
||||
void apply(osg::Geode& node)
|
||||
{
|
||||
int num = node.getNumDrawables();
|
||||
|
||||
@@ -48,6 +48,8 @@ namespace osgDB {
|
||||
|
||||
SharedStateManager(unsigned int mode = SHARE_ALL);
|
||||
|
||||
META_NodeVisitor("osgDB","SharedStateManager")
|
||||
|
||||
void setShareMode(unsigned int mode);
|
||||
|
||||
unsigned int getShareMode() { return _shareMode; }
|
||||
|
||||
@@ -43,6 +43,7 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
EventVisitor();
|
||||
virtual ~EventVisitor();
|
||||
|
||||
META_NodeVisitor("osgGA","EventVisitor")
|
||||
|
||||
void setActionAdapter(osgGA::GUIActionAdapter* actionAdapter) { _actionAdapter=actionAdapter; }
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ class OSGSIM_EXPORT InsertImpostorsVisitor : public osg::NodeVisitor
|
||||
/** Default to traversing all children. */
|
||||
InsertImpostorsVisitor();
|
||||
|
||||
META_NodeVisitor("osgSim","InsertImpostorsVisitor")
|
||||
|
||||
void setImpostorThresholdRatio(float ratio) { _impostorThresholdRatio = ratio; }
|
||||
float getImpostorThresholdRatio() const { return _impostorThresholdRatio; }
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
/// Copy constructor that does a shallow copy.
|
||||
CullVisitor(const CullVisitor&);
|
||||
|
||||
META_NodeVisitor("osgUtil","CullVisitor")
|
||||
|
||||
/** Create a shallow copy of the CullVisitor, used by CullVisitor::create() to clone the prototype. */
|
||||
virtual CullVisitor* clone() const { return new CullVisitor(*this); }
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ class OSGUTIL_EXPORT DisplayRequirementsVisitor : public osg::NodeVisitor
|
||||
* alpha and stencil off.*/
|
||||
DisplayRequirementsVisitor();
|
||||
|
||||
META_NodeVisitor("osgUtil","DisplayRequirementsVisitor")
|
||||
|
||||
/** Set the DisplaySettings. */
|
||||
inline void setDisplaySettings(osg::DisplaySettings* ds) { _ds = ds; }
|
||||
|
||||
@@ -32,6 +32,8 @@ class OSGUTIL_EXPORT DrawElementTypeSimplifierVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
META_NodeVisitor("osgUtil","DrawElementTypeSimplifierVisitor")
|
||||
|
||||
void apply(osg::Geode& node);
|
||||
};
|
||||
|
||||
|
||||
@@ -51,9 +51,10 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
|
||||
* display list/texture objects etc. Default mode is to compile
|
||||
* GL objects.
|
||||
*/
|
||||
GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES|CHECK_BLACK_LISTED_MODES);
|
||||
|
||||
|
||||
GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES|CHECK_BLACK_LISTED_MODES);
|
||||
|
||||
META_NodeVisitor("osg","GLObjectsVisitor")
|
||||
|
||||
virtual void reset()
|
||||
{
|
||||
_drawablesAppliedSet.clear();
|
||||
|
||||
@@ -102,6 +102,8 @@ class OSGUTIL_EXPORT IntersectVisitor : public osg::NodeVisitor
|
||||
IntersectVisitor();
|
||||
virtual ~IntersectVisitor();
|
||||
|
||||
META_NodeVisitor("osgUtil","IntersectVisitor")
|
||||
|
||||
void reset();
|
||||
|
||||
/** Add a line segment to use for intersection testing during scene traversal.
|
||||
|
||||
@@ -137,6 +137,8 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
IntersectionVisitor(Intersector* intersector=0, ReadCallback* readCallback=0);
|
||||
|
||||
META_NodeVisitor("osgUtil","IntersectionVisitor")
|
||||
|
||||
virtual void reset();
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ class OSGUTIL_EXPORT Simplifier : public osg::NodeVisitor
|
||||
|
||||
Simplifier(double sampleRatio=1.0, double maximumError=FLT_MAX, double maximumLength=0.0);
|
||||
|
||||
META_NodeVisitor("osgUtil","Simplifier")
|
||||
|
||||
void setSampleRatio(float sampleRatio) { _sampleRatio = sampleRatio; }
|
||||
float getSampleRatio() const { return _sampleRatio; }
|
||||
|
||||
@@ -167,6 +167,8 @@ public:
|
||||
|
||||
StatsVisitor();
|
||||
|
||||
META_NodeVisitor("osgUtil","StatsVisitor")
|
||||
|
||||
void reset();
|
||||
|
||||
void apply(osg::Node& node);
|
||||
|
||||
@@ -41,9 +41,11 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
|
||||
UpdateVisitor();
|
||||
virtual ~UpdateVisitor();
|
||||
|
||||
META_NodeVisitor("osgUtil","UpdateVisitor")
|
||||
|
||||
virtual void reset();
|
||||
|
||||
/** During traversal each type of node calls its callbacks and its children traversed. */
|
||||
/** During traversal each type of node calls its callbacks and its children traversed. */
|
||||
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
|
||||
|
||||
@@ -39,6 +39,8 @@ class TransformVisitor : public NodeVisitor
|
||||
_ignoreCameras(ignoreCameras)
|
||||
{}
|
||||
|
||||
META_NodeVisitor("osg","TransformVisitor")
|
||||
|
||||
virtual void apply(Transform& transform)
|
||||
{
|
||||
if (_coordMode==LOCAL_TO_WORLD)
|
||||
|
||||
@@ -129,6 +129,8 @@ public:
|
||||
|
||||
}
|
||||
|
||||
META_NodeVisitor("osgDB","FindCompileableGLObjectsVisitor")
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
apply(node.getStateSet());
|
||||
@@ -1486,6 +1488,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
META_NodeVisitor("osgDB","FindCompileableGLObjectsVisitor")
|
||||
|
||||
virtual void apply(osg::PagedLOD& plod)
|
||||
{
|
||||
if (plod.getName()!=_marker)
|
||||
@@ -1842,6 +1846,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
META_NodeVisitor("osgDB","FindPagedLODsVisitor")
|
||||
|
||||
virtual void apply(osg::PagedLOD& plod)
|
||||
{
|
||||
plod.setFrameNumberOfLastTraversal(_frameNumber);
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace
|
||||
class TsgVisitor: public NodeVisitor {
|
||||
public:
|
||||
TsgVisitor(BumpMapping* bm): NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), _bm(bm) {}
|
||||
|
||||
META_NodeVisitor("osgFX","TsgVisitor")
|
||||
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
for (unsigned i=0; i<geode.getNumDrawables(); ++i) {
|
||||
@@ -50,6 +53,9 @@ namespace
|
||||
class TexCoordGenerator: public osg::NodeVisitor {
|
||||
public:
|
||||
TexCoordGenerator(int du, int nu): NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), du_(du), nu_(nu) {}
|
||||
|
||||
META_NodeVisitor("osgFX","TexCoordGenerator")
|
||||
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
const osg::BoundingSphere &bsphere = geode.getBound();
|
||||
|
||||
@@ -20,26 +20,6 @@ using namespace osg;
|
||||
using namespace osgGA;
|
||||
|
||||
|
||||
class CollectParentPaths : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
CollectParentPaths() :
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {}
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
if (node.getNumParents()==0)
|
||||
{
|
||||
_nodePaths.push_back(getNodePath());
|
||||
}
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
osg::NodePath _nodePath;
|
||||
typedef std::vector< osg::NodePath > NodePathList;
|
||||
NodePathList _nodePaths;
|
||||
};
|
||||
|
||||
NodeTrackerManipulator::NodeTrackerManipulator()
|
||||
{
|
||||
_trackerMode = NODE_CENTER_AND_ROTATION;
|
||||
@@ -120,14 +100,17 @@ void NodeTrackerManipulator::setTrackNode(osg::Node* node)
|
||||
return;
|
||||
}
|
||||
|
||||
CollectParentPaths cpp;
|
||||
node->accept(cpp);
|
||||
|
||||
if (!cpp._nodePaths.empty())
|
||||
osg::NodePathList nodePaths = node->getParentalNodePaths();
|
||||
if (!nodePaths.empty())
|
||||
{
|
||||
if (nodePaths.size()>1)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"osgGA::NodeTrackerManipualtor::setTrackNode(..) taking first parent path, ignoring others."<<std::endl;
|
||||
}
|
||||
|
||||
osg::notify(osg::INFO)<<"NodeTrackerManipulator::setTrackNode(Node*"<<node<<" "<<node->getName()<<"): Path set"<<std::endl;
|
||||
_trackNodePath.clear();
|
||||
setTrackNodePath( cpp._nodePaths[0] );
|
||||
setTrackNodePath( nodePaths.front() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -15,35 +15,26 @@
|
||||
#include <osgManipulator/Selection>
|
||||
#include <osgManipulator/Command>
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace osgManipulator;
|
||||
|
||||
class FindNodePathToRootVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
osg::NodePath& _nodePathToRoot;
|
||||
|
||||
FindNodePathToRootVisitor(osg::NodePath& np)
|
||||
: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS),
|
||||
_nodePathToRoot(np)
|
||||
{}
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
_nodePathToRoot.push_back(&node);
|
||||
traverse(node);
|
||||
}
|
||||
};
|
||||
|
||||
void osgManipulator::computeNodePathToRoot(osg::Node& node, osg::NodePath& np)
|
||||
{
|
||||
np.clear();
|
||||
osg::ref_ptr<FindNodePathToRootVisitor> visitor = new FindNodePathToRootVisitor(np);
|
||||
node.accept(*visitor);
|
||||
np.pop_back();
|
||||
std::reverse(np.begin(), np.end());
|
||||
|
||||
osg::NodePathList nodePaths = node.getParentalNodePaths();
|
||||
|
||||
if (!nodePaths.empty())
|
||||
{
|
||||
np = nodePaths.front();
|
||||
if (nodePaths.size()>1)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"osgManipulator::computeNodePathToRoot(,) taking first parent path, ignoring others."<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Selection::Selection()
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
if (matrix) pushMatrix(*matrix);
|
||||
}
|
||||
|
||||
META_NodeVisitor("osgShadow","CollectOccludersVisitor")
|
||||
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
if (node.getStateSet()) pushState(node.getStateSet());
|
||||
|
||||
@@ -1014,6 +1014,8 @@ class PolytopeVisitor : public osg::NodeVisitor
|
||||
_polytopeStack.back().second.setAndTransformProvidingInverse(polytope, _polytopeStack.back().first);
|
||||
}
|
||||
|
||||
META_NodeVisitor("osgSim","PolytopeVisitor")
|
||||
|
||||
void reset()
|
||||
{
|
||||
_polytopeStack.clear();
|
||||
|
||||
@@ -34,7 +34,8 @@ public:
|
||||
CollectedCoordinateSystemNodesVisitor():
|
||||
NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) {}
|
||||
|
||||
|
||||
META_NodeVisitor("osgViewer","CollectedCoordinateSystemNodesVisitor")
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
traverse(node);
|
||||
|
||||
Reference in New Issue
Block a user