Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoRayPickAction Class Reference

The SoRayPickAction class does ray intersection with scene graphs. More...

#include <Inventor/actions/SoRayPickAction.h>

Inheritance diagram for SoRayPickAction:
SoPickAction SoAction

Public Member Functions

 SoRayPickAction (const SbViewportRegion &viewportregion)
 
virtual ~SoRayPickAction ()
 
SoPickedPointaddIntersection (const SbVec3f &objectspacepoint, SbBool frontpick=TRUE)
 
void computeWorldSpaceRay (void)
 
const SbLinegetLine (void)
 
SoPickedPointgetPickedPoint (const int index=0) const
 
const SoPickedPointListgetPickedPointList (void) const
 
float getRadius (void) const
 
virtual SoType getTypeId (void) const
 
const SbViewVolumegetViewVolume (void)
 
SbBool hasWorldSpaceRay (void) const
 
SbBool intersect (const SbBox3f &box, const SbBool usefullviewvolume=TRUE)
 
SbBool intersect (const SbBox3f &box, SbVec3f &intersection, const SbBool usefullviewvolume=TRUE)
 
SbBool intersect (const SbVec3f &point) const
 
SbBool intersect (const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2, SbVec3f &intersection, SbVec3f &barycentric, SbBool &front) const
 
SbBool intersect (const SbVec3f &v0, const SbVec3f &v1, SbVec3f &intersection) const
 
SbBool isBetweenPlanes (const SbVec3f &intersection) const
 
SbBool isPickAll (void) const
 
void reset (void)
 
void setNormalizedPoint (const SbVec2f &normpoint)
 
void setObjectSpace (const SbMatrix &matrix)
 
void setObjectSpace (void)
 
void setPickAll (const SbBool flag)
 
void setPoint (const SbVec2s &viewportPoint)
 
void setRadius (const float radiusinpixels)
 
void setRay (const SbVec3f &start, const SbVec3f &direction, float neardistance=-1.0, float fardistance=-1.0)
 
- Public Member Functions inherited from SoPickAction
void enableCulling (const SbBool flag)
 
const SbViewportRegiongetViewportRegion (void) const
 
SbBool isCullingEnabled (void) const
 
void setViewportRegion (const SbViewportRegion &newregion)
 
- Public Member Functions inherited from SoAction
virtual ~SoAction (void)
 
virtual void apply (const SoPathList &pathlist, SbBool obeysrules=FALSE)
 
void apply (SoAction *beingApplied)
 
virtual void apply (SoNode *root)
 
virtual void apply (SoPath *path)
 
const SoPathgetCurPath (void)
 
PathCode getCurPathCode (void) const
 
virtual SoNodegetCurPathTail (void)
 
SoNodegetNodeAppliedTo (void) const
 
const SoPathListgetOriginalPathListAppliedTo (void) const
 
SoPathgetPathAppliedTo (void) const
 
PathCode getPathCode (int &numindices, const int *&indices)
 
const SoPathListgetPathListAppliedTo (void) const
 
SoStategetState (void) const
 
AppliedCode getWhatAppliedTo (void) const
 
SbBool hasTerminated (void) const
 
virtual void invalidateState (void)
 
SbBool isLastPathListAppliedTo (void) const
 
virtual SbBool isOfType (SoType type) const
 
void popCurPath (const PathCode prevpathcode)
 
void popCurPath (void)
 
void popPushCurPath (const int childindex, SoNode *node=NULL)
 
void pushCurPath (const int childindex, SoNode *node=NULL)
 
void pushCurPath (void)
 
void switchToNodeTraversal (SoNode *node)
 
void switchToPathTraversal (SoPath *path)
 
void traverse (SoNode *const node)
 
void usePathCode (int &numindices, const int *&indices)
 

Static Public Member Functions

static void addMethod (const SoType type, SoActionMethod method)
 
static void enableElement (const SoType type, const int stackindex)
 
static SoType getClassTypeId (void)
 
