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). | |
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 | Obsolete.
Returns the list of enabled elements for a given action subclass.
(Inherited from SoAction.) | |
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 | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
ForwardTraversal(SoNode) | Traverse a node that is not part of the current scenegraph. | |
ForwardTraversal(SoPath) | Traverse a path that is not part of the current scenegraph. | |
GetContinueActionInBranchFlag | This function indicates if the action must stop in the current branch. | |
GetCurPath | 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. | |
GetDistribMode | Returns the distribution mode of this action across a cluster (ScaleViz-Cluster only). | |
GetHashCode |
Overrides GetHashCode().
(Inherited from SoNetBase.) | |
GetLine | ||
GetNodeAppliedTo | Returns the node the action is being applied to. | |
GetNormalizedPoint | Gets the viewport point in normalized coordinates [0..1] (returns the last value passed to OIV.Inventor.Actions.SoRayPickAction.SetNormalizedPoint(OIV.Inventor.SbVec2f)). | |
GetOriginalPathListAppliedTo | Returns the original path list the action is being applied to. | |
GetPathAppliedTo | Returns the path the action is being applied to. | |
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 | Returns the path list the action is being applied to. | |
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 | Gets the state from the action. | |
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 | Returns code indicating what action is being applied to. | |
HasTerminated | Returns true if the traversal has reached a termination condition. | |
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 | Returns true if the current list is the last one from the original. | |
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 | Creates state if it is NULL or it is no longer valid because new elements have been enabled since it was created. | |
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 | Does traversal of a graph rooted by a node. | |
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 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:
MeshVizXLM surface shapes are rendered with MoDrawStyle.displayFaces true and MoMaterial.enhancedColoring false.
The picking mode is DEFAULT, see OIV.Inventor.Actions.SoRayPickAction.SetPickingMode(OIV.Inventor.Actions.SoRayPickAction.PickingModes).
The pick all property is false, see OIV.Inventor.Actions.SoRayPickAction.SetPickAll(System.Boolean).
The picked shape is not in a OIV.Inventor.Nodes.SoRenderToTarget.
The action is associated with a scene manager, see OIV.Inventor.Actions.SoAction.SetSceneManager(OIV.Inventor.SoSceneManager).
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.
If necessary, you can force the OIV.VolumeViz.Nodes.SoVolumeRender to use only the CPU by setting the environment variable IVVR_GPU_PICKING to 0 (see OIV.Inventor.SoPreferences). The OIV.Inventor.Nodes.SoPickStyle.method is ignored by OIV.VolumeViz.Nodes.SoVolumeRender.
The class OIV.VolumeViz.Nodes.SoHeightFieldRender uses the GPU to process a ray pick action. IVVR_GPU_PICKING variable and OIV.Inventor.Nodes.SoPickStyle.method are ignored. You cannot force the OIV.VolumeViz.Nodes.SoHeightFieldRender to use only the CPU.
The classes OIV.VolumeViz.Nodes.SoOrthoSlice, OIV.VolumeViz.Nodes.SoObliqueSlice, OIV.VolumeViz.Nodes.SoFenceSlice and OIV.VolumeViz.Nodes.SoVolumeSkin do not use the GPU to process a ray pick action. IVVR_GPU_PICKING variable and OIV.Inventor.Nodes.SoPickStyle.method are ignored. You cannot force these classes to use the GPU.
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
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(); } } }