Open Inventor Reference
SoRayPickAction.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * Further, this software is distributed without any warranty that it is
16  * free of the rightful claim of any third person regarding infringement
17  * or the like. Any license provided herein, whether implied or
18  * otherwise, applies only to this software file. Patent licenses, if
19  * any, provided herein do not apply to combinations of this program with
20  * other software, or any other product whatsoever.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27  * Mountain View, CA 94043, or:
28  *
29  * http://www.sgi.com
30  *
31  * For further information regarding this notice, see:
32  *
33  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34  *
35  */
36 
37 
38 /*
39  * Copyright (C) 1990,91 Silicon Graphics, Inc.
40  *
41  _______________________________________________________________________
42  ______________ S I L I C O N G R A P H I C S I N C . ____________
43  |
44  | $Revision: 1.1.1.1 $
45  |
46  | Description:
47  | Defines the SoRayPickAction class
48  |
49  | Author(s) : Paul S. Strauss, Nick Thompson
50  |
51  ______________ S I L I C O N G R A P H I C S I N C . ____________
52  _______________________________________________________________________
53  */
54 
55 #ifndef _SO_RAY_PICK_ACTION_
56 #define _SO_RAY_PICK_ACTION_
57 
59 #include <Inventor/SoLists.h>
61 
62 
65 
96 
98 
100 
101  public:
102 
106  SoRayPickAction(const SbViewportRegion &viewportRegion);
107 
109  virtual ~SoRayPickAction();
110 
115 
119  void setPoint(const SbVec2s &viewportPoint);
120 
123  void setNormalizedPoint(const SbVec2f &normPoint);
124 
131  void setRadius(float radiusInPixels);
132 
143  void setRay(const SbVec3f &start, const SbVec3f &direction,
144  float nearDistance = -1.0,
145  float farDistance = -1.0);
146 
149  void setPickAll(bool flag) { pickAll = flag; }
152  bool isPickAll() const { return pickAll; }
153 
158 
160  const SoPickedPointList &getPickedPointList() const { return ptList; }
161 
163  SoPickedPoint * getPickedPoint(int index = 0) const;
164 
165  SoEXTENDER public:
166 
173 
176  bool hasWorldSpaceRay() const;
177 
186  void setObjectSpace(const SbMatrix &matrix);
187 
195 
198  bool intersect(const SbVec3f &v0,
199  const SbVec3f &v1,
200  const SbVec3f &v2,
201  SbVec3f &intersection, SbVec3f &barycentric,
202  bool &front) const;
203 
205  bool intersect(const SbVec3f &v0, const SbVec3f &v1,
206  SbVec3f &intersection) const;
207 
209  bool intersect(const SbVec3f &point) const;
210 
215  bool intersect(const SbBox3f &box,
216  bool useFullViewVolume = TRUE);
217 
225  const SbViewVolume &getViewVolume() const { return objVol; }
226 
232  const SbLine & getLine() const { return objLine; }
233 
240  bool isBetweenPlanes(const SbVec3f &intersection) const;
241 
249  SoPickedPoint * addIntersection(const SbVec3f &objectSpacePoint);
250 
251  protected:
253  virtual void beginTraversal(SoNode *node);
254 
255  SoINTERNAL public:
256  static void initClass();
257 
258  private:
259  bool lineWasSet;
260  bool rayWasComputed;
261  bool pickAll;
262  SbVec2s VPPoint;
263  SbVec2f normVPPoint;
264  bool normPointSet;
265  float VPRadius;
266  SbMatrix objToWorld;
267  SbMatrix worldToObj;
268  SoPickedPointList ptList;
269 
273  SbViewVolume worldVol;
274 
279  bool clipToNear, clipToFar;
280 
283  SbLine objLine;
284  SbViewVolume objVol;
285 
290  bool extraMatrixSet;
291  SbMatrix extraMatrix;
292 
294  void computeMatrices();
295 
297  void computeObjVolAndLine();
298 
301  bool isCloser(const SoPickedPoint *pp0,
302  const SoPickedPoint *pp1);
303 
306  static float rayDistance(const SbVec3f &start,
307  const SbVec3f &direction,
308  const SbVec3f &point);
309 };
310 
311 #endif /* _SO_RAY_PICK_ACTION_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition: SbBasic.h:154
#define TRUE
Definition: SbBasic.h:76
#define SoINTERNAL
Definition: SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition: SbSystem.h:81
#define SO_ACTION_HEADER(className)
Macros to be called within the class definition header for an action subclass:
Definition: SoSubAction.h:87
3D box class.
Definition: SbBox.h:81
Directed line in 3D.
Definition: SbLinear.h:1292
4x4 matrix class.
Definition: SbLinear.h:823
2D vector class.
Definition: SbLinear.h:246
2D vector class.
Definition: SbLinear.h:354
3D vector class.
Definition: SbLinear.h:120
3D viewing volume class.
Definition: SbLinear.h:1058
Class for representing a viewport.
Abstract base class for all database nodes.
Definition: SoNode.h:103
Abstract base class for picking objects in a scene.
Definition: SoPickAction.h:77
Maintains a list of pointers to SoPickedPoint instances.
Definition: SoLists.h:383
Represents point on surface of picked object.
Definition: SoPickedPoint.h:89
Intersects objects with a ray cast into scene.
virtual ~SoRayPickAction()
Destructor.
bool isBetweenPlanes(const SbVec3f &intersection) const
Returns TRUE if the given object-space intersection point is between the near and far planes of the o...
bool intersect(const SbBox3f &box, bool useFullViewVolume=TRUE)
Bounding box: just return whether the ray intersects it.
SoPickedPoint * addIntersection(const SbVec3f &objectSpacePoint)
Adds an SoPickedPoint instance representing the given object space point to the current list and retu...
void computeWorldSpaceRay()
If a ray was not defined with setRay(), this causes the world space pick ray to be computed from the ...
void setPickAll(bool flag)
Sets/returns whether the action will return all objects intersected or just the closest one.
bool hasWorldSpaceRay() const
This returns TRUE if the action has had a world space ray set or computed.
void setObjectSpace()
This is called by shapes to set up object space picking.
static void initClass()
void setRay(const SbVec3f &start, const SbVec3f &direction, float nearDistance=-1.0, float farDistance=-1.0)
Sets a world-space ray along which to pick.
const SbLine & getLine() const
Returns SbLine that can be used for other intersection tests.
bool intersect(const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2, SbVec3f &intersection, SbVec3f &barycentric, bool &front) const
These intersect the current object-space ray with a variety of primitives: triangle,...
void setPoint(const SbVec2s &viewportPoint)
Setting up the action before it is applied:
SoRayPickAction(const SbViewportRegion &viewportRegion)
Constructor takes viewport region to use for picking.
SoPickedPoint * getPickedPoint(int index=0) const
Returns the indexed picked point from the list.
virtual void beginTraversal(SoNode *node)
Initiates action on graph.
void setNormalizedPoint(const SbVec2f &normPoint)
Sets the viewport point in normalized coordinates, which range from (0,0) at the lower left to (1,...
bool isPickAll() const
Sets/returns whether the action will return all objects intersected or just the closest one.
const SoPickedPointList & getPickedPointList() const
Examining results after the action is applied:
const SbViewVolume & getViewVolume() const
Returns an SbViewVolume that represents the object-space ray to pick along.
bool intersect(const SbVec3f &v0, const SbVec3f &v1, SbVec3f &intersection) const
Line:
void setRadius(float radiusInPixels)
Set the radius (in pixels) around the point.
bool intersect(const SbVec3f &point) const
Point:
void setObjectSpace(const SbMatrix &matrix)