Inroduced simple PrintVisitor class for helping debug scene graph structures
This commit is contained in:
49
include/osgUtil/PrintVisitor
Normal file
49
include/osgUtil/PrintVisitor
Normal file
@@ -0,0 +1,49 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
#ifndef OSGUTIL_PRINTVISITOR
|
||||
#define OSGUTIL_PRINTVISITOR 1
|
||||
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osgUtil/Export>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
class OSGUTIL_EXPORT PrintVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
PrintVisitor(std::ostream& out, int indent=0, int step=2);
|
||||
|
||||
void apply(osg::Node& node);
|
||||
|
||||
std::ostream& output()
|
||||
{
|
||||
for(unsigned int i=0;i<_indent; ++i) _out<<" ";
|
||||
return _out;
|
||||
}
|
||||
|
||||
void enter() { _indent += _step; }
|
||||
void leave() { _indent -= _step; }
|
||||
|
||||
std::ostream& _out;
|
||||
unsigned int _indent;
|
||||
unsigned int _step;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,6 +29,7 @@ SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/PlaneIntersector
|
||||
${HEADER_PATH}/PolytopeIntersector
|
||||
${HEADER_PATH}/PositionalStateContainer
|
||||
${HEADER_PATH}/PrintVisitor
|
||||
${HEADER_PATH}/ReflectionMapGenerator
|
||||
${HEADER_PATH}/RenderBin
|
||||
${HEADER_PATH}/RenderLeaf
|
||||
@@ -69,6 +70,7 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
PlaneIntersector.cpp
|
||||
PolytopeIntersector.cpp
|
||||
PositionalStateContainer.cpp
|
||||
PrintVisitor.cpp
|
||||
RenderBin.cpp
|
||||
RenderLeaf.cpp
|
||||
RenderStage.cpp
|
||||
|
||||
@@ -44,54 +44,6 @@ inline int EQUAL_F(float a, float b)
|
||||
{ return a == b || fabsf(a-b) <= MAX_F(fabsf(a),fabsf(b))*1e-3f; }
|
||||
|
||||
|
||||
class PrintVisitor : public NodeVisitor
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
PrintVisitor(std::ostream& out):
|
||||
NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_out(out)
|
||||
{
|
||||
_indent = 0;
|
||||
_step = 4;
|
||||
}
|
||||
|
||||
inline void moveIn() { _indent += _step; }
|
||||
inline void moveOut() { _indent -= _step; }
|
||||
inline void writeIndent()
|
||||
{
|
||||
for(int i=0;i<_indent;++i) _out << " ";
|
||||
}
|
||||
|
||||
virtual void apply(Node& node)
|
||||
{
|
||||
moveIn();
|
||||
writeIndent(); _out << node.className() <<std::endl;
|
||||
traverse(node);
|
||||
moveOut();
|
||||
}
|
||||
|
||||
virtual void apply(Geode& node) { apply((Node&)node); }
|
||||
virtual void apply(Billboard& node) { apply((Geode&)node); }
|
||||
virtual void apply(LightSource& node) { apply((Group&)node); }
|
||||
virtual void apply(ClipNode& node) { apply((Group&)node); }
|
||||
|
||||
virtual void apply(Group& node) { apply((Node&)node); }
|
||||
virtual void apply(Transform& node) { apply((Group&)node); }
|
||||
virtual void apply(Projection& node) { apply((Group&)node); }
|
||||
virtual void apply(Switch& node) { apply((Group&)node); }
|
||||
virtual void apply(LOD& node) { apply((Group&)node); }
|
||||
|
||||
protected:
|
||||
|
||||
PrintVisitor& operator = (const PrintVisitor&) { return *this; }
|
||||
|
||||
std::ostream& _out;
|
||||
int _indent;
|
||||
int _step;
|
||||
};
|
||||
|
||||
CullVisitor::CullVisitor():
|
||||
NodeVisitor(CULL_VISITOR,TRAVERSE_ACTIVE_CHILDREN),
|
||||
_currentStateGraph(NULL),
|
||||
|
||||
36
src/osgUtil/PrintVisitor.cpp
Normal file
36
src/osgUtil/PrintVisitor.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/* -*-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 <osgUtil/PrintVisitor>
|
||||
|
||||
namespace osgUtil
|
||||
{
|
||||
|
||||
PrintVisitor::PrintVisitor(std::ostream& out, int indent, int step):
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_out(out),
|
||||
_indent(indent),
|
||||
_step(step)
|
||||
{
|
||||
}
|
||||
|
||||
void PrintVisitor::apply(osg::Node& node)
|
||||
{
|
||||
output()<<node.libraryName()<<"::"<<node.className()<<std::endl;
|
||||
|
||||
enter();
|
||||
traverse(node);
|
||||
leave();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user