static void initClass (void)
 
- Static Public Member Functions inherited from SoPickAction
static void addMethod (const SoType type, SoActionMethod method)
 
static void enableElement (const SoType type, const int stackindex)
 
static SoType getClassTypeId (void)
 
static void initClass (void)
 
- Static Public Member Functions inherited from SoAction
static SoType getClassTypeId (void)
 
static void initClass (void)
 
static void initClasses (void)
 
static void nullAction (SoAction *action, SoNode *node)
 

Protected Member Functions

virtual void beginTraversal (SoNode *node)
 
virtual const SoEnabledElementsListgetEnabledElements (void) const
 
- Protected Member Functions inherited from SoPickAction
 SoPickAction (const SbViewportRegion &viewportregion)
 
virtual ~SoPickAction (void)
 
- Protected Member Functions inherited from SoAction
 SoAction (void)
 
virtual void endTraversal (SoNode *node)
 
void setTerminated (const SbBool flag)
 
virtual SbBool shouldCompactPathList (void) const
 

Static Protected Member Functions

static SoActionMethodListgetClassActionMethods (void)
 
static SoEnabledElementsListgetClassEnabledElements (void)
 
- Static Protected Member Functions inherited from SoPickAction
static SoActionMethodListgetClassActionMethods (void)
 
static SoEnabledElementsListgetClassEnabledElements (void)
 
- Static Protected Member Functions inherited from SoAction
static SoActionMethodListgetClassActionMethods (void)
 
static SoEnabledElementsListgetClassEnabledElements (void)
 

Additional Inherited Members

- Public Types inherited from SoAction
enum  AppliedCode { NODE = 0 , PATH = 1 , PATH_LIST = 2 }
 
enum  PathCode { NO_PATH = 0 , IN_PATH = 1 , BELOW_PATH = 2 , OFF_PATH = 3 }
 
- Protected Attributes inherited from SoPickAction
SbViewportRegion vpRegion
 
- Protected Attributes inherited from SoAction
SoStatestate
 
SoActionMethodListtraversalMethods
 

Detailed Description

The SoRayPickAction class does ray intersection with scene graphs.

For interaction with the scene graph geometry, it is necessary to be able to do intersection testing for rays. This functionality is provided by the SoRayPickAction class.

SoRayPickAction can be used to pass arbitrary rays through the scene for intersection detections, by using the setRay() method.

Because a very common operation is to check for intersections along the ray from the mouse cursor upon mouse clicks, it also contains convenience methods for setting up a ray from the near plane to the far plane from the 2D mouse cursor coordinates. See the setPoint() and setNormalizedPoint() methods. A simple usage example for this case is presented below.

Note that one common mistake when using a ray pick action to intersect from a point under the mouse cursor after a mouse click is that one tries to apply it to a scene graph that does not contain a camera explicitly set up by the application programmer. Without a camera as part of the traversal, the ray pick action does not know which view volume to send the ray through.

In this regard, be aware that the getSceneGraph() call in the So*-libraries' viewer classes will return the root of the user-supplied scene graph, not the "real" internal scene graph root used by the viewer (which should always contain a camera node). So ray picks done from the application code will fail when doing this:

// initializing viewer scene graph
SoSeparator * root = new SoSeparator;
root->ref();
root->addChild(ecb);
root->addChild(new SoCone);
viewer->setSceneGraph( root );
// -- [snip] -------------------------
// attempting ray pick in the event_cb() callback method
SoRayPickAction rp( viewer->getViewportRegion() );
rp.setPoint(mouseevent->getPosition());
rp.apply(viewer->getSceneGraph());
// BUG: results will not be what you expected, as no camera was
// part of the "user's scene graph"
The SbList class is a template container class for lists.
Definition SbList.h:70
void ref(void) const
Definition SoBase.cpp:478
The SoCone class is for rendering cone shapes.
Definition SoCone.h:41
The SoEventCallback class provides functionality for catching events.
Definition SoEventCallback.h:52
virtual void addChild(SoNode *node)
Definition SoGroup.cpp:453
static SoType getClassTypeId(void)
Definition SoMouseButtonEvent.cpp:100
The SoRayPickAction class does ray intersection with scene graphs.
Definition SoRayPickAction.h:50
The SoSeparator class is a state-preserving group node.
Definition SoSeparator.h:44

