Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Working with Traversers

Using a Traverser is very simple. While it is a four-step process, one process might be a one-time operation and two processes are optional:

  1. Create a Traverser.
    A Traverser can be created as any other object. The predefined concrete Traversers don't need a constructor argument.
    For example to create a SearchTraverser , do the following:
        SearchTraverser  cst;
    
  2. Initialize the Traverser (optional).
    Some Traversers might require some initialization.
    For example, to tell the SearchTraverser cst to look for all Nodes of type LightSource , do the following:
        cst.setBaseClassSearch( true );
        cst.setClassName("class nvsg::LightSource");
    
  3. Do the traversal.
    Call the member function apply of the Traverser. Depending on the type of Traverser, it might be OK to omit the ViewState argument.
    For example, the SearchTraverser doesn't use the ViewState:
        cst.apply( NULL, &scene );
    
  4. Get the results of the traversal (optional).
    Some Traversers might create information that can be queried after the traversal. For example, to get the results of a search traversal do the following:
        const vector<const Object *> & searchResults = cst.getResults();
    

A RenderTraverser like the GLTraverser is even easier to use:

  RenderTraverser * rt = new GLTraverser;
  rt->apply( &viewState, &scene );
However, a RenderTraverser needs some prerequisites to be fullfilled, as there has to be a valid drawing environment. This Environment might depend on the type of RenderTraverser. For Details, see the sample application SimpleViewer.

Note:
Strictly distinguish between read-only traversers like a GLTraverser , which works on constant data and can't change them, and read-write traversers like AppTraverser , which are allowed to modify the data.
See also:
How to Derive a Traverser
Back to Working With NVSG Classes
Generated on Tue Mar 1 13:20:36 2005 for NVSGSDK by NVIDIA