Click or drag to resize
SoRayPickAction Class

Intersects objects with a ray cast into scene.

Inheritance Hierarchy
SystemObject
  OIV.InventorSoNetBase
    OIV.Inventor.ActionsSoAction
      OIV.Inventor.ActionsSoPickAction
        OIV.Inventor.ActionsSoRayPickAction

Namespace: OIV.Inventor.Actions
Assembly: OIV.Inventor (in OIV.Inventor.dll) Version: 2024.2.1.0 (10.16.1.0)
Syntax
public class SoRayPickAction : SoPickAction

The SoRayPickAction type exposes the following members.

Constructors
  NameDescription
Public methodSoRayPickAction

Constructor takes viewport region to use for picking.

Top
Methods
  NameDescription
Public methodAddIntersection

Adds an OIV.Inventor.SoPickedPoint instance representing the given object space point to the current list and returns it.

Public methodAddIntersection_
Public methodApply(SoNode)

Initiates an action on the graph defined by a node.

(Overrides SoActionApply(SoNode).)
Public methodApply(SoPath)

Initiates an action on the graph defined by a path.

(Overrides SoActionApply(SoPath).)
Public methodApply(SoPathList)
Calls Apply(pathList, false).
Public methodApply(SoPathList, Boolean)

Initiates an action on the graph defined by a list of paths.

(Overrides SoActionApply(SoPathList, Boolean).)
Public methodClearApplyResult

Clears the picked point list.

(Overrides SoActionClearApplyResult.)
Public methodClearPickedPointList Obsolete.

Clears the picked point list.

Public methodComputeWorldSpaceRay
Public methodEnableConicPickVolume

Controls the pick volume shape for picking with OIV.Inventor.Actions.SoRayPickAction.SetRay(OIV.Inventor.SbVec3f, OIV.Inventor.SbVec3f, System.Single, System.Single).

Public methodEnableCulling
(Inherited from SoPickAction.)
Public methodStatic memberEnableElement
Public methodEnableElements Obsolete.
Returns the list of enabled elements for a given action subclass.
(Inherited from SoAction.)
Public methodEnableNormalsGeneration

Enables generation of normal vectors for picked points.

Public methodEnableRadiusForTriangles

Enable radius for triangle-based shape.

Public methodEnableTexCoordsGeneration

Enables generation of texture coordinates for picked points.

Public methodStatic memberEnableTriangleCulling

Enables culling of triangles relative to the ray frustum.

Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodForwardTraversal(SoNode)

Traverse a node that is not part of the current scenegraph.

(Inherited from SoAction.)
Public methodForwardTraversal(SoPath)

Traverse a path that is not part of the current scenegraph.

(Inherited from SoAction.)
Public methodGetContinueActionInBranchFlag

This function indicates if the action must stop in the current branch.

(Inherited from SoAction.)
Public methodGetCurPath

Returns the path accumulated during traversal, i.e., the chain of nodes from the root of the traversed graph to the current node being traversed.

(Inherited from SoAction.)
Public methodGetDistribMode

Returns the distribution mode of this action across a cluster (ScaleViz-Cluster only).

(Inherited from SoAction.)
Public methodGetHashCode
Overrides GetHashCode().
(Inherited from SoNetBase.)
Public methodGetLine
Public methodGetNodeAppliedTo

Returns the node the action is being applied to.

(Inherited from SoAction.)
Public methodGetNormalizedPoint

Gets the viewport point in normalized coordinates [0..1] (returns the last value passed to OIV.Inventor.Actions.SoRayPickAction.SetNormalizedPoint(OIV.Inventor.SbVec2f)).

Public methodGetOriginalPathListAppliedTo

Returns the original path list the action is being applied to.

(Inherited from SoAction.)
Public methodGetPathAppliedTo

Returns the path the action is being applied to.

(Inherited from SoAction.)
Public methodGetPathCode

Returns path code based on where current node (the node at the end of the current path) lies with respect to the path(s) the action is being applied to.

(Inherited from SoAction.)
Public methodGetPathListAppliedTo

Returns the path list the action is being applied to.

(Inherited from SoAction.)
Public methodGetPickedPoint
Calls GetPickedPoint(System.Int32(0)).
Public methodGetPickedPoint(Int32)

Returns the indexed picked point from the list.

Public methodGetPickedPointList

Returns list of picked points.

Public methodGetPickedPointsListLength
Public methodGetPickingMode

Returns the OIV.Inventor.Actions.SoRayPickAction.PickingModes used for the ray pick action.

