NodePtr
buildGraphRecurse(UInt32 depth, UInt32 maxDepth, GeometryPtr pGeo)
{
    if(depth == maxDepth)
    {
        NodePtr pNodeGeo = Node::create();

        beginEditCP(pNodeGeo, Node::CoreFieldId);
        pNodeGeo->setCore(pGeo);
        endEditCP  (pNodeGeo, Node::CoreFieldId);

        return pNodeGeo;
    }
    else
    {
        NodePtr   pNodeGroup  = Node  ::create();
        GroupPtr  pGroup      = Group ::create();

        NodePtr   pNodeSwitch = Node  ::create();
        SwitchPtr pSwitch     = Switch::create();

        beginEditCP(pNodeGroup, Node::CoreFieldId | Node::ChildrenFieldId);
        pNodeGroup->setCore (pGroup     );
        pNodeGroup->addChild(pNodeSwitch);
        endEditCP  (pNodeGroup, Node::CoreFieldId | Node::ChildrenFieldId);

        beginEditCP(pSwitch, Switch::ChoiceFieldId);
        pSwitch->editChoice() = Switch::ALL;
        endEditCP  (pSwitch, Switch::ChoiceFieldId);

        beginEditCP(pNodeSwitch, Node::CoreFieldId | Node::ChildrenFieldId);
        pNodeSwitch->setCore(pSwitch);

        for(UInt32 i = 0; i < 8; ++i)
        {
            NodePtr      pNodeTrans  = Node     ::create();
            TransformPtr pTrans      = Transform::create();

            Vec3f       vecTrans;

            if(i & 0x01)
            {
                vecTrans[0] =  0.25 * X_SIZE * (1.0 / (depth + 1.0)) + 0.2 * (osgrand() - 0.5);
            }
            else
            {
                vecTrans[0] = -0.25 * X_SIZE * (1.0 / (depth + 1.0)) + 0.2 * (osgrand() - 0.5);
            }

            if(i & 0x02)
            {
                vecTrans[1] =  0.25 * Y_SIZE * (1.0 / (depth + 1.0)) + 0.2 * (osgrand() - 0.5);
            }
            else
            {
                vecTrans[1] = -0.25 * Y_SIZE * (1.0 / (depth + 1.0)) + 0.2 * (osgrand() - 0.5);
            }

            if(i & 0x04)
            {
                vecTrans[2] =  0.25 * Z_SIZE * (1.0 / (depth + 1.0)) + 0.2 * (osgrand() - 0.5);
            }
            else
            {
                vecTrans[2] = -0.25 * Z_SIZE * (1.0 / (depth + 1.0)) + 0.2 * (osgrand() - 0.5);
            }

            beginEditCP(pTrans, Transform::MatrixFieldId);
            pTrans->editMatrix().setTranslate(vecTrans);
            endEditCP  (pTrans, Transform::MatrixFieldId);

            beginEditCP(pNodeTrans, Node::CoreFieldId | Node::ChildrenFieldId);
            pNodeTrans->setCore (pTrans                                      );
            pNodeTrans->addChild(buildGraphRecurse(depth + 1, maxDepth, pGeo));
            endEditCP  (pNodeTrans, Node::CoreFieldId | Node::ChildrenFieldId);

            pNodeSwitch->addChild(pNodeTrans);
        }

        endEditCP  (pNodeSwitch, Node::CoreFieldId | Node::ChildrenFieldId);

        return pNodeGroup;
    }
}