#include <WFX/scene/SceneGraphPrinter.h>
#define IPRINT(msg) { for ( UInt i=0; i<CurrentIndent; i++) *Output << " "; \
                        *Output << msg; \
                        *Output << std::endl; }
                        

using namespace WFX::scene;

SceneGraphPrinter::SceneGraphPrinter(std::ostream* output) : Output(output) {
    CurrentIndent = 0;
}

void SceneGraphPrinter::visitNode(Node& n) {
    CurrentIndent += 4;
    IPRINT("=> Node (" << n.Children.size() << ")");
    std::list<Spatial*>::iterator it;
    for (it = n.Children.begin(); it != n.Children.end(); it++) {
        (*it)->accept(*this);
    }
    CurrentIndent -= 4;
}

void SceneGraphPrinter::visitTriMesh(TriMesh& t) {
    IPRINT("=> TriMesh (" << t.getFaceCount() << ")");
}

void SceneGraphPrinter::visitOctreeNode(OctreeNode& n) {
    CurrentIndent += 4;
    IPRINT("=> OctreeNode (" << n.Geometry.size() << ")");
    //Geometry
    std::list<Spatial*>::iterator it;
    for (it = n.Geometry.begin(); it != n.Geometry.end(); it++) {
        CurrentIndent += 2;
        (*it)->accept(*this);
        CurrentIndent -= 2;
    }
    //children
    for (UInt i=0; i<8; i++) {
        if (n.Children[i])
            n.Children[i]->accept(*this);
    }

    CurrentIndent -= 4;
}