Public methodGetPipeId

Gets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration.

(Inherited from SoAction.)
Public methodGetPoint

Gets the viewport point in pixels (returns the last value passed to OIV.Inventor.Actions.SoRayPickAction.SetPoint(OIV.Inventor.SbVec2s)).

Public methodGetPointFloat
Public methodGetRadius

Gets the radius (in pixels) around the point.

Public methodGetSceneManager

Return the OIV.Inventor.SoSceneManager associated with this action.

(Inherited from SoAction.)
Public methodGetState

Gets the state from the action.

(Inherited from SoAction.)
Public methodStatic memberGetStereoMode

Returns the view used to perform pick when stereo is active.

Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetUnsortedPickedPoint
Public methodGetViewportRegion

Returns current viewport region to use for action.

(Inherited from SoPickAction.)
Public methodGetViewVolume
Public methodGetWhatAppliedTo

Returns code indicating what action is being applied to.

(Inherited from SoAction.)
Public methodHasTerminated

Returns true if the traversal has reached a termination condition.

(Inherited from SoAction.)
Public methodHasWorldSpaceRay
Public methodIntersect(SbBox3f)
Calls Intersect(box, true).
Public methodIntersect(SbVec3f)
Public methodIntersect(SbXfBox3f)
Calls Intersect(box, true).
Public methodIntersect(SbBox3f, Boolean)

Bounding box: just return whether the ray intersects it.

Public methodIntersect(SbXfBox3f, Boolean)

Bounding box: just return whether the ray intersects it.

Public methodIntersect(SbVec3f, SbVec3f, SbVec3f)
Public methodIntersect(SbVec3f, SbVec3f, SbVec3f, SbVec3f, SbVec3f, Boolean)
Public methodInvalidateState

Invalidates the current traversal state in the action, forcing it to be recreated when the action is next applied.

(Inherited from SoAction.)
Public methodIsBeingApplied

Returns true if this action is currently being applied.

(Inherited from SoAction.)
Public methodIsBetweenPlanes
Public methodIsConicPickVolume

Returns true if the picking volume is a conic shape (not a frustum).

Public methodIsCullingEnabled
(Inherited from SoPickAction.)
Public methodIsLastPathListAppliedTo

Returns true if the current list is the last one from the original.

(Inherited from SoAction.)
Public methodIsNormalsGenerationEnabled

Returns whether generation of normal vectors is enabled for picked points.

Public methodIsPickAll

Returns whether the action will return all objects intersected or just the closest one.

Public methodIsRadiusEnableForTriangles

Returns whether the pick radius specified by OIV.Inventor.Actions.SoRayPickAction.SetRadius(System.Single) is taken into account for picking on triangle-based shapes.

Public methodIsTexCoordsGenerationEnabled

Returns whether texture coordinate generation is enabled for picked points.

Public methodStatic memberIsTriangleCulling

Returns whether triangle culling is enabled.

Public methodIsUsingAlternateRep

Returns true if current action is using alternate representations.

(Inherited from SoAction.)
Public methodPostDelayedTraversal

Method called by SoMultiPassManager after delayed pass traversals.

(Inherited from SoAction.)
Public methodPreDelayedTraversal

Method called by SoMultiPassManager before delayed pass traversals.

(Inherited from SoAction.)
Public methodResetContinueActionInBranchFlag

This function resets the continue action flag.

(Inherited from SoAction.)
Public methodSetNormalizedPoint

Sets the viewport point in normalized coordinates, which range from (0,0) at the lower left to (1,1) at the upper right.

Public methodSetObjectSpace
Public methodSetObjectSpace(SbMatrix)
Public methodSetPickAll

Sets whether the action will return all objects intersected or just the closest one.

Public methodSetPickingMode

Sets the picking mode.

Public methodSetPipeId

Sets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration.

(Inherited from SoAction.)
Public methodSetPoint(SbVec2f)
Public methodSetPoint(SbVec2s)

Sets the viewport point through which the ray passes, starting at the camera position.

Public methodSetRadius

Sets the radius around the point.

Public methodSetRay(SbVec3f, SbVec3f)
Calls SetRay(start, direction, -1.0, -1.0).
Public methodSetRay(Single, SbVec3f, SbVec3f)
Calls SetRay(fovy, start, direction, -1.0, -1.0).
Public methodSetRay(SbVec3f, SbVec3f, Single)
Calls SetRay(start, direction, nearDistance, -1.0).
Public methodSetRay(Single, SbVec3f, SbVec3f, Single)
Calls SetRay(fovy, start, direction, nearDistance, -1.0).
Public methodSetRay(SbVec3f, SbVec3f, Single, Single)

Sets a world-space ray along which to pick.

Public methodSetRay(Single, SbVec3f, SbVec3f, Single, Single)

Sets a world-space ray along which to pick in the the same way as the other version of OIV.Inventor.Actions.SoRayPickAction.SetRay(OIV.Inventor.SbVec3f, OIV.Inventor.SbVec3f, System.Single, System.Single), but allows you to set a view angle value.

Public methodSetSceneManager

Set the scene manager associated with this action (if any ).

(Inherited from SoAction.)
Public methodStatic memberSetStereoMode

Tells ray pick action in which view the pick occurs.

Public methodSetUpState

Creates state if it is NULL or it is no longer valid because new elements have been enabled since it was created.

(Inherited from SoAction.)
Public methodSetViewportRegion

Sets current viewport region to use for action.

(Inherited from SoPickAction.)
Public methodStopActionInBranch

This function stops the action in the current Scene Graph branch.

(Inherited from SoAction.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTraverse

Does traversal of a graph rooted by a node.

(Inherited from SoAction.)
Public methodUseAlternateRep

Tell the action to use alternate representations during traversal when available.

(Inherited from SoAction.)
Top
Remarks

This class performs picking by casting a ray into a scene and performing intersection tests with each object. The ray is extended to be a frustum a pyramid or a rectangular prism, a cone or a cylinder, depending on the camera type and client inputs (refer to OIV.Inventor.Actions.SoRayPickAction.SetRay(OIV.Inventor.SbVec3f, OIV.Inventor.SbVec3f, System.Single, System.Single) and OIV.Inventor.Actions.SoRayPickAction.EnableConicPickVolume(System.Boolean)) for intersection with points and lines. Each intersection is returned as an OIV.Inventor.SoPickedPoint instance.

The picking ray can be specified as either a ray from the camera location through a particular viewport pixel, or as a world-space ray. Calling any of the OIV.Inventor.Actions.SoRayPickAction.SetPoint(OIV.Inventor.SbVec2s), OIV.Inventor.Actions.SoRayPickAction.SetNormalizedPoint(OIV.Inventor.SbVec2f), or OIV.Inventor.Actions.SoRayPickAction.SetRadius(System.Single) methods tells the action to compute the picking ray from a viewport pixel. In this case, a camera node must be encountered during traversal of the scene graph in order to determine the location of the ray in world space.

Callers can request the action to compute all intersections along the ray (sorted closest to farthest) by setting the pickAll flag to true. By default, the action computes only the closest intersection. In either case, the intersections are returned in an OIV.Inventor.SoPickedPointList. Each intersection can be examined by accessing the appropriate OIV.Inventor.SoPickedPoint in the list. The OIV.Inventor.SoPickedPoint object provides methods to get the path (OIV.Inventor.SoPath) to the picked geometry in the scene graph, the intersection point in 3D space and other info.

The OIV.Inventor.SoPickedPoint object can also return one of the subclasses of OIV.Inventor.Details.SoDetail, which contains more information about the picked geometry. For example, if a polygonal geometry node like OIV.Inventor.Nodes.SoIndexedFaceSet was picked, an OIV.Inventor.Details.SoFaceDetail object is returned which provides methods to get the index of the face in the primitive, the vertices of the face and so on. For vertex based geometry each vertex can then be queried as an OIV.Inventor.Details.SoPointDetail. Note: Texture coordinates for the picked point are not computed by default (to save time). If you need this information, use OIV.Inventor.Actions.SoRayPickAction.EnableTexCoordsGeneration(System.Boolean). Or set the environment variable OIV_PICK_GENERATE_ALL_PROPERTIES. You can also disable computing the normal vector for the picked if you do not need this information. See OIV.Inventor.Actions.SoRayPickAction.EnableNormalsGeneration(System.Boolean).

In the default mode, Inventor computes the intersection of the pick ray with geometry nodes (face, line, point, volume, mesh, etc). In this case OIV.Inventor.SoPickedPoint.GetPoint() returns the coordinate of the intersection and OIV.Inventor.SoPickedPoint.GetDetail(OIV.Inventor.Nodes.SoNode) typically returns an OIV.Inventor.Details.SoDetail class specific to the picked geometry. Since Open Inventor 9.0, OIV.Inventor.Actions.SoRayPickAction also supports a POINT_PICKING mode (see OIV.Inventor.Actions.SoRayPickAction.PickingModes). In this mode, Inventor finds all the vertices inside the pick radius. This is only supported for OIV.Inventor.Nodes.SoBufferedShape and classes derived from OIV.Inventor.Nodes.SoIndexedShape. This mode can be much faster because, for example, it does not need to check for intersection with all the triangles of an OIV.Inventor.Nodes.SoIndexedFaceSet.

Applications can use the OIV.Inventor.Nodes.SoPickStyle node to control if and how geometry can be picked. For example application might want to specify that annotation geometry, e.g. a legend, is not pickable. It can also specify that geometry should be picked using its bounding box rather than exact geometry. This may be more efficient for text strings when it is not necessary to know which character in the string was picked.

The application can get platform independent input events, e.g. mouse button press, as OIV.Inventor.Events.SoEvent objects using the OIV.Inventor.Nodes.SoEventCallback node. In the delegatefunction the application can create an OIV.Inventor.Actions.SoRayPickAction and apply it to the scene graph. Note however that the application can also simply call the node's OIV.Inventor.Actions.SoRayPickAction.GetPickedPoint(System.Int32) method. In this case Open Inventor automatically applies a pick action to the scene graph and returns the result, so the application does not need to use OIV.Inventor.Actions.SoRayPickAction directly. Creating and using an OIV.Inventor.Actions.SoRayPickAction explicitly does allow more options to be set. In this case the application will normally call OIV.Inventor.Actions.SoRayPickAction.SetPoint(OIV.Inventor.SbVec2s) with the position obtained from the event object. If using system events directly, remember that Open Inventor expects Y pixel values to start from zero at the bottom of the window.

The OIV.Inventor.Nodes.SoSelection node provides an even higher level way to manage selecting and de-selecting objects in the scene. This node automatically applies a pick action and maintains a list of currently selected objects (paths). Using OIV.Inventor.Nodes.SoSelection the application does not need to use OIV.Inventor.Actions.SoRayPickAction directly. The OIV.Inventor.Nodes.SoExtSelection node provides more complex picking algorithms. For example it allows the user to select objects using a "rubberband" rectangle or a freeform shape (lasso). Open Inventor provides special render actions that can automatically highlight objects selected using an OIV.Inventor.Nodes.SoSelection or OIV.Inventor.Nodes.SoExtSelection node. See OIV.Inventor.Actions.SoBoxHighlightRenderAction, OIV.Inventor.Actions.SoHaloHighlightRenderAction and OIV.Inventor.Actions.SoLineHighlightRenderAction.

Picking algorithm on vertex shapes

Open Inventor implements two different picking algorithms for shapes defined by vertices: the GPU picking algorithm and the CPU picking algorithm.

The GPU picking algorithm is very efficient when the shapes have millions of vertices. For now, only OIV.Inventor.Nodes.SoPointSet and MeshVizXLM surface shapes (such as MoMeshSkin) are compatible with GPU picking. These conditions are required to activate GPU picking:

Note: if gl_FragDepth is modified in the shader, the retrieved picked point is wrong.

The CPU picking algorithm is used when the previous conditions are not met. In this case, it does true geometric picking in 3D coordinates, so there are no limits to the number of objects that can be picked. Geometric picking means that precise intersections with the geometry are computed. It also means that picking works for any type of primitive, including polygonal geometry, meshes and volumes (VolumeViz). The picking volume can be projected through the scene using orthogonal or perspective projection. See OIV.Inventor.Actions.SoRayPickAction.SetRay(OIV.Inventor.SbVec3f, OIV.Inventor.SbVec3f, System.Single, System.Single) for details. The shape of the picking volume can be rectangular (prism if orthogonal, frustum if perspective) or conic (cylinder if orthogonal, cone if perspective). See OIV.Inventor.Actions.SoRayPickAction.EnableConicPickVolume(System.Boolean).

If the OIV.Inventor.Nodes.SoPickStyle.method selected is AUTO, Open Inventor chooses the most appropriate method (CPU or GPU) for each shape traversed in the scene graph.

CPU picking optimization

Pick traversals are optimized using hierarchical bounding boxes cached at the OIV.Inventor.Nodes.SoSeparator (and a few other) grouping nodes. If the pick ray does not intersect the bounding box then the pick action will not traverse the children of that separator. When optimizing for picking, the application should first consider how quickly Open Inventor can find the geometry to pick. Organizing the scene graph spatially to take advantage of the bounding box optimization can help with this. Second the application should consider how long it will take to find the face to pick. For a very large surface this can take a significant time. Enabling triangle culling, splitting large surfaces into smaller pieces or using proxy geometry may help to reduce the time taken.

Traversing the camera node:

Note that when using OIV.Inventor.Actions.SoRayPickAction with pixel coordinates (OIV.Inventor.Actions.SoRayPickAction.SetPoint(OIV.Inventor.SbVec2s)) the pick action must traverse a camera node in order to unproject the coordinate back into 3D space. If the application explicitly creates its own camera, this is usually not a problem because the camera is in the application scene graph. However, if the application allows the viewer to automatically create a camera then the camera is in the viewer's scene graph above the application scene graph. Calling the viewer's getSceneGraph() method returns the application scene graph, not the complete viewer scene graph. To ensure that the traversed scene graph contains a camera, call the viewer's OIV.Inventor.Actions.SoAction.GetSceneManager() method, then call the scene manager's getSceneGraph method. Alternatively, in an event callback call the event action's getPickRoot() method.

Picking VolumeViz shapes:

The OIV.VolumeViz.Nodes.SoVolumeRender and OIV.VolumeViz.Nodes.SoHeightFieldRender nodes uses the GPU to compute the picked voxel during a OIV.Inventor.Actions.SoRayPickAction. For this to work, the OIV.Inventor.Actions.SoRayPickAction must have its scene manager initialised using the method OIV.Inventor.Actions.SoAction.SetSceneManager(OIV.Inventor.SoSceneManager). OIV.Inventor.Actions.SoHandleEventAction does this automatically, so it is not necessary for the application to take any action when using (for example) an OIV.Inventor.Nodes.SoEventCallback node and calling the OIV.Inventor.Actions.SoRayPickAction.GetPickedPoint(System.Int32) method. However, if the application creates its own OIV.Inventor.Actions.SoRayPickAction then it should set the scene manager. If no scene manager is specified, a warning message is issued and the ray pick action is processed on the CPU.

Hidden references:

OIV.Inventor.Actions.SoRayPickAction creates one or more OIV.Inventor.SoPath objects when applied to the scene graph. The OIV.Inventor.SoPath object references each node in the path. This reference will prevent the node and its associated memory from being reclaimed for as long as the OIV.Inventor.SoPath object exists. These OIV.Inventor.SoPath objects are stored internally in the action and exist until the action object itself is reclaimed or reset (see OIV.Inventor.Actions.SoRayPickAction.ClearApplyResult()).

Shapes that redefine the rayPick method:

In order to make this action work properly with respect to the picked path stored in the picked point list, any shape that redefines the rayPick method must either call the method OIV.Inventor.Actions.SoRayPickAction.SetObjectSpace() or the method SoShape.computeObjectSpaceRay() in its rayPick method before calling the OIV.Inventor.Actions.SoRayPickAction.AddIntersection(OIV.Inventor.SbVec3f) methods. See the chapter "Creating a node - Creating a Shape Node - Picking" in the Inventor Toolmaker Volume 1.

Sets: OIV.Inventor.Elements.SoPickRayElement, OIV.Inventor.Elements.SoViewportRegionElement

EXAMPLE

Do picking using an OIV.Inventor.Nodes.SoEventCallback node. Note: In this case, you could do picking by simply calling the OIV.Inventor.Actions.SoHandleEventAction's GetPickedPoint()method, which applies an OIV.Inventor.Actions.SoRayPickAction internally. However it may be necessary to use OIV.Inventor.Actions.SoRayPickAction directly in order to set specific options.

private void mouseBtnCB(SoEventCallback node, Object data)
{
   SoEvent evt = node.GetEvent();
   // If this is a mouse button1 press event
   if (SoMouseButtonEvent.IsButtonPressEvent( evt, SoMouseButtonEvent.Buttons.BUTTON1 )) {
       SoHandleEventAction action = node.GetAction();
       // Do picking using event's cursor position
       SoRayPickAction rayPick = new SoRayPickAction( action.GetViewportRegion() );
       rayPick.SetPoint( evt.GetPosition() );
       rayPick.SetRadius( 10 ); // Optional: Use larger pick radius
       rayPick.Apply( action.GetPickRoot() );
       SoPickedPoint pickedPt = rayPick.GetPickedPoint();
       if (pickedPt != null) {
           SoPath pickedPath = pickedPt.GetPath();
           SoNode pickedNode = pickedPath.FullPath.GetTail();
       }
   }
}

See Also