Class SoCallbackAction

Direct Known Subclasses:
SoSTLWriteAction, SoToU3DAction

public class SoCallbackAction extends SoAction
Performs a generic traversal of a scene graph or path. Performs a generic traversal of a scene graph or path. In many cases a "custom" action can be implemented using SoCallbackAction with much less complexity than deriving a completely new action class.

The application can specify callback methods that will be called when the action traverses a node of the specified class or a derived class. For example a callback for the SoCone class will only be called for SoCone nodes, but a callback for the SoShape class will be called for any type of shape node.

This makes SoCallbackAction flexible and very convenient for "visiting" a set of nodes, especially when you only need the node itself and not a path to the node. For example, to count all the shapes in the scene graph. It is possible to get the path to the node being visited (see getCurPath() ), but SoSearchAction may be more convenient for getting a path to one or a small number of nodes.

In addition, callback methods can be registered to collect the primitives (trangles, lines and points) generated by shapes in the scene graph. These primitives are the actual geometry if the shape contains triangles, lines or points, else they represent or approximate the actual geometry. NOTE: Most, but not all, shapes can generate primitives. See below for a complete list. Triangle primitives are used for all surfaces (such as cubes, face sets, or 3D text), line segment primitives are used for line shapes, and point primitives are used for point shapes. Note that the type of primitives generated for a shape is the same, regardless of drawing style or other properties.

Most of the methods on this class access information from the traversal state. They should be called only by callback functions that are invoked during traversal, so there is a valid state to work with.

EXAMPLE

Apply a callback action to visit all shape nodes.

 SoCallbackAction action = new SoCallbackAction();
 action.addPreCallback     ( SoShape.class, new NodeCallback(), null );
 action.addTriangleCallback( SoShape.class, new TriangleCallback(), null );
 action.apply( root );
This method will be called for each shape node in the scene graph.
 class NodeCallback extends SoCallbackActionCB {
     @Override
     public int invoke( SoCallbackAction s, SoNode node ) {
         // Print node's name (if any) and class name
         System.out.println( "Shape \"" + node.getName() + "\": " + node.getClass().getName() );
         return SoCallbackAction.Responses.CONTINUE.getValue();
     }
 }
This method will be called for each triangle in the shape node.
 class TriangleCallback extends SoTriangleCB {
     @Override
     public void invoke( SoCallbackAction action, SoPrimitiveVertex v1,
                         SoPrimitiveVertex v2, SoPrimitiveVertex v3 ) {
         System.out.println("  Triangle:");
         printVertex(v1, "1");
         printVertex(v2, "2");
         printVertex(v3, "3");
     }
 
     private void printVertex(SoPrimitiveVertex vertex, String label) {
         SbVec3f point = vertex.getPoint();
         System.out.println("    Vert" + label + " = " + point.getX() + ", "
                 + point.getY() + ", " + point.getZ());
     }
 }

Example output:

Shape "": SoCone
  Triangle:
    Vert1 = 0.0, -1.0, -1.0
    Vert2 = 0.0, 1.0, -0.0
    Vert3 = 0.38268346, -1.0, -0.9238795
  Triangle:
    Vert1 = 0.38268346, -1.0, -0.9238795
    Vert2 = 0.0, 1.0, -0.0
    Vert3 = 0.0, 1.0, -0.0
  . . .
 

