How to count the number of pfGeosets in a vgObject

 

Vega Code Example

 

 

 

 

 

 
 

This example function illustrates how to count the number of pfGeoSets with in vgObject.

 

  • How to get the root pfNode from a vgObject
  • How to test if a pfNode is of a specific type using pfIsOfType
  • How to test if a pfNode is a pfGeode node type
  • How to get the number of pfGeoSets in a pfGeode
  • How to get the number of children for a pfNode using pfGetNumChildren
  • Show how to traverse a pfNode tree using recursion

 

 
   
 

 

 
 
 
 

 

#include "vg.h"          // Required for the standard Vega classes
#include "vgperf.h"      // Required for the vgGetXXXPfNode functions
#include "pf.h"          // Required for the standard Performer classes
#include "vgutil.h"
#include "pfutil.h"      // Required for pfFindNode

 

int

getNumberPfGeoSetsInVegaObject( vgObject *obj ) {

// ############################################

// # Public Function

// #

// # Returns the number of pfGeoSets with  

// # in a vgObject by traversing the pfNode

// # tree of the vgObject    

// #

// ############################################

int numGeoSets = 0;

 

    //

    // Sanity check we need an object

    //

    if( obj == NULL )

        return 0;

 

    //

    // Retrieve the Objects root pfNode

    //

    pfNode *node = vgGetObjPfNode( obj );

    if( node == NULL )

       return 0;

 

    //

    // Now we can traverse the Nodes tree and count

    //

    numGeoSets = getNumberPfGeoSetsInNode ( node, numGeoSets );

 

return numGeoSets;

 

} // findNamedDCSNodeInVgObject

 

  

 

 

int

getNumberPfGeoSetsInNode( pfNode *node, int geoSetTotal ) {

// ########################################################

// #

// # Public Function

// #

// # A simple Recursive function that will traverse the given

// # nodes tree and count all the pfGeoSet it encounters

// #

// ########################################################

 

    

    //

    //  Sanity check we need a Node

    //

    if( node == NULL )

        return geoSetTotal;

 

    //

    //  Check to see if the Node is of the type pfGeode

    //  which is the Performer node that parents pfGeoSets

    //

    if( pfIsOfType( node,  pfGetGeodeClassType() )) {

 

        //

        //  Get the number of pfGeoSets attached to the pfGeode

        //

        int numGeosets = pfGetNumGSets ( node );

 

        geoSetTotal   += numGeosets;

 

        }

    

    else {

 

        //

        // Cycle through the children for this node

        //

        int numChildren = pfGetNumChildren ( node );

 

        for ( int idx = 0; idx < numChildren; idx++ ) {

        

            //

            // Get the child node and recurse in to them

            //

            pfNode *childNode  = pfGetChild ( node, idx );

 

            geoSetTotal = getNumberPfGeoSetsInNode ( childNode, geoSetTotal );

            

            }

        }

    

    

return geoSetTotal;

 

} // getNumberPfGeoSetsInNode

 

 

 

 
 

 

 

Copyright 2004 Gordon Tomlinson  All Rights Reserved.

All logos, trademarks and copyrights in this site are property of their respective owner.