Creating new nodes

Defining a new node

There are several things to do when you define a new node to follow the framework. A node is made up of two types of attributes: atomic attributes and children.

Atomic attributes

It is recommended to provide public set and get methods for atomic attributes. That is why that for an X3DTK::X3D::Cylinder node, you can access and modify the radius attribute by X3DTK::X3D::Cylinder::getRadius and X3DTK::X3D::Cylinder::setRadius.


It is recommended to provide a public get method for accessing the children of a node. Nevertheless it is recommended to not define a set method, since a generic one called X3DTK::X3DAbstractNode::setChild is provided.


This the most important part of the definition of a new node. Indeed atomic attributes and children are recorded in the constructor as well as the type string of the node necessary for the X3DTK::SFType singleton.

Here is an example for a new MyNode node belonging to the MyComponent of the X3D scene graph, which has a floating atomic attribute called length, an X3DTK::X3DGeometryNode child and an X3DTK::MFNode children:

// Passing the three strings indicating the name of the node (found in an X3D file), the name of the component and of the scene graph. define(Recorder<MyNode>::getTypeName("MyNode", "MyComponent", "X3D")); // The address of the member is given as well as the initialisation value. define(Recorder<MyNode, SFFloat>::getAttribute("length", &MyNode::_length, 1.0f)); // The child is named child. define(Recorder<MyNode, X3DGeometryNode>::getSFNode("child", &MyNode::_child)); // The children are named children. define(Recorder<MyNode, X3DNode>::getMFNode("children", &MyNode::_children));


The destructor is made virtual, and the X3DTK::X3DAbstractNode::removeChildren must be called if the node has children.

Copy constructor

You cannot declare a copy constructor. Nodes must be used dynamically. That is why an automated X3DTK::X3DAbstractNode::clone method is provided.

Graph traversal

The graph traversal order is implicitly defined by the recording order of the children. That is why for MyNode, a DFS walk will traverse child first and then children.


These examples show how to define a new node:
Generated on Fri Jul 30 12:02:31 2004 for X3DToolKit by doxygen 1.3.6