See Also:
  • Constructor Details

    • SoCallbackAction

      public SoCallbackAction()
      The constructor.
  • Method Details

    • addPreTailCallback

      public void addPreTailCallback(SoCallbackActionCB cb, Object userData)
    • addPostTailCallback

      public void addPostTailCallback(SoCallbackActionCB cb, Object userData)
    • addPreCallback

      public void addPreCallback(Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, Object userData)
    • addPostCallback

      public void addPostCallback(Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, Object userData)
    • addTriangleCallback

      public void addTriangleCallback(Class<? extends SoNode> nodeClass, SoTriangleCB cb, Object userData)
    • addLineSegmentCallback

      public void addLineSegmentCallback(Class<? extends SoNode> nodeClass, SoLineSegmentCB cb, Object userData)
    • addPointCallback

      public void addPointCallback(Class<? extends SoNode> nodeClass, SoPointCB cb, Object userData)
    • getMaterial

      public SoCallbackAction.Material getMaterial()
      Calls getMaterial((int)0).
    • getFontRenderStyle

      public SoFont.RenderStyles getFontRenderStyle()
      Returns the current font information from the state.
    • getFontSize

      public float getFontSize()
      Returns the current font information from the state.
    • invokePreCallbacks

      public void invokePreCallbacks(SoNode node)
    • invokeTriangleCallbacks

      public void invokeTriangleCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2, SoPrimitiveVertex[] v3)
    • getPointSize

      public float getPointSize()
      Returns the current drawing style information from the state.
    • invokePostCallbacks

      public void invokePostCallbacks(SoNode node)
    • getFontName

      public String getFontName()
      Returns the current font information from the state.
    • getMaterial

      public SoCallbackAction.Material getMaterial(int mtlIndex)
      Returns the current material information from the state. Providing a mtlIndex will return the material defined for that index.
    • getMaterialBinding

      public SoMaterialBinding.Bindings getMaterialBinding()
      Returns the current material information from the state.
    • getTransparencyType

      public SoGLRenderAction.TransparencyTypes getTransparencyType()
      Returns the current Transparency Type information from the state.
    • enableElement

      public static void enableElement(Class<? extends Inventor> t, int stkIndex)
    • getCurrentResponse

      public SoCallbackAction.Responses getCurrentResponse()
    • getLightModel

      public SoLightModel.Models getLightModel()
      Returns the current lighting model information from the state.
    • getLightAttenuation

      public SbVec3f getLightAttenuation()
      Returns the current lighting model information from the state.
    • invokeLineSegmentCallbacks

      public void invokeLineSegmentCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2)
    • getNumCoordinates

      public int getNumCoordinates()
      Returns the current coordinates from the state.
    • getCoordinate3

      public SbVec3f getCoordinate3(int index)
      Returns the current coordinates from the state.
    • getCoordinate4

      public SbVec4f getCoordinate4(int index)
      Returns the current coordinates from the state.
    • getComplexityType

      public SoComplexity.Types getComplexityType()
      Returns complexity information from the state.
    • getTextureCoordinate4

      public SbVec4f getTextureCoordinate4(int index)
      Returns texture information from the state.
    • getComplexity

      public float getComplexity()
      Returns complexity information from the state.
    • getDecimationType

      public SoDecimationTypeElement.Types getDecimationType()
      Returns the current decimation type from the state.
    • getLinePatternScaleFactor

      public int getLinePatternScaleFactor()
      Returns the current drawing style information from the state.
    • invokePointCallbacks

      public void invokePointCallbacks(SoShape shape, SoPrimitiveVertex[] v)
    • getLineWidth

      public float getLineWidth()
      Returns the current drawing style information from the state.
    • shouldGeneratePrimitives

      public boolean shouldGeneratePrimitives(SoShape shape)
    • getDecimationPercentage

      public float getDecimationPercentage()
      Returns the current decimation percentage from the state.
    • getDrawStyle

      public SoDrawStyle.Styles getDrawStyle()
      Returns the current drawing style information from the state.
    • getLinePattern

      public short getLinePattern()
      Returns the current drawing style information from the state.
    • getTextureWrapT

      public SoTexture.WrapType getTextureWrapT()
      Returns the current texture mapping information from the state.
    • getCreaseAngle

      public float getCreaseAngle()
      Returns the current shape hints from the state.
    • getTextureWrapS

      public SoTexture.WrapType getTextureWrapS()
      Returns the current texture mapping information from the state.
    • getNumTextureCoordinates

      public int getNumTextureCoordinates()
      Returns texture information from the state. getNumTextureCoordinates() returns 0 if texture coordinates are generated by a function.
    • getUnits

      public SoUnits.UnitsType getUnits()
      Returns the current units from the state.
    • getShapeType

      public SoShapeHints.ShapeTypes getShapeType()
      Returns the current shape hints from the state.
    • getModelMatrix

      public SbMatrix getModelMatrix()
      Returns the current modeling transformation from the state.
    • getFaceType

      public SoShapeHints.FaceTypes getFaceType()
      Returns the current shape hints from the state.
    • getTextureBlendColor

      public SbColor getTextureBlendColor()
      Returns texture information from the state.
    • getTextureMatrix

      public SbMatrix getTextureMatrix()
      Returns the current texture mapping information from the state.
    • getTextureImage

      public SoCallbackAction.TextureImage getTextureImage()
      Returns texture information from the state. getTextureImage() returns NULL if no texture is enabled.
    • getTextureFileName

      public String getTextureFileName()
      Returns texture information from the state.
    • getTextureModel

      public SoTexture.Models getTextureModel()
      Returns the current texture mapping information from the state.
    • getTextureCoordinate2

      public SbVec2f getTextureCoordinate2(int index)
      Returns texture information from the state.
    • getTextureCoordinateBinding

      public SoTextureCoordinateBinding.Bindings getTextureCoordinateBinding()
      Returns texture information from the state.
    • getTextureTransformNode

      public SoTexture2Transform getTextureTransformNode()
      Returns the current texture mapping information from the state.
    • getSwitch

      public int getSwitch()
      Returns the current switch value.
    • getNormalBinding

      public SoNormalBinding.Bindings getNormalBinding()
      Returns the current normal information from the state.
    • getPickStyle

      public SoPickStyle.Styles getPickStyle()
      Returns the current picking style.
    • getNumProfileCoordinates

      public int getNumProfileCoordinates()
      Returns the current profiles and their coordinates from the state.
    • isCallbackAll

      public boolean isCallbackAll()
      Returns whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node.
    • getNumNormals

      public int getNumNormals()
      Returns the current normal information from the state.
    • setCallbackAll

      public void setCallbackAll(boolean flag)
      Sets whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node. Default is false.
    • getNormal

      public SbVec3f getNormal(int index)
      Returns the current normal information from the state.
    • getProjectionMatrix

      public SbMatrix getProjectionMatrix()
      Returns the current camera and viewing information from the state.
    • getProfile

      public Vector<SoNode> getProfile()
      Returns the current profiles and their coordinates from the state.
    • getFocalDistance

      public float getFocalDistance()
      Returns the current camera and viewing information from the state.
    • getVertexOrdering

      public SoShapeHints.VertexOrderings getVertexOrdering()
      Returns the current shape hints from the state.
    • getViewVolume

      public SbViewVolume getViewVolume()
      Returns the current camera and viewing information from the state.
    • getProfileCoordinate2

      public SbVec2f getProfileCoordinate2(int index)
      Returns the current profiles and their coordinates from the state.
    • getViewingMatrix

      public SbMatrix getViewingMatrix()
      Returns the current camera and viewing information from the state.
    • getProfileCoordinate3

      public SbVec3f getProfileCoordinate3(int index)
      Returns the current profiles and their coordinates from the state.