<< Previous Chapter: Creating a new container type Tutorial Overview Next Chapter: Tips for porting from 1.x >>

Debugging Tips


This is a very simple tool that lets you visualize the scene graph quickly. It can help in cases where you want to verify a graph you built looks the way you expect or (perhaps the more useful/common case) when you want to get an idea of the graph constructed by a loader from a file. For its most basic usage you simply create a SceneGraphPrinter object with a the root Node of the scene (or part) that you want to print and then call printDownTree(std::cout) to get a print out of the tree starting at the root node (you can pass any std::ostream to redirect output into a file for example.

#include <OpenSG/OSGFieldContainerUtils.h>  // header for SceneGraphPrinter

OSG::NodeRefPtr someNode;

OSG::SceneGraphPrinter sgp(someNode);


You can also get a printout of the nodes "above" the one you pass as root to the constructor by calling printUpTree. This prints all nodes along up to the root of the scene (i.e. a node without a parent).

To get more details about the NodeCores in the scene you can also register CorePrintFunctions that have a signature like this: void (SceneGraphPrinter *, NodeCore *) that is they get the SceneGraphPrinter object and current NodeCore? as argument and return nothing. These functions are registered with a SceneGraphPrinter instance by calling addPrintFunc and removed again with subPrintFunc. They can use the getStream and indentStream member functions of SceneGraphPrinter to get the stream to write additional information about the core.

void printTransform(OSG::SceneGraphPrinter *sgp, OSG::NodeCore *core)
    OSG::Transform* xform = dynamic_cast<OSG::Transform*>(core);

    if(xform == NULL)
        return;        // should never happen unless this is registered for the wrong type

    sgp->indentStream() << "Transform matrix:\n"
                        << xform->getMatrix();

OSG::SceneGraphPrinter sgp;

sgp.addPrintFunc(OSG::Transform::getClassType(), &printTransform);

<< Previous Chapter: Creating a new container type Tutorial Overview Next Chapter: Tips for porting from 1.x >>
Last modified 6 years ago Last modified on 10/05/11 00:25:08