While this is the correct way to do it:

// initializing viewer scene graph
SoSeparator * root = new SoSeparator;
root->ref();
// Need to set up our own camera in the "user scene graph", or else
// the ray pick action will fail because the camera is hidden in the
// viewer-specific root of the scene graph.
root->addChild(pcam);
root->addChild(ecb);
root->addChild(new SoCone);
viewer->setSceneGraph( root );
pcam->viewAll( root, viewer->getViewportRegion() );
// -- [snip] -------------------------
// attempting ray pick in the event_cb() callback method
SoRayPickAction rp( viewer->getViewportRegion() );
rp.setPoint(mouseevent->getPosition());
rp.apply(viewer->getSceneGraph());
The SoPerspectiveCamera class defines a camera node with perspective rendering.
Definition SoPerspectiveCamera.h:39

Or if you do want the convenience of having the viewer set up a camera for you implicitly, you can get hold of the root-node of the "complete" scene graph by simply calling:

SoNode * realroot = viewer->getSceneManager()->getSceneGraph();
The SoNode class is the base class for nodes used in scene graphs.
Definition SoNode.h:56

Constructor & Destructor Documentation

◆ SoRayPickAction()

SoRayPickAction::SoRayPickAction ( const SbViewportRegion & viewportregion)

Constructor.

Some node types need a viewportregion to know exactly how they are positioned within the scene. For an in-depth explanation of why the viewportregion argument is needed, see the documentation of SoGetBoundingBox::SoGetBoundingBox(const SbViewportRegion &).

◆ ~SoRayPickAction()

SoRayPickAction::~SoRayPickAction ( void )
virtual

Destructor, free temporary resources used by action.

Member Function Documentation

◆ addIntersection()

SoPickedPoint * SoRayPickAction::addIntersection ( const SbVec3f & objectspacepoint_in,
SbBool frontpick = TRUE )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ addMethod()

void SoRayPickAction::addMethod ( const SoType type,
SoActionMethod method )
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ beginTraversal()

void SoRayPickAction::beginTraversal ( SoNode * node)
protectedvirtual

This virtual method is called from SoAction::apply(), and is the entry point for the actual scene graph traversal.

It can be overridden to initialize the action at traversal start, for specific initializations in the action subclasses inheriting SoAction.

Default method just calls traverse(), which any overridden implementation of the method must do too (or call SoAction::beginTraversal()) to trigger the scene graph traversal.

Reimplemented from SoPickAction.

◆ computeWorldSpaceRay()

void SoRayPickAction::computeWorldSpaceRay ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ enableElement()

void SoRayPickAction::enableElement ( const SoType type,
const int stackindex )
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ getClassActionMethods()

SoActionMethodList * SoRayPickAction::getClassActionMethods ( void )
staticprotected

Returns list of action methods for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.

◆ getClassEnabledElements()

SoEnabledElementsList * SoRayPickAction::getClassEnabledElements ( void )
staticprotected

Returns list of enabled elements for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.

◆ getClassTypeId()

SoType SoRayPickAction::getClassTypeId ( void )
static

This static method returns the SoType object associated with objects of this class.

◆ getEnabledElements()

const SoEnabledElementsList & SoRayPickAction::getEnabledElements ( void ) const
protectedvirtual

Returns list of enabled elements.

Reimplemented from SoPickAction.

◆ getLine()

const SbLine & SoRayPickAction::getLine ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ getPickedPoint()

SoPickedPoint * SoRayPickAction::getPickedPoint ( const int index = 0) const

Returns the picked point with index in the list of picked points.

