Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoReorganizeAction Class Reference
[Action Classes]

Inherits SoSimplifyAction.

List of all members.


Detailed Description

The SoReorganizeAction class reorganizes your scene graph to optimize traversal/rendering.

Note. This is work-in-progress. pederb, 2005-04-05.

The code below is an example of a program that applies an SoReorganizeAction on a scene graph, converting all shapes into shapes that can be rendered using vertex array or VBO rendering.

  #include <Inventor/SoDB.h>
  #include <Inventor/nodes/SoSeparator.h>
  #include <Inventor/nodes/SoCoordinate3.h>
  #include <Inventor/nodes/SoCoordinate4.h>
  #include <Inventor/nodes/SoNormal.h>
  #include <Inventor/nodes/SoTextureCoordinate2.h>
  #include <Inventor/nodes/SoSeparator.h>
  #include <Inventor/actions/SoWriteAction.h>
  #include <Inventor/actions/SoSearchAction.h>
  #include <Inventor/errors/SoDebugError.h>
  #include <Inventor/nodes/SoShapeHints.h>
  #include <Inventor/SoInput.h>
  #include <Inventor/SoOutput.h>
  #include <Inventor/SoInteraction.h>
  #include <Inventor/actions/SoReorganizeAction.h>
  #include <cassert>
  #include <cstdio>
  
  static void strip_node(SoType type, SoNode * root) 
  {
    SoSearchAction sa;
    sa.setType(type);
    sa.setSearchingAll(TRUE);
    sa.setInterest(SoSearchAction::ALL);
    sa.apply(root);

    SoPathList & pl = sa.getPaths();
    for (int i = 0; i < pl.getLength(); i++) {
      SoFullPath * p = (SoFullPath*) pl[i];
        if (p->getTail()->isOfType(type)) {
          SoGroup * g = (SoGroup*) p->getNodeFromTail(1);
          g->removeChild(p->getIndexFromTail(0));
        }
      } 
    sa.reset();  
  }

  int
  main(int argc, char ** argv )
  {
    if (argc < 3) {
      fprintf(stderr,"Usage: reorganize <infile> <outfile> [nostrip]\n");
      return -1;
    }

    SbBool strip = TRUE;
    if (argc > 3) {
      if (strcmp(argv[3], "nostrip") == 0) strip = FALSE;
      else {
        fprintf(stderr,"Usage: reorganize <infile> <outfile> [nostrip]\n");
        return -1;
      }
    }

    SoDB::init();
    SoInteraction::init();
    
    SoInput input;
    SbBool ok = input.openFile(argv[1]);
    if (!ok) {
      fprintf(stderr,"Unable to open file.\n");
      return -1;
    }
    SoSeparator * root = SoDB::readAll(&input); 
  
    SbBool vrml1 = input.isFileVRML1();
    SbBool vrml2 = input.isFileVRML2();

    if (vrml2) {
      fprintf(stderr,"VRML2 not supported yet\n");
      return -1;
    }
  
    if (!root) {
      fprintf(stderr,"Unable to read file.\n");
      return -1;
    }
    root->ref();

    fprintf(stderr,"Applying SoReorganizeAction...");
    SoReorganizeAction reorg;
    reorg.apply(root);
    fprintf(stderr,"done\n");

    SoOutput out;
    if (out.openFile(argv[2])) {      
      if (strip) { // strip coord3, texcoord and normal nodes
        fprintf(stderr,"stripping old nodes from scene graph\n");
        strip_node(SoCoordinate3::getClassTypeId(), root);
        strip_node(SoCoordinate4::getClassTypeId(), root);
        strip_node(SoNormal::getClassTypeId(), root);
        strip_node(SoTextureCoordinate2::getClassTypeId(), root);
      }
      fprintf(stderr,"writing target\n");
      SoWriteAction wa(&out);
      wa.apply(root);
    }
    root->unref();
    return 0;
  } // main()

Since:
Coin 2.5

Public Member Functions

virtual SoType getTypeId (void) const
 SoReorganizeAction (SoSimplifier *simplifier=NULL)
virtual ~SoReorganizeAction (void)
SoSeparatorgetSimplifiedSceneGraph (void) const
void generateNormals (SbBool onoff)
SbBool areNormalGenerated (void) const
void generateTriangleStrips (SbBool onoff)
SbBool areTriangleStripGenerated (void) const
void generateTexCoords (SbBool onoff)
SbBool areTexCoordsGenerated (void) const
void generateVPNodes (SbBool onoff)
SbBool areVPNodesGenerated (void)
void matchIndexArrays (SbBool onoff)
SbBool areIndexArraysMatched (void) const
SoSimplifier * getSimplifier (void) const
virtual void apply (SoNode *root)
virtual void apply (SoPath *path)
virtual void apply (const SoPathList &pathlist, SbBool obeysrules=0)

Static Public Member Functions

static SoType getClassTypeId (void)
static void addMethod (const SoType type, SoActionMethod method)
static void enableElement (const SoType type, const int stackindex)
static void initClass (void)
static void startReport (const char *msg)
static void finishReport (void)

Protected Member Functions

virtual const
SoEnabledElementsList
getEnabledElements (void) const
virtual void beginTraversal (SoNode *node)

Static Protected Member Functions

static SoEnabledElementsListgetClassEnabledElements (void)
static SoActionMethodListgetClassActionMethods (void)

Constructor & Destructor Documentation

SoReorganizeAction::~SoReorganizeAction ( void   )  [virtual]

The destructor.


Member Function Documentation

void SoReorganizeAction::addMethod ( const SoType  type,
SoActionMethod  method 
) [static]

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

void SoReorganizeAction::enableElement ( const SoType  type,
const int  stackindex 
) [static]

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.


The documentation for this class was generated from the following files:

Copyright © 1998-2008 by Kongsberg SIM. All rights reserved.

Generated on Tue May 5 02:52:20 2009 for Coin by Doxygen 1.5.5.