Open Inventor Release 2024.1.1
 
Loading...
Searching...
No Matches
SoPickedPoint.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_PICKED_POINT_
51#define _SO_PICKED_POINT_
52
53#include <Inventor/SbBasic.h>
54#include <Inventor/SbLinear.h>
55#include <Inventor/SbViewportRegion.h>
56#include <Inventor/SoLists.h>
57
58class SoDetail;
60class SoPath;
61class SoState;
62class SoGetMatrixActionWrapper;
63class SoRayPickAction;
64class SoAction;
65class SoTextureCoordinateBundle;
66
68//
69// Class: SoPickedPoint
70//
71// An SoPickedPoint represents a point on the surface of an object
72// that was picked by applying an SoRayPickAction to a scene. It
73// contains the point of intersection, the surface normal and texture
74// coordinates at that point, and other items.
75//
77
104
105 public:
110
115
120
121 // Returns an instance that is a copy of this instance. The caller
122 // is responsible for deleting the copy when done.
124
128 const SbVec3f & getPoint() const { return worldPoint; }
136 const SbVec3f & getNormal() const { return worldNormal; }
145 const SbVec4f & getTextureCoords() const { return imageTexCoords; }
146
152 int getMaterialIndex() const { return materialIndex; }
153
157 inline SoPath * getPath() const { return path; }
158
164 SbBool isOnGeometry() const { return onGeometry; }
165
167 //
168 // The following methods all take a pointer to a node in the
169 // returned path. If the node pointer is NULL (the default), the
170 // information corresponding to the tail of the path is returned.
171 //
172
180 const SoDetail * getDetail(const SoNode *node = NULL) const;
181
191 SbMatrix getObjectToWorld(const SoNode *node = NULL) const;
192
202 SbMatrix getWorldToObject(const SoNode *node = NULL) const;
203
213 SbMatrix getObjectToImage(const SoNode *node = NULL) const;
214
224 SbMatrix getImageToObject(const SoNode *node = NULL) const;
225
235 SbVec3f getObjectPoint(const SoNode *node = NULL) const;
236
246 SbVec3f getObjectNormal(const SoNode *node = NULL) const;
247
257 SbVec4f getObjectTextureCoords(const SoNode *node=NULL) const;
258
259 //
261
262 private:
263
264 // NOTE: these methods should be called ONLY by the node that
265 // causes the SoPickedPoint instance to be created, and ONLY at
266 // the time it is created. Setting or changing the normal or
267 // texture coordinates at a later time may cause undefined results.
268
269 // Sets the normal in object space
270 void setObjectNormal(const SbVec3f &normal);
271
272 // Sets the texture coordinates in object space
273 void setObjectTextureCoords(const SbVec4f &texCoords);
274
275 // Sets the material index
276 void setMaterialIndex(int index) { materialIndex = index; }
277
278 // Sets the detail corresponding to the given node in the path.
279 // NULL may be passed to remove a detail. All detail pointers are
280 // NULL by default.
281 void setDetail(SoDetail *detail, SoNode *node);
282
283 private:
284
285 // The constructor is internal since instances are created only by
286 // the SoRayPickAction
287 SoPickedPoint(const SoPath *path, SoState *state,
288 const SbVec3f &objSpacePoint);
289
290 // override the current path this is useful for alternate representations
291 void overridePath(const SoPath* _path);
292
293 // set TextureCoords during picking
294 void setObjectTextureCoords( const SoRayPickAction *action, const SoTextureCoordinateBundle &tcb );
295
303 const SbVec3d& getPointD() const { return worldPointD; }
304
305 private:
306 SoGetMatrixAction *getGetMatrixAction() const;
307 // This action is used to get the world-to-object matrix
308 SoGetMatrixActionWrapper *m_matrixActionWrapper;
309
310 // Intersection point and normal in world space, and texture
311 // coordinates in image space
312 SbVec3f worldPoint;
313 SbVec3d worldPointD;
314 SbVec3f worldNormal;
315 SbVec4f imageTexCoords;
316
317 // ViewportRegion, which is needed when figuring out matrices
318 SbViewportRegion vpRegion;
319
320 // Material index
321 int materialIndex;
322
323 // TRUE if pick was on geometry of shape as opposed to bbox
324 SbBool onGeometry;
325
326 // The path to the shape that was picked
327 SoPath *path;
328
329 // Details corresponding to nodes in path, one per node in path.
330 // Many may be NULL.
331 SoDetailList details;
332
333 // The pointer to the state allows us to access matrices to
334 // convert from object space to world and image space. This
335 // pointer is valid only during construction and setting of the
336 // info inside the instance.
337 SoState *state;
338
339 // Returns index in path of given node, or -1 if not found
340 int getNodeIndex(const SoNode *node) const;
341
342 // Applies SoGetMatrixAction to path to node
343 void getMatrix(const SoNode *node) const;
344
345 // Multiplies SbVec4f by matrix - for transforming texture coords
346 static SbVec4f multVecMatrix4(const SbMatrix &m, const SbVec4f v);
347
348 // void operator=( const SoPickedPoint & );
349
350 // evaluates the object space (norm, point) when action is known
351 static void getObjectGeomlUsingModelMatrixElement( const SoAction* action, const SbVec3f &inVec, SbVec3f &outVec, bool normalize = true );
352
353 // optimized methods for picking
354 SbVec3f getObjectNormal( const SoAction *action ) const;
355
356 SbVec3f getObjectPoint( const SoAction *action ) const;
357
358};
359
360#endif /* _SO_PICKED_POINT_ */
361
4x4 matrix class.
Definition SbMatrix.h:309
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D vector class ...
Definition SbVec.h:1214
3D vector class.
Definition SbVec.h:932
4D vector class.
Definition SbVec.h:2214
Class for representing a viewport.
Abstract base class for all actions.
Definition SoAction.h:132
Base class for describing detail information about a shape node.
Definition SoDetail.h:99
Maintains a list of instances of details.
Computes transformation matrix for a subgraph.
Abstract base class for all database nodes.
Definition SoNode.h:145
Path that points to a list of hierarchical nodes.
Definition SoPath.h:187
Represents point on surface of picked object.
SbMatrix getImageToObject(const SoNode *node=NULL) const
Returns the texture transformation matrix between image space and the object space corresponding to t...
SoPickedPoint()
Default constructor.
const SbVec3f & getPoint() const
Returns the intersection point in world space.
const SbVec4f & getTextureCoords() const
Returns the texture coordinates in image space.
const SbVec3f & getNormal() const
Returns the surface normal in world space.
SbMatrix getObjectToWorld(const SoNode *node=NULL) const
Returns the transformation matrix between the object space and world space corresponding to the given...
SbMatrix getObjectToImage(const SoNode *node=NULL) const
Returns the texture transformation matrix between the object space and image space corresponding to t...
const SoDetail * getDetail(const SoNode *node=NULL) const
Returns the detail that corresponds to the specified node in the path returned by getPath().
SbVec4f getObjectTextureCoords(const SoNode *node=NULL) const
Returns the texture coordinates in the object space corresponding to the given node in the path.
SbVec3f getObjectNormal(const SoNode *node=NULL) const
Returns the surface normal in the object space corresponding to the given node in the path.
~SoPickedPoint()
Destructor.
int getMaterialIndex() const
Returns the index into the current set of materials of the material active at the intersection point.
SbVec3f getObjectPoint(const SoNode *node=NULL) const
Returns the intersection point in the object space corresponding to the given node in the path.
SbBool isOnGeometry() const
Returns whether the intersection is actually on the geometry of the character that was hit,...
SbMatrix getWorldToObject(const SoNode *node=NULL) const
Returns the transformation matrix between world space and the object space corresponding to the given...
SoPickedPoint * copy() const
SoPath * getPath() const
Returns the path to the object that was intersected.
SoPickedPoint(const SoPickedPoint &pp)
Copy constructor.
Intersects objects with a ray cast into scene.
Traversal state.
Definition SoState.h:74
int SbBool
Boolean type.
Definition SbBase.h:87