Class SoCallbackAction
- Direct Known Subclasses:
SoSTLWriteAction,SoToU3DAction
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.
Apply a callback action to visit all shape nodes.
This method will be called for each shape node in the scene graph.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 triangle in the shape node.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(); } }
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic enumPossible responses from a pre or post callback.static classNested classes/interfaces inherited from class com.openinventor.inventor.actions.SoAction
SoAction.AppliedCodes, SoAction.DistribModes, SoAction.PathCodes, SoAction.PathIndicesNested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand -
Field Summary
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLineSegmentCallback(Class<? extends SoNode> nodeClass, SoLineSegmentCB cb, Object userData) voidaddPointCallback(Class<? extends SoNode> nodeClass, SoPointCB cb, Object userData) voidaddPostCallback(Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, Object userData) voidaddPostTailCallback(SoCallbackActionCB cb, Object userData) voidaddPreCallback(Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, Object userData) voidaddPreTailCallback(SoCallbackActionCB cb, Object userData) voidaddTriangleCallback(Class<? extends SoNode> nodeClass, SoTriangleCB cb, Object userData) static voidenableElement(Class<? extends Inventor> t, int stkIndex) floatReturns complexity information from the state.Returns complexity information from the state.getCoordinate3(int index) Returns the current coordinates from the state.getCoordinate4(int index) Returns the current coordinates from the state.floatReturns the current shape hints from the state.floatReturns the current decimation percentage from the state.Returns the current decimation type from the state.Returns the current drawing style information from the state.Returns the current shape hints from the state.floatReturns the current camera and viewing information from the state.Returns the current font information from the state.Returns the current font information from the state.floatReturns the current font information from the state.Returns the current lighting model information from the state.Returns the current lighting model information from the state.shortReturns the current drawing style information from the state.intReturns the current drawing style information from the state.floatReturns the current drawing style information from the state.Calls getMaterial((int)0).getMaterial(int mtlIndex) Returns the current material information from the state.Returns the current material information from the state.Returns the current modeling transformation from the state.getNormal(int index) Returns the current normal information from the state.Returns the current normal information from the state.intReturns the current coordinates from the state.intReturns the current normal information from the state.intReturns the current profiles and their coordinates from the state.intReturns texture information from the state.Returns the current picking style.floatReturns the current drawing style information from the state.Returns the current profiles and their coordinates from the state.getProfileCoordinate2(int index) Returns the current profiles and their coordinates from the state.getProfileCoordinate3(int index) Returns the current profiles and their coordinates from the state.Returns the current camera and viewing information from the state.Returns the current shape hints from the state.intReturns the current switch value.Returns texture information from the state.getTextureCoordinate2(int index) Returns texture information from the state.getTextureCoordinate4(int index) Returns texture information from the state.Returns texture information from the state.Returns texture information from the state.Returns texture information from the state.Returns the current texture mapping information from the state.Returns the current texture mapping information from the state.Returns the current texture mapping information from the state.Returns the current texture mapping information from the state.Returns the current texture mapping information from the state.Returns the current Transparency Type information from the state.getUnits()Returns the current units from the state.Returns the current shape hints from the state.Returns the current camera and viewing information from the state.Returns the current camera and viewing information from the state.voidinvokeLineSegmentCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2) voidinvokePointCallbacks(SoShape shape, SoPrimitiveVertex[] v) voidinvokePostCallbacks(SoNode node) voidinvokePreCallbacks(SoNode node) voidinvokeTriangleCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2, SoPrimitiveVertex[] v3) booleanReturns whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node.voidsetCallbackAll(boolean flag) Sets whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node.booleanshouldGeneratePrimitives(SoShape shape) Methods inherited from class com.openinventor.inventor.actions.SoAction
apply, apply, clearApplyResult, forwardTraversal, forwardTraversal, getContinueActionInBranchFlag, getCurPath, getDistribMode, getNodeAppliedTo, getOriginalPathListAppliedTo, getPathAppliedTo, getPathCode, getPathListAppliedTo, getPipeId, getSceneManager, getState, getWhatAppliedTo, hasTerminated, invalidateState, isBeingApplied, isLastPathListAppliedTo, isUsingAlternateRep, nullAction, postDelayedTraversal, preDelayedTraversal, resetContinueActionInBranchFlag, setPipeId, setSceneManager, setUpState, stopActionInBranch, traverse, useAlternateRepMethods inherited from class com.openinventor.inventor.Inventor
dispose, getNativeResourceHandle
-
Constructor Details
-
SoCallbackAction
public SoCallbackAction()The constructor.
-
-
Method Details
-
addPreTailCallback
-
addPostTailCallback
-
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
-
getMaterial
Calls getMaterial((int)0). -
getFontRenderStyle
Returns the current font information from the state. -
getFontSize
public float getFontSize()Returns the current font information from the state. -
invokePreCallbacks
-
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
-
getFontName
Returns the current font information from the state. -
getMaterial
Returns the current material information from the state. Providing a mtlIndex will return the material defined for that index. -
getMaterialBinding
Returns the current material information from the state. -
getTransparencyType
Returns the current Transparency Type information from the state. -
enableElement
-
getCurrentResponse
-
getLightModel
Returns the current lighting model information from the state. -
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
Returns the current coordinates from the state. -
getCoordinate4
Returns the current coordinates from the state. -
getComplexityType
Returns complexity information from the state. -
getTextureCoordinate4
Returns texture information from the state. -
getComplexity
public float getComplexity()Returns complexity information from the state. -
getDecimationType
Returns the current decimation type from the state. -
getLinePatternScaleFactor
public int getLinePatternScaleFactor()Returns the current drawing style information from the state. -
invokePointCallbacks
-
getLineWidth
public float getLineWidth()Returns the current drawing style information from the state. -
shouldGeneratePrimitives
-
getDecimationPercentage
public float getDecimationPercentage()Returns the current decimation percentage from the state. -
getDrawStyle
Returns the current drawing style information from the state. -
getLinePattern
public short getLinePattern()Returns the current drawing style information from the state. -
getTextureWrapT
Returns the current texture mapping information from the state. -
getCreaseAngle
public float getCreaseAngle()Returns the current shape hints from the state. -
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
Returns the current units from the state. -
getShapeType
Returns the current shape hints from the state. -
getModelMatrix
Returns the current modeling transformation from the state. -
getFaceType
Returns the current shape hints from the state. -
getTextureBlendColor
Returns texture information from the state. -
getTextureMatrix
Returns the current texture mapping information from the state. -
getTextureImage
Returns texture information from the state.getTextureImage()returns NULL if no texture is enabled. -
getTextureFileName
Returns texture information from the state. -
getTextureModel
Returns the current texture mapping information from the state. -
getTextureCoordinate2
Returns texture information from the state. -
getTextureCoordinateBinding
Returns texture information from the state. -
getTextureTransformNode
Returns the current texture mapping information from the state. -
getSwitch
public int getSwitch()Returns the current switch value. -
getNormalBinding
Returns the current normal information from the state. -
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
Returns the current normal information from the state. -
getProjectionMatrix
Returns the current camera and viewing information from the state. -
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
Returns the current shape hints from the state. -
getViewVolume
Returns the current camera and viewing information from the state. -
getProfileCoordinate2
Returns the current profiles and their coordinates from the state. -
getViewingMatrix
Returns the current camera and viewing information from the state. -
getProfileCoordinate3
Returns the current profiles and their coordinates from the state.
-