Returns NULL if less than index + 1 points where picked during the last ray pick action.

◆ getPickedPointList()

const SoPickedPointList & SoRayPickAction::getPickedPointList ( void ) const

Returns a list of the picked points.

◆ getRadius()

float SoRayPickAction::getRadius ( void ) const

Gets the radius of the picking ray, in screen pixels.

◆ getTypeId()

SoType SoRayPickAction::getTypeId ( void ) const
virtual

Returns the type identification of an object derived from a class inheriting SoAction. This is used for runtime type checking and "downward" casting.

Reimplemented from SoPickAction.

◆ getViewVolume()

const SbViewVolume & SoRayPickAction::getViewVolume ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ hasWorldSpaceRay()

SbBool SoRayPickAction::hasWorldSpaceRay ( void ) const

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ initClass()

void SoRayPickAction::initClass ( void )
static

Initializes the runtime type system for this class, and sets up the enabled elements and action method list.

◆ intersect() [1/5]

SbBool SoRayPickAction::intersect ( const SbBox3f & box,
const SbBool usefullviewvolume = TRUE )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ intersect() [2/5]

SbBool SoRayPickAction::intersect ( const SbBox3f & box,
SbVec3f & intersection,
const SbBool usefullviewvolume = TRUE )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ intersect() [3/5]

SbBool SoRayPickAction::intersect ( const SbVec3f & point_in) const

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ intersect() [4/5]

SbBool SoRayPickAction::intersect ( const SbVec3f & v0_in,
const SbVec3f & v1_in,
const SbVec3f & v2_in,
SbVec3f & intersection,
SbVec3f & barycentric,
SbBool & front ) const

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ intersect() [5/5]

SbBool SoRayPickAction::intersect ( const SbVec3f & v0_in,
const SbVec3f & v1_in,
SbVec3f & intersection ) const

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ isBetweenPlanes()

SbBool SoRayPickAction::isBetweenPlanes ( const SbVec3f & intersection_in) const

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ isPickAll()

SbBool SoRayPickAction::isPickAll ( void ) const

Returns whether only the closest object or all the objects the ray intersects with is picked.

See also
setPickAll()

◆ reset()

void SoRayPickAction::reset ( void )

Truncates the internal picked points list.

Since
Coin 2.2

◆ setNormalizedPoint()

void SoRayPickAction::setNormalizedPoint ( const SbVec2f & normpoint)

Sets the viewport-space point which the ray is sent through. The coordinate is normalized, ranging from (0, 0) to (1, 1).

See also
setPoint()

◆ setObjectSpace() [1/2]

void SoRayPickAction::setObjectSpace ( const SbMatrix & matrix)

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ setObjectSpace() [2/2]

void SoRayPickAction::setObjectSpace ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ setPickAll()

void SoRayPickAction::setPickAll ( const SbBool flag)

Lets you decide whether or not all the objects the ray intersects with should be picked. If not, only the intersection point of the object closest to the camera will be picked.

Default value of the "pick all" flag is FALSE.

◆ setPoint()

void SoRayPickAction::setPoint ( const SbVec2s & viewportpoint)

Sets the viewport-space point. This point is calculated into a line from the near clipping plane to the far clipping plane, and the intersection ray follows the line.

This is a convenient way to detect object intersection below the cursor.

◆ setRadius()

void SoRayPickAction::setRadius ( const float radiusinpixels)

Sets the radius of the picking ray, in screen pixels. Default value is 5.0.

The radius of the intersection ray will only influence the pick operation's behavior versus lines and points, and has no effect on picking of shapes / polygons.

◆ setRay()

void SoRayPickAction::setRay ( const SbVec3f & start,
const SbVec3f & direction,
float neardistance = -1.0,
float fardistance = -1.0 )

Sets the intersection ray in world space coordinates.

Use this method if you want to send any ray through the scene to detect intersections, independently of mouse cursor position upon clicks and scene graph camera settings.


The documentation for this class was generated from the following files: