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-2014 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 00103 class SoPickedPoint { 00104 00105 public: 00109 SoPickedPoint(); 00110 00114 SoPickedPoint(const SoPickedPoint &pp); 00115 00119 ~SoPickedPoint(); 00120 00121 // Returns an instance that is a copy of this instance. The caller 00122 // is responsible for deleting the copy when done. 00123 SoPickedPoint * copy() const; 00124 00128 const SbVec3f & getPoint() const { return worldPoint; } 00136 const SbVec3f & getNormal() const { return worldNormal; } 00145 const SbVec4f & getTextureCoords() const { return imageTexCoords; } 00146 00152 int getMaterialIndex() const { return materialIndex; } 00153 00157 inline SoPath * getPath() const { return path; } 00158 00164 SbBool isOnGeometry() const { return onGeometry; } 00165 00167 // 00168 // The following methods all take a pointer to a node in the 00169 // returned path. If the node pointer is NULL (the default), the 00170 // information corresponding to the tail of the path is returned. 00171 // 00172 00180 const SoDetail * getDetail(const SoNode *node = NULL) const; 00181 00191 SbMatrix getObjectToWorld(const SoNode *node = NULL) const; 00192 00202 SbMatrix getWorldToObject(const SoNode *node = NULL) const; 00203 00213 SbMatrix getObjectToImage(const SoNode *node = NULL) const; 00214 00224 SbMatrix getImageToObject(const SoNode *node = NULL) const; 00225 00235 SbVec3f getObjectPoint(const SoNode *node = NULL) const; 00236 00246 SbVec3f getObjectNormal(const SoNode *node = NULL) const; 00247 00257 SbVec4f getObjectTextureCoords(const SoNode *node=NULL) const; 00258 00259 // 00261 00262 private: 00263 00264 // NOTE: these methods should be called ONLY by the node that 00265 // causes the SoPickedPoint instance to be created, and ONLY at 00266 // the time it is created. Setting or changing the normal or 00267 // texture coordinates at a later time may cause undefined results. 00268 00269 // Sets the normal in object space 00270 void setObjectNormal(const SbVec3f &normal); 00271 00272 // Sets the texture coordinates in object space 00273 void setObjectTextureCoords(const SbVec4f &texCoords); 00274 00275 // Sets the material index 00276 void setMaterialIndex(int index) { materialIndex = index; } 00277 00278 // Sets the detail corresponding to the given node in the path. 00279 // NULL may be passed to remove a detail. All detail pointers are 00280 // NULL by default. 00281 void setDetail(SoDetail *detail, SoNode *node); 00282 00283 private: 00284 00285 // The constructor is internal since instances are created only by 00286 // the SoRayPickAction 00287 SoPickedPoint(const SoPath *path, SoState *state, 00288 const SbVec3f &objSpacePoint); 00289 00290 // override the current path this is useful for alternate representations 00291 void overridePath(const SoPath* _path); 00292 00293 // set TextureCoords during picking 00294 void setObjectTextureCoords( const SoRayPickAction *action, const SoTextureCoordinateBundle &tcb ); 00295 00296 private: 00297 SoGetMatrixAction *getGetMatrixAction() const; 00298 // This action is used to get the world-to-object matrix 00299 SoGetMatrixActionWrapper *m_matrixActionWrapper; 00300 00301 // Intersection point and normal in world space, and texture 00302 // coordinates in image space 00303 SbVec3f worldPoint; 00304 SbVec3f worldNormal; 00305 SbVec4f imageTexCoords; 00306 00307 // ViewportRegion, which is needed when figuring out matrices 00308 SbViewportRegion vpRegion; 00309 00310 // Material index 00311 int materialIndex; 00312 00313 // TRUE if pick was on geometry of shape as opposed to bbox 00314 SbBool onGeometry; 00315 00316 // The path to the shape that was picked 00317 SoPath *path; 00318 00319 // Details corresponding to nodes in path, one per node in path. 00320 // Many may be NULL. 00321 SoDetailList details; 00322 00323 // The pointer to the state allows us to access matrices to 00324 // convert from object space to world and image space. This 00325 // pointer is valid only during construction and setting of the 00326 // info inside the instance. 00327 SoState *state; 00328 00329 // Returns index in path of given node, or -1 if not found 00330 int getNodeIndex(const SoNode *node) const; 00331 00332 // Applies SoGetMatrixAction to path to node 00333 void getMatrix(const SoNode *node) const; 00334 00335 // Multiplies SbVec4f by matrix - for transforming texture coords 00336 static SbVec4f multVecMatrix4(const SbMatrix &m, const SbVec4f v); 00337 00338 // void operator=( const SoPickedPoint & ); 00339 00340 // evaluates the object space (norm, point) when action is known 00341 static void getObjectGeomlUsingModelMatrixElement( const SoAction* action, const SbVec3f &inVec, SbVec3f &outVec, bool normalize = true ); 00342 00343 // optimized methods for picking 00344 SbVec3f getObjectNormal( const SoAction *action ) const; 00345 00346 SbVec3f getObjectPoint( const SoAction *action ) const; 00347 00348 }; 00349 00350 #endif /* _SO_PICKED_POINT_ */ 00351 00352