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_QUAD_MESH_ 00051 #define _SO_QUAD_MESH_ 00052 00053 #include <Inventor/fields/SoSFInt32.h> 00054 #include <Inventor/nodes/SoNonIndexedShape.h> 00055 00057 // 00058 // Class: SoQuadMesh 00059 // 00060 // Shape node with implicit quadrilateral connectivity. The number of 00061 // vertices in each row and column of the quadMesh is given by the 00062 // verticesPerRow and verticesPerColumn fields. The current 00063 // coordinates are taken in order (starting at startIndex) to form 00064 // the rows of the quadMesh; i.e., the first verticesPerColumn vertices 00065 // form the first row of the quadMesh, the next verticesPerColumn 00066 // vertices form the next row, and so on. It is an error if there are 00067 // not enough coordinates. If materials or normals are bound to 00068 // vertices, they will begin at startIndex, as well; otherwise, they 00069 // will start at index 0. 00070 // 00072 00156 class SoQuadMesh : public SoNonIndexedShape { 00157 00158 SO_NODE_HEADER(SoQuadMesh); 00159 00160 public: 00161 // Fields 00165 SoSFInt32 verticesPerColumn; 00169 SoSFInt32 verticesPerRow; 00170 00174 SoQuadMesh(); 00175 00176 private: 00178 virtual void GLRender(SoGLRenderAction *action); 00179 00180 // Generates default normals using the given normal bundle. 00181 // Returns TRUE. 00182 virtual void generateDefaultNormals(SoState *state, 00183 const SbVec3f *coords, 00184 int numCoords, 00185 SoNormalBundle *nb, 00186 SbBool storeRef = FALSE); 00187 00189 virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action); 00190 00191 private: 00192 int getNumRows(void) const; // returns the number of Rows 00193 int getNumCols(void) const; // returns the number of Columns 00194 int getNumQuads(void) const; // returns the number of Quads 00195 int getNumMeshVerts(void) const; // returns the number of vertices of the Quad Mesh 00196 00197 // returns the number of PART 00198 inline int getNumParts(void) const { return getNumRows(); }// PARTS are ROWS 00199 00200 // returns the number of FACES 00201 inline int getNumFaces(void) const { return getNumQuads(); } // FACES are Quads 00202 00203 // returns the number of vertices needed 00204 int getNumVerticesNeeded(void) const; 00205 00206 // Checks if enough vertices, normals, textureCoord, colors...etc... 00207 bool check_RenderVectors( SoState *state, bool bUseTexCoordsAnyway ); 00208 00209 // Generic version of Generate default normals 00210 void generateDefaultNormals_QuadMesh(SoState *state, const SbVec3f *vecPQuadCoord[], SbVec3f normals[] ); 00211 00212 virtual void callDEBUGGLRender(SoGLRenderAction *action,uint32_t useTexCoordsAnyway); 00213 00214 //Typedef of pointer to method on QuadMesh; 00215 //This will be used to simplify declaration and initialization. 00216 typedef void (SoQuadMesh::*PMQM)(SoGLRenderAction *); 00217 00218 // Compute transformations from Modelling coordinate to tangent space (facet space). 00219 virtual SbMatrix3* computeVtxTangentSpaceMat(const float *bumpTexCoords, int &numMat) const ; 00220 00221 static void initClass(); 00222 static void exitClass(); 00223 00224 private: 00225 00226 // This enum is used to indicate the current material or normal binding 00227 enum Binding { 00228 OVERALL, PER_ROW, PER_QUAD, PER_VERTEX 00229 }; 00230 // Generates triangles representing rows 00231 virtual void generatePrimitives(SoAction *action); 00232 00233 //Approx number of primitives 00234 virtual void countPrim(){ 00235 totalNumVertices = verticesPerColumn.getValue() * verticesPerRow.getValue(); 00236 } 00237 00238 //return number of primitives 00239 virtual int getNumPrim(){return totalNumVertices;} 00240 00241 // return num vertices 00242 virtual int getNumVert() 00243 { return (int)(verticesPerColumn.getValue() * verticesPerRow.getValue()); } 00244 00245 //max auto caching test 00246 virtual int getMaxTestValueForAutoCache(){return totalNumVertices;} 00247 00248 //min auto caching test 00249 virtual int getMinTestValueForAutoCache(){return verticesPerColumn.getValue();} 00250 00251 // invalid test 00252 virtual SbBool numPrimInvalid(){return totalNumVertices < 0 ;} 00253 00254 // render function 00255 void doRendering(SoGLRenderAction *action, const SoShapeStyleElement* shapeStyle); 00256 00257 // Overrides standard method to create an SoFaceDetail instance 00258 virtual SoDetail *createTriangleDetail(SoRayPickAction *action, 00259 const SoPrimitiveVertex *v1, 00260 const SoPrimitiveVertex *v2, 00261 const SoPrimitiveVertex *v3, 00262 SoPickedPoint *pp); 00263 00264 virtual ~SoQuadMesh(); 00265 00266 private: 00267 00268 // Returns current material or normal binding from action's state 00269 static Binding getMaterialBinding(SoAction *action); 00270 Binding getNormalBinding(SoAction *action, SoNormalBundle *nb); 00271 00272 // Saves normal binding when generating primitives for picking 00273 Binding savedNormalBinding; 00274 00275 // Returns index (of material or normal) based on given binding 00276 static int getBindIndex(Binding binding, int vert, 00277 int row, int quad); 00278 00279 virtual int getNumNeeedNormals(){return (verticesPerColumn.getValue() * verticesPerRow.getValue());} 00280 00281 // Blow vpCache when vertexProperty field changes: 00282 virtual void notify(SoNotList *list); 00283 00284 // This stores the total number of vertices; we use this 00285 // information to influence Separator's auto-caching algorithm 00286 // (shapes with very few triangles should be cached because 00287 // traversing them can be expensive, shapes with lots of triangles 00288 // shouldn't be cached because they'll take up too much memory). 00289 int totalNumVertices; 00290 }; 00291 00292 #endif /* _SO_QUAD_MESH_ */ 00293 00294