For a step-by-step processor definition, see the simpleNodeCounter example.
Two types of processors exist: X3DTK::X3DOnePassProcessor
and X3DTK::X3DMultiPassProcessor
. You derive them and add functions: For example:
#include <X3DTK/kernel.h> namespace X3DTK { namespace X3D { class MyProcessor : public X3DOnePassProcessor { public: MyProcessor(); void compute(X3DNode *N); } } }
X3DTK::X3DOnePassProcessor
like this:
MyProcessor::MyProcessor() : X3DOnePassProcessor() { setGraphTraversal(new DFSGraphTraversal()); ... }
For an X3DTK::X3DMultiPassProcessor
which has two passes (Faces and Vertices):
MyProcessor::MyProcessor() : X3DMultiPassProcessor() { setGraphTraversal("Faces", new DFSGraphTraversal()); setGraphTraversal("Vertices", new DFSGraphTraversal()); ... }
X3DTK::X3D::X3DGeometryNode
:
#include <X3DTK/X3D/scenegraph.h> namespace X3DTK { namespace X3D { class MyRenderingVisitor : public RenderingVisitor { public: MyRenderingVisitor(); static void enterX3DGeometryNode(X3DGeometryNode *N); static bool walkOnX3DGeometryNode(X3DGeometryNode *N, X3DAbstractNode *child); static void leaveX3DGeometryNode(X3DGeometryNode *N); } } }
Here is an example:
void MyRenderingVisitor::enterX3DGeometryNode(X3DGeometryNode *N) { // using N... Singleton<MyProcessorStateVariables>::getInstance()->addNode(N); ... } bool MyRenderingVisitor::walkOnX3DGeometryNode(X3DGeometryNode *N, X3DAbstractNode *child) { return (dynamic_cast<Coordinate *>(child) != 0); }
These callbacks are recorded in the constructor of the component visitor:
MyRenderingVisitor::MyRenderingVisitor() : RenderingVisitor() { define(Recorder<X3DGeometryNode>::getEnterFunction(&MyRenderingVisitor::enterX3DGeometryNode)); define(Recorder<X3DGeometryNode>::getWalkOnFunction(&MyRenderingVisitor::walkOnX3DGeometryNode)); define(Recorder<X3DGeometryNode>::getLeaveFunction(&MyRenderingVisitor::leaveX3DGeometryNode)); }
This is a portable syntax. The recording of functions can also be done like this, using template function that are not well implemented on some compilers:
MyRenderingVisitor::MyRenderingVisitor() : RenderingVisitor() { defineEnterFunction(&MyRenderingVisitor::enterX3DGeometryNode); defineWalkOnFunction(&MyRenderingVisitor::walkOnX3DGeometryNode); defineLeaveFunction(&MyRenderingVisitor::leaveX3DGeometryNode); }
MyProcessor::MyProcessor() : X3DOnePassProcessor() { setGraphTraversal(new DFSGraphTraversal()); setComponentVisitor(new MyRenderingVisitor()); }
For an X3DTK::X3DMultiPassProcessor
which has two passes (Faces and Vertices):
MyProcessor::MyProcessor() : X3DMultiPassProcessor() { setGraphTraversal("Faces", new DFSGraphTraversal()); setGraphTraversal("Vertices", new DFSGraphTraversal()); setComponentVisitor("Faces", new MyRenderingFacesVisitor()); setComponentVisitor("Vertices", new MyRenderingVerticesVisitor()); }