
#ifndef __WFX_SCENE_OCTREEBUILDER_H__
#define __WFX_SCENE_OCTREEBUILDER_H__

#include <WFX/WFXIncludes.h>
#include <WFX/scene/Node.h>
#include <WFX/scene/SceneGraphVisitor.h>
#include <WFX/math/Cube.h>

namespace WFX {

    namespace scene {

        /**
         * Builds an Octree
         * implements the SceneGraphVisitor to add GeometryNodes to the Tree
         */
        class OctreeBuilder : public SceneGraphVisitor {
            public:
                /** Ctor/Dtor */
                OctreeBuilder();
                virtual ~OctreeBuilder();

                /** starts the build-process */
                void build();
                
                /** adds a subtree to include in the build process */
                void addSource(AbstractNode* n) {
                    SourceNodes->addChild(n);
                }
                /** sets the max face stop criterion */
                inline static void setMaxFaces(UInt m) {
                    MaxFaces = m;
                }
                /** returns max face stop criterion */
                inline static UInt getMaxFaces() {
                    return MaxFaces;
                }
                /** sets the max subdivision stop criterion */
                inline static void setMaxDivisions(UInt m) {
                    MaxDivisions = m;
                }
                /** returns the max subdivision stop criterion */
                inline static UInt getMaxDivisions() {
                    return MaxDivisions;
                }
                /** deletes attached source nodes */
                void deleteSources();
                /** returns the Octree */
                inline OctreeNode* getOctree() {
                    return RootNode;
                }
                
                /** visits a Node */
                void visitNode(Node& n);
                /** visits a TriMesh */
                void visitTriMesh(TriMesh& m);
                /** visits an OctreeNode */
                void visitOctreeNode(OctreeNode& o);
            protected:
            private:
                /** max faces */
                static UInt MaxFaces;
                /** max subdivisions */
                static UInt MaxDivisions;
                
                /** root Node */
                OctreeNode* RootNode;
                /** Nodes to build Octree from */
                Node* SourceNodes;
                
        };

    }

}


#endif //include guard


