From e60db47c1bac5b618cb91891b429996367738943 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 19 Mar 2009 11:11:51 +0000 Subject: [PATCH] Inroduced simple PrintVisitor class for helping debug scene graph structures --- include/osgUtil/PrintVisitor | 49 ++++++++++++++++++++++++++++++++++++ src/osgUtil/CMakeLists.txt | 2 ++ src/osgUtil/CullVisitor.cpp | 48 ----------------------------------- src/osgUtil/PrintVisitor.cpp | 36 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 48 deletions(-) create mode 100644 include/osgUtil/PrintVisitor create mode 100644 src/osgUtil/PrintVisitor.cpp diff --git a/include/osgUtil/PrintVisitor b/include/osgUtil/PrintVisitor new file mode 100644 index 000000000..b57fab292 --- /dev/null +++ b/include/osgUtil/PrintVisitor @@ -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 +#include + +#include + +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 + diff --git a/src/osgUtil/CMakeLists.txt b/src/osgUtil/CMakeLists.txt index e35c162a8..dc57bbcc8 100644 --- a/src/osgUtil/CMakeLists.txt +++ b/src/osgUtil/CMakeLists.txt @@ -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 diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index d3df69c7f..1bf4666a1 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.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() < + +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()<