graphTester

Introduction

This is the minimum example that we can show from the X3DToolKit. Here we load a scene and displays in text mode the structure of the X3D scene graph. One shall say that it is the "hello world!" of the X3DToolKit.

However this can be useful when you debug an application that builds or modifies a scene graph.

Some important functions and classes:

Main

First of all, a loader is built:
X3D::Loader *loader();
It knows all the standard X3D nodes.

Second, an X3DTK::GraphTester processor is built:

GraphTester tester();

To cleanly close the application, we use the X3DTK::MemReleaser to release the dynamically allocated scene graph.

MemReleaser releaser();

Then, the scene can be loaded from the file:

X3D::Scene *s = loader.load(argv[1]);

And the processor can be applied to the scene:

tester.test(s);

The final step is to release the scene graph:

releaser.release(s);

Notice that to be more concise but less clean, we could have written:

GraphTester().test(loader().load(argv[1]));

Code

Main.cpp

#include <X3DTK/X3D/scenegraph.h>
#include <X3DTK/graphtester.h>
#include <X3DTK/memreleaser.h>
#include <iostream>

using namespace X3DTK;
using namespace std;

int main(int argc, char *argv[])
{ 
  if (argc <= 1)
  {
    cerr << "usage: graphtester input" << endl;
    exit(0);
  }
  
  // Default loader for the X3D Nodes.
  X3D::Loader loader;
  // Instanciation of X3DTK::GraphTester.
  GraphTester tester;
  // Instanciation of X3DTK::MemReleaser.
  MemReleaser releaser;
  
  // Loads the scene.
  X3D::Scene *s = loader.load(argv[1]);
  // Tests the scene graph.
  tester.test(s);
  // Releases the scene graph.
  releaser.release(s);
  
  return 1;
}

Generated on Fri Jul 30 12:02:31 2004 for X3DToolKit by doxygen 1.3.6