SoRayPickAction Class |
Intersects objects with a ray cast into scene.
Namespace: OIV.Inventor.Actions
The SoRayPickAction type exposes the following members.
Name | Description | |
---|---|---|
SoRayPickAction | Constructor takes viewport region to use for picking. |
Name | Description | |
---|---|---|
AddIntersection | Adds an OIV.Inventor.SoPickedPoint instance representing the given object space point to the current list and returns it. | |
AddIntersection_ | ||
Apply(SoNode) | Initiates an action on the graph defined by a node. | |
Apply(SoPath) | Initiates an action on the graph defined by a path. | |
Apply(SoPathList) | Calls Apply(pathList, false). (Inherited from SoAction.) | |
Apply(SoPathList, Boolean) | Initiates an action on the graph defined by a list of paths. | |
ClearApplyResult | Clears the picked point list. | |
ClearPickedPointList | Obsolete. Clears the picked point list. | |
ComputeWorldSpaceRay | ||
EnableConicPickVolume | Controls the pick volume shape for picking with OIV.Inventor.Actions.SoRayPickAction.SetRay(OIV.Inventor.SbVec3f, OIV.Inventor.SbVec3f, System.Single, System.Single). | |
EnableCulling | (Inherited from SoPickAction.) | |
EnableElement | ||
EnableElements | (Overrides SoPickActionEnableElements.) | |
EnableNormalsGeneration | Enables generation of normal vectors for picked points. | |
EnableRadiusForTriangles | Enable radius for triangle-based shape. | |
EnableTexCoordsGeneration | Enables generation of texture coordinates for picked points. | |
EnableTriangleCulling | Enables culling of triangles relative to the ray frustum. | |
Equals | (Inherited from Object.) | |
ForwardTraversal | Traverse a node that is not part of the current scenegraph. | |
GetContinueActionInBranchFlag | This function indicates if the action must stop in the current branch. | |
GetCurPath | (Inherited from SoAction.) | |
GetDistribMode | Returns the distribution mode of this action across a cluster (ScaleViz-Cluster only) Default is LOCAL_ONLY. | |
GetHashCode |
Overrides GetHashCode().
(Inherited from SoNetBase.) | |
GetLine | ||
GetNodeAppliedTo | (Inherited from SoAction.) | |
GetNormalizedPoint | Gets the viewport point in normalized coordinates 0..1. | |
GetOriginalPathListAppliedTo | (Inherited from SoAction.) | |
GetPathAppliedTo | (Inherited from SoAction.) | |
GetPathCode | 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. | |
GetPathListAppliedTo | (Inherited from SoAction.) | |
GetPickedPoint | Calls GetPickedPoint(System.Int32(0)). | |
GetPickedPoint(Int32) | Returns the indexed picked point from the list. | |
GetPickedPointList | Returns list of picked points. | |
GetPickedPointsListLength | ||
GetPickingMode | Returns the OIV.Inventor.Actions.SoRayPickAction.PickingModes used for the ray pick action. | |
GetPipeId | Gets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration. | |
GetPoint | Gets the viewport point in pixels (returns the last value passed to OIV.Inventor.Actions.SoRayPickAction.SetPoint(OIV.Inventor.SbVec2s)). | |
GetPointFloat | Float version of OIV.Inventor.Actions.SoRayPickAction.GetPoint(). | |
GetRadius | Gets the radius (in pixels) around the point. | |
GetSceneManager | Return the OIV.Inventor.SoSceneManager associated with this action. | |
GetState | (Inherited from SoAction.) | |
GetStereoMode | Returns the view used to perform pick when stereo is active. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
GetUnsortedPickedPoint | ||
GetViewportRegion | Returns current viewport region to use for action. | |
GetViewVolume | ||
GetWhatAppliedTo | (Inherited from SoAction.) | |
HasTerminated | (Inherited from SoAction.) | |
HasWorldSpaceRay | ||
Intersect(SbBox3f) | Calls Intersect(box, true). | |
Intersect(SbVec3f) | ||
Intersect(SbXfBox3f) | Calls Intersect(box, true). | |
Intersect(SbBox3f, Boolean) | Bounding box: just return whether the ray intersects it. | |
Intersect(SbXfBox3f, Boolean) | Bounding box: just return whether the ray intersects it. | |
Intersect(SbVec3f, SbVec3f, SbVec3f) | ||
Intersect(SbVec3f, SbVec3f, SbVec3f, SbVec3f, SbVec3f, Boolean) | ||
InvalidateState | Invalidates the current traversal state in the action, forcing it to be recreated when the action is next applied. | |
IsBeingApplied | Returns true if this action is currently being applied. | |
IsBetweenPlanes | ||
IsConicPickVolume | Returns true if the picking volume is a conic shape (not a frustum). | |
IsCullingEnabled | (Inherited from SoPickAction.) | |
IsLastPathListAppliedTo | (Inherited from SoAction.) | |
IsNormalsGenerationEnabled | Returns whether generation of normal vectors is enabled for picked points. | |
IsPickAll | Returns whether the action will return all objects intersected or just the closest one. | |
IsRadiusEnableForTriangles | Returns whether the pick radius specified by OIV.Inventor.Actions.SoRayPickAction.SetRadius(System.Single) is taken into account for picking on triangle-based shapes. | |
IsTexCoordsGenerationEnabled | Returns whether texture coordinate generation is enabled for picked points. | |
IsTriangleCulling | Returns whether triangle culling is enabled. | |
IsUsingAlternateRep | Returns true if current action is using alternate representations. | |
PostDelayedTraversal | Method called by SoMultiPassManager after delayed pass traversals. | |
PreDelayedTraversal | Method called by SoMultiPassManager before delayed pass traversals. | |
ResetContinueActionInBranchFlag | This function resets the continue action flag. | |
SetNormalizedPoint | Sets the viewport point in normalized coordinates, which range from (0,0) at the lower left to (1,1) at the upper right. | |
SetObjectSpace | ||
SetObjectSpace(SbMatrix) | ||
SetPickAll | Sets whether the action will return all objects intersected or just the closest one. | |
SetPickingMode | Sets the picking mode. | |
SetPipeId | Sets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration. | |
SetPoint(SbVec2f) | Float version of OIV.Inventor.Actions.SoRayPickAction.SetPoint(OIV.Inventor.SbVec2s). | |
SetPoint(SbVec2s) | Sets the viewport point through which the ray passes, starting at the camera position. | |
SetRadius | Sets the radius around the point. | |
SetRay(SbVec3f, SbVec3f) | Calls SetRay(start, direction, -1.0, -1.0). | |
SetRay(Single, SbVec3f, SbVec3f) | Calls SetRay(fovy, start, direction, -1.0, -1.0). | |
SetRay(SbVec3f, SbVec3f, Single) | Calls SetRay(start, direction, nearDistance, -1.0). | |
SetRay(Single, SbVec3f, SbVec3f, Single) | Calls SetRay(fovy, start, direction, nearDistance, -1.0). | |
SetRay(SbVec3f, SbVec3f, Single, Single) | Sets a world-space ray along which to pick. | |
SetRay(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. | |
SetSceneManager | Set the scene manager associated with this action (if any ). | |
SetStereoMode | Tells ray pick action in which view the pick occurs. | |
SetUpState | (Inherited from SoAction.) | |
SetViewportRegion | Sets current viewport region to use for action. | |
StopActionInBranch | This function stops the action in the current Scene Graph branch. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
Traverse | (Inherited from SoAction.) | |
UseAlternateRep | Tell the action to use alternate representations during traversal when available. |
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 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).
Open Inventor does true geometric picking in 3D coordinates (it does not use OpenGL for picking), so there are no limits on the number of objects in the scene or 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 (MeshViz) 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).
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 and OIV.Inventor.Actions.SoLineHighlightRenderAction.
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 consider first how quickly can Open Inventor find the geometry that should be picked. Organizing the scene graph spatially to take advantage of the bounding box optimization can help with this. Second the application should consider how long will it take to find the face that should be picked. For a very large surface this can be significant. Enabling triangle culling, splitting large surfaces into smaller pieces or using proxy geometry may be helpful.
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 OIV.VolumeViz.Nodes.SoVolumeRender nodes:Since Open Inventor 8.6, the OIV.VolumeViz.Nodes.SoVolumeRender node (by default) uses the GPU to compute the picked voxel during an 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 software picking is done. If necessary, using the GPU for volume picking may be disabled by setting the environment variable IVVR_GPU_PICKING to 0 (see OIV.Inventor.SoPreferences).
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 OIV.Inventor.Nodes.SoShape.ComputeObjectSpaceRay(OIV.Inventor.Actions.SoRayPickAction) 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.SoViewportRegionElementDo 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 sender, Object data) { SoMouseButtonEvent evt = (SoMouseButtonEvent)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) { SoFullPath pickedPath = (SoFullPath)pickedPt.GetPath(); SoNode pickedNode = pickedPath.GetTail(); } } }