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_INDEXED_SHAPE_ 00051 #define _SO_INDEXED_SHAPE_ 00052 00053 #include <Inventor/fields/SoMFInt32.h> 00054 #include <Inventor/nodes/SoVertexShape.h> 00055 00057 // 00058 // Class: SoIndexedShape 00059 // 00060 // Abstract indexed shape node class. All nodes derived from this 00061 // (such as SoIndexedFaceSet and SoIndexedLineSet) are shapes 00062 // that are constructed from vertices defined by indexing into the 00063 // current coordinates. The coordinate indices are stored in the 00064 // coordIndex field, which is used by all subclasses. 00065 // 00066 // One rule is used: all coordinate indices less than 0 may be used 00067 // for special purposes, such as to denote the end of a face or 00068 // polyline. This means that all indices < 0 can be ignored safely 00069 // when looking at vertices. 00070 // 00071 // Depending on the current material, normal, and texture coordinate 00072 // binding values, materials, normals, and texture coordinates may be 00073 // accessed in order or may be indexed using the materialIndex, 00074 // normalIndex, and textureCoordIndex fields. 00075 // 00077 class SoFieldSensor ; 00078 class SbVec2d; 00079 00157 class SoIndexedShape : public SoVertexShape { 00158 00159 SO_NODE_ABSTRACT_HEADER(SoIndexedShape); 00160 00161 public: 00168 SoMFInt32 coordIndex; 00175 SoMFInt32 materialIndex; 00182 SoMFInt32 normalIndex; 00189 SoMFInt32 textureCoordIndex; 00190 00191 private: 00200 virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er); 00201 00210 virtual void computeBBox(SoAction *action, SbXfBox3d &box, SbVec3d ¢er); 00211 00215 virtual void rayPick(SoRayPickAction *action); 00216 00217 private: 00218 static void initClass(); 00219 static void exitClass(); 00220 00221 private: 00223 SoIndexedShape(); 00224 00226 virtual ~SoIndexedShape(); 00227 00228 SoINTERNAL private: 00229 // max auto caching test 00230 virtual int getMaxTestValueForAutoCache() 00231 {return coordIndex.getNum();} 00232 00233 // auto caching test 00234 virtual int getMinTestValueForAutoCache() 00235 {return coordIndex.getNum();} 00236 00237 // Returns TRUE if texture coordinates should be indexed 00238 static SbBool areTexCoordsIndexed(SoAction *action); 00239 00240 // Starting at a given index in the coordIndex array, figure out 00241 // how many vertices there are before either the end of the array 00242 // or the next 'border' index 00243 int getNumVerts(int startCoord); 00244 00245 // Setup for fast rendering. This should be called by subclasses, 00246 // which can then use the textureI/colorI/normalI arrays (which 00247 // will either point to one of the coordIndex arrays, or to a 00248 // consective array of integers. This must be called AFTER the 00249 // vpCache has been filled in. 00250 void setupIndices(int numParts, int numFaces, 00251 SbBool needNormals, SbBool needTexCoords, 00252 SbBool needTexCoords3); 00253 00254 // These must not be called unless setupIndices has been called first: 00255 const int32_t * getNormalIndices() const 00256 { return (normalI ? normalI : getConsecutiveIndices()); } 00257 const int32_t * getColorIndices() const 00258 { return (colorI ? colorI : getConsecutiveIndices()); } 00259 const int32_t * getTexCoordIndices() const 00260 { return (texCoordI ? texCoordI : getConsecutiveIndices()); } 00261 00262 // return the greatest indice used. 00263 virtual int32_t getMaxVertexUsed() const; 00264 00265 // return the number of vertex to use 00266 virtual int32_t getNumVertexUsed() const; 00267 00268 // return memory gain factor for indexing 00269 virtual float getIndexingGainFactor() const; 00270 00271 // Keep indices up to date if things change 00272 virtual void notify(SoNotList *list); 00273 00274 // helper function used internally to build connectivity of an indexed shape 00275 static inline void updateConnectivity(const int curVert, const int _index, int32_t *connectIndex, int32_t *connectivity); 00276 00277 #ifndef HIDDEN_FROM_DOC 00278 00279 template< int MODE> 00280 void computeCoordBBox_(SoAction *action, SbBox3f &box, SbVec3f ¢er, const SbVec2d &pointSizes ); 00281 #endif // HIDDEN_FROM_DOC 00282 00283 void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er, const SbVec2d &pointSizes ); 00284 00285 private: 00286 00287 // Internal routines used to allocate sequential indices so the 00288 // same rendering loops can be used for indexed or non-indexed 00289 // cases: 00290 int32_t* allocateSequentialWithHoles(); 00291 00292 static bool s_evaluateIndexingGainFactor; 00293 // eval the indexing gain factor 00294 void evalIndexingGainFactor() const; 00295 00296 // These are filled in by the setupIndices routine: 00297 const int32_t *texCoordI; 00298 const int32_t *colorI; 00299 const int32_t *normalI; 00300 00301 unsigned char materialBinding; 00302 unsigned char normalBinding; 00303 unsigned char texCoordBinding; 00304 00305 mutable int32_t m_maxVertexUsed; 00306 mutable int32_t m_numVertexUsed; 00307 mutable float m_indexingGainFactor; 00308 00309 bool bAlloc_texCoordI; // == true if texCoordI was allocated 00310 bool bAlloc_colorI; // == true if colorI was allocated 00311 bool bAlloc_normalI; // == true if normalI was allocated 00312 }; 00313 00314 // inline functions declaration 00315 void 00316 SoIndexedShape::updateConnectivity(const int curVert, const int _index, int32_t *connectIndex, int32_t *connectivity) 00317 { 00318 if ( _index >=0 ) 00319 { 00320 int32_t lastConnect = connectIndex[_index]; 00321 if ( lastConnect==-1 ) 00322 { 00323 connectivity[curVert]= curVert; 00324 } 00325 else 00326 { 00327 connectivity[curVert] = connectivity[lastConnect]; 00328 connectivity[lastConnect] = curVert; 00329 } 00330 connectIndex[_index] = curVert; 00331 } 00332 } 00333 00334 #endif /* _SO_INDEXED_SHAPE_ */ 00335 00336