00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul S. Strauss (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_PICKED_POINT_ 00051 #define _SO_PICKED_POINT_ 00052 00053 #include <Inventor/SbBasic.h> 00054 #include <Inventor/SbLinear.h> 00055 #include <Inventor/SbViewportRegion.h> 00056 #include <Inventor/SoLists.h> 00057 00058 class SoDetail; 00059 class SoGetMatrixAction; 00060 class SoPath; 00061 class SoState; 00062 class SoGetMatrixActionWrapper; 00063 class SoRayPickAction; 00064 class SoAction; 00065 class SoTextureCoordinateBundle; 00066 00068 // 00069 // Class: SoPickedPoint 00070 // 00071 // An SoPickedPoint represents a point on the surface of an object 00072 // that was picked by applying an SoRayPickAction to a scene. It 00073 // contains the point of intersection, the surface normal and texture 00074 // coordinates at that point, and other items. 00075 // 00077 00104 class SoPickedPoint { 00105 00106 public: 00110 SoPickedPoint(); 00111 00115 SoPickedPoint(const SoPickedPoint &pp); 00116 00120 ~SoPickedPoint(); 00121 00122 // Returns an instance that is a copy of this instance. The caller 00123 // is responsible for deleting the copy when done. 00124 SoPickedPoint * copy() const; 00125 00129 const SbVec3f & getPoint() const { return worldPoint; } 00137 const SbVec3f & getNormal() const { return worldNormal; } 00146 const SbVec4f & getTextureCoords() const { return imageTexCoords; } 00147 00153 int getMaterialIndex() const { return materialIndex; } 00154 00158 inline SoPath * getPath() const { return path; } 00159 00165 SbBool isOnGeometry() const { return onGeometry; } 00166 00168 // 00169 // The following methods all take a pointer to a node in the 00170 // returned path. If the node pointer is NULL (the default), the 00171 // information corresponding to the tail of the path is returned. 00172 // 00173 00181 const SoDetail * getDetail(const SoNode *node = NULL) const; 00182 00192 SbMatrix getObjectToWorld(const SoNode *node = NULL) const; 00193 00203 SbMatrix getWorldToObject(const SoNode *node = NULL) const; 00204 00214 SbMatrix getObjectToImage(const SoNode *node = NULL) const; 00215 00225 SbMatrix getImageToObject(const SoNode *node = NULL) const; 00226 00236 SbVec3f getObjectPoint(const SoNode *node = NULL) const; 00237 00247 SbVec3f getObjectNormal(const SoNode *node = NULL) const; 00248 00258 SbVec4f getObjectTextureCoords(const SoNode *node=NULL) const; 00259 00260 // 00262 00263 private: 00264 00265 // NOTE: these methods should be called ONLY by the node that 00266 // causes the SoPickedPoint instance to be created, and ONLY at 00267 // the time it is created. Setting or changing the normal or 00268 // texture coordinates at a later time may cause undefined results. 00269 00270 // Sets the normal in object space 00271 void setObjectNormal(const SbVec3f &normal); 00272 00273 // Sets the texture coordinates in object space 00274 void setObjectTextureCoords(const SbVec4f &texCoords); 00275 00276 // Sets the material index 00277 void setMaterialIndex(int index) { materialIndex = index; } 00278 00279 // Sets the detail corresponding to the given node in the path. 00280 // NULL may be passed to remove a detail. All detail pointers are 00281 // NULL by default. 00282 void setDetail(SoDetail *detail, SoNode *node); 00283 00284 private: 00285 00286 // The constructor is internal since instances are created only by 00287 // the SoRayPickAction 00288 SoPickedPoint(const SoPath *path, SoState *state, 00289 const SbVec3f &objSpacePoint); 00290 00291 // override the current path this is useful for alternate representations 00292 void overridePath(const SoPath* _path); 00293 00294 // set TextureCoords during picking 00295 void setObjectTextureCoords( const SoRayPickAction *action, const SoTextureCoordinateBundle &tcb ); 00296 00297 private: 00298 SoGetMatrixAction *getGetMatrixAction() const; 00299 // This action is used to get the world-to-object matrix 00300 SoGetMatrixActionWrapper *m_matrixActionWrapper; 00301 00302 // Intersection point and normal in world space, and texture 00303 // coordinates in image space 00304 SbVec3f worldPoint; 00305 SbVec3f worldNormal; 00306 SbVec4f imageTexCoords; 00307 00308 // ViewportRegion, which is needed when figuring out matrices 00309 SbViewportRegion vpRegion; 00310 00311 // Material index 00312 int materialIndex; 00313 00314 // TRUE if pick was on geometry of shape as opposed to bbox 00315 SbBool onGeometry; 00316 00317 // The path to the shape that was picked 00318 SoPath *path; 00319 00320 // Details corresponding to nodes in path, one per node in path. 00321 // Many may be NULL. 00322 SoDetailList details; 00323 00324 // The pointer to the state allows us to access matrices to 00325 // convert from object space to world and image space. This 00326 // pointer is valid only during construction and setting of the 00327 // info inside the instance. 00328 SoState *state; 00329 00330 // Returns index in path of given node, or -1 if not found 00331 int getNodeIndex(const SoNode *node) const; 00332 00333 // Applies SoGetMatrixAction to path to node 00334 void getMatrix(const SoNode *node) const; 00335 00336 // Multiplies SbVec4f by matrix - for transforming texture coords 00337 static SbVec4f multVecMatrix4(const SbMatrix &m, const SbVec4f v); 00338 00339 void operator=( const SoPickedPoint & ); 00340 00341 // evaluates the object space (norm, point) when action is known 00342 static void getObjectGeomlUsingModelMatrixElement( const SoAction* action, const SbVec3f &inVec, SbVec3f &outVec, bool normalize = true ); 00343 00344 // optimized methods for picking 00345 SbVec3f getObjectNormal( const SoAction *action ) const; 00346 00347 SbVec3f getObjectPoint( const SoAction *action ) const; 00348 00349 }; 00350 00351 #endif /* _SO_PICKED_POINT_ */ 00352 00353