4.8. Using New Action Classes

Like nodes, action classes must be initialized before any instances can be constructed. Also note that before you can add a method to the method list, you must initialize both the action class and the node class involved.

Example 4-3 reads in a scene graph from the file volume.iv and applies the GetVolumeAction action to it, printing the resulting volume.

Example 4.3.  PrintVolume.c++

#include <Inventor/SoDB.h>
#include <Inventor/SoInput.h>
#include <Inventor/SoInteraction.h>
#include <Inventor/nodes/SoSeparator.h>

// Header file for new action class
#include "GetVolumeAction.h"

   // Initialize Inventor

   // Initialize the new action class

   // Open the file and read the scene
   SoInput      myInput;
   SoSeparator  *root;
   if (! myInput.openFile("volume.iv")) {
     fprintf(stderr, "Can't open \"volume.iv\" for reading\n");
     return 1;
   root = SoDB::readAll(&myInput);
   if (root == NULL) {
     printf("Couldn't read scene from \"volume.iv\"\n");
     return 2;

   // Compute the volume: apply a GetVolumeAction to the root
   GetVolumeAction va;

   // Print the result
   printf("Total volume = %g\n", va.getVolume());

   return 0;