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:
    SoCallback, SoEventCallback, SoShape
    • Constructor Detail

      • SoCallbackAction

        public SoCallbackAction()
        The constructor.
    • Method Detail

      • addPreTailCallback

        public void addPreTailCallback​(SoCallbackActionCB cb,
                                       java.lang.Object userData)
      • addPostTailCallback

        public void addPostTailCallback​(SoCallbackActionCB cb,
                                        java.lang.Object userData)
      • addPreCallback

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

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

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

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

        public void addPointCallback​(java.lang.Class<? extends SoNode> nodeClass,
                                     SoPointCB cb,
                                     java.lang.Object userData)
      • 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)
      • getPointSize

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

        public void invokePostCallbacks​(SoNode node)
      • getFontName

        public java.lang.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.
      • enableElement

        public static void enableElement​(java.lang.Class<? extends Inventor> t,
                                         int stkIndex)
      • 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.
      • 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.
      • getLinePatternScaleFactor

        public int getLinePatternScaleFactor()
        Returns the current drawing style information from the state.
      • 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.
      • getModelMatrix

        public SbMatrix getModelMatrix()
        Returns the current modeling transformation 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.
      • getTextureFileName

        public java.lang.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.
      • 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 java.util.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.
      • 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.