Geant4 Cross Reference |
1 // see license file for original license. 1 // see license file for original license. 2 2 3 #ifndef tools_glutess__tess 3 #ifndef tools_glutess__tess 4 #define tools_glutess__tess 4 #define tools_glutess__tess 5 5 6 #include "mesh" 6 #include "mesh" 7 #include "dict" 7 #include "dict" 8 #include "priorityq" 8 #include "priorityq" 9 9 10 #include <csetjmp> 10 #include <csetjmp> 11 11 12 /* The begin/end calls must be properly nested 12 /* The begin/end calls must be properly nested. We keep track of 13 * the current state to enforce the ordering. 13 * the current state to enforce the ordering. 14 */ 14 */ 15 enum TessState { T_DORMANT, T_IN_POLYGON, T_IN 15 enum TessState { T_DORMANT, T_IN_POLYGON, T_IN_CONTOUR }; 16 16 17 /* We cache vertex data for single-contour pol 17 /* We cache vertex data for single-contour polygons so that we can 18 * try a quick-and-dirty decomposition first. 18 * try a quick-and-dirty decomposition first. 19 */ 19 */ 20 #define GLU_TESS_MAX_CACHE 100 20 #define GLU_TESS_MAX_CACHE 100 21 21 22 typedef struct CachedVertex { 22 typedef struct CachedVertex { 23 GLUdouble coords[3]; 23 GLUdouble coords[3]; 24 void *data; 24 void *data; 25 } CachedVertex; 25 } CachedVertex; 26 26 27 struct GLUtesselator { 27 struct GLUtesselator { 28 28 29 /*** state needed for collecting the input d 29 /*** state needed for collecting the input data ***/ 30 30 31 enum TessState state; /* what begin/end ca 31 enum TessState state; /* what begin/end calls have we seen? */ 32 32 33 GLUhalfEdge *lastEdge; /* lastEdge->Org is 33 GLUhalfEdge *lastEdge; /* lastEdge->Org is the most recent vertex */ 34 GLUmesh *mesh; /* stores the input contou 34 GLUmesh *mesh; /* stores the input contours, and eventually 35 the tessell 35 the tessellation itself */ 36 36 37 void (GLUAPIENTRY *callError)( GLUenum er 37 void (GLUAPIENTRY *callError)( GLUenum errnum ); 38 38 39 /*** state needed for projecting onto the sw 39 /*** state needed for projecting onto the sweep plane ***/ 40 40 41 GLUdouble normal[3]; /* user-specified norm 41 GLUdouble normal[3]; /* user-specified normal (if provided) */ 42 GLUdouble sUnit[3]; /* unit vector in s-dire 42 GLUdouble sUnit[3]; /* unit vector in s-direction (debugging) */ 43 GLUdouble tUnit[3]; /* unit vector in t-dire 43 GLUdouble tUnit[3]; /* unit vector in t-direction (debugging) */ 44 44 45 /*** state needed for the line sweep ***/ 45 /*** state needed for the line sweep ***/ 46 46 47 GLUdouble relTolerance; /* tolerance for mer 47 GLUdouble relTolerance; /* tolerance for merging features */ 48 GLUenum windingRule; /* rule for determinin 48 GLUenum windingRule; /* rule for determining polygon interior */ 49 GLUboolean fatalError; /* fatal error: need 49 GLUboolean fatalError; /* fatal error: needed combine callback */ 50 50 51 Dict *dict; /* edge dictionary for swe 51 Dict *dict; /* edge dictionary for sweep line */ 52 PriorityQ *pq; /* priority queue of verte 52 PriorityQ *pq; /* priority queue of vertex events */ 53 GLUvertex *event; /* current sweep event b 53 GLUvertex *event; /* current sweep event being processed */ 54 54 55 void (GLUAPIENTRY *callCombine)( GLUdoubl 55 void (GLUAPIENTRY *callCombine)( GLUdouble coords[3], void *data[4], 56 GLUfloat weight[4], void **outDa 56 GLUfloat weight[4], void **outData ); 57 57 58 /*** state needed for rendering callbacks (s 58 /*** state needed for rendering callbacks (see render.c) ***/ 59 59 60 GLUboolean flagBoundary; /* mark boundary e 60 GLUboolean flagBoundary; /* mark boundary edges (use EdgeFlag) */ 61 GLUboolean boundaryOnly; /* Extract contour 61 GLUboolean boundaryOnly; /* Extract contours, not triangles */ 62 GLUface *lonelyTriList; 62 GLUface *lonelyTriList; 63 /* list of triangles which could not be re 63 /* list of triangles which could not be rendered as strips or fans */ 64 64 65 void (GLUAPIENTRY *callBegin)( GLUenum ty 65 void (GLUAPIENTRY *callBegin)( GLUenum type ); 66 void (GLUAPIENTRY *callEdgeFlag)( GLUbool 66 void (GLUAPIENTRY *callEdgeFlag)( GLUboolean boundaryEdge ); 67 void (GLUAPIENTRY *callVertex)( void *dat 67 void (GLUAPIENTRY *callVertex)( void *data ); 68 void (GLUAPIENTRY *callEnd)( void ); 68 void (GLUAPIENTRY *callEnd)( void ); 69 void (GLUAPIENTRY *callMesh)( GLUmesh *me 69 void (GLUAPIENTRY *callMesh)( GLUmesh *mesh ); 70 70 71 71 72 /*** state needed to cache single-contour po 72 /*** state needed to cache single-contour polygons for renderCache() */ 73 73 74 GLUboolean emptyCache; /* empty cache on 74 GLUboolean emptyCache; /* empty cache on next vertex() call */ 75 int cacheCount; /* number of cached vert 75 int cacheCount; /* number of cached vertices */ 76 CachedVertex cache[GLU_TESS_MAX_CACHE]; /* 76 CachedVertex cache[GLU_TESS_MAX_CACHE]; /* the vertex data */ 77 77 78 /*** rendering callbacks that also pass poly 78 /*** rendering callbacks that also pass polygon data ***/ 79 void (GLUAPIENTRY *callBeginData)( GLUenu 79 void (GLUAPIENTRY *callBeginData)( GLUenum type, void *polygonData ); 80 void (GLUAPIENTRY *callEdgeFlagData)( GLU 80 void (GLUAPIENTRY *callEdgeFlagData)( GLUboolean boundaryEdge, 81 void *polygonData ); 81 void *polygonData ); 82 void (GLUAPIENTRY *callVertexData)( void 82 void (GLUAPIENTRY *callVertexData)( void *data, void *polygonData ); 83 void (GLUAPIENTRY *callEndData)( void *po 83 void (GLUAPIENTRY *callEndData)( void *polygonData ); 84 void (GLUAPIENTRY *callErrorData)( GLUenu 84 void (GLUAPIENTRY *callErrorData)( GLUenum errnum, void *polygonData ); 85 void (GLUAPIENTRY *callCombineData)( GLUd 85 void (GLUAPIENTRY *callCombineData)( GLUdouble coords[3], void *data[4], 86 GLUfloat weight[4], void **outData 86 GLUfloat weight[4], void **outData, 87 void *polygonData ); 87 void *polygonData ); 88 88 89 jmp_buf env; /* place to jump to when m 89 jmp_buf env; /* place to jump to when memAllocs fail */ 90 90 91 void *polygonData; /* client data for cur 91 void *polygonData; /* client data for current polygon */ 92 }; 92 }; 93 93 94 void GLUAPIENTRY __gl_noBeginData( GLUenum typ 94 void GLUAPIENTRY __gl_noBeginData( GLUenum type, void *polygonData ); 95 void GLUAPIENTRY __gl_noEdgeFlagData( GLUboole 95 void GLUAPIENTRY __gl_noEdgeFlagData( GLUboolean boundaryEdge, void *polygonData ); 96 void GLUAPIENTRY __gl_noVertexData( void *data 96 void GLUAPIENTRY __gl_noVertexData( void *data, void *polygonData ); 97 void GLUAPIENTRY __gl_noEndData( void *polygon 97 void GLUAPIENTRY __gl_noEndData( void *polygonData ); 98 void GLUAPIENTRY __gl_noErrorData( GLUenum err 98 void GLUAPIENTRY __gl_noErrorData( GLUenum errnum, void *polygonData ); 99 void GLUAPIENTRY __gl_noCombineData( GLUdouble 99 void GLUAPIENTRY __gl_noCombineData( GLUdouble coords[3], void *data[4], 100 GLUfloat weight[4], void **outData, 100 GLUfloat weight[4], void **outData, 101 void *polygonData ); 101 void *polygonData ); 102 102 103 #define CALL_BEGIN_OR_BEGIN_DATA(a) \ 103 #define CALL_BEGIN_OR_BEGIN_DATA(a) \ 104 if (tess->callBeginData != &__gl_noBeginDat 104 if (tess->callBeginData != &__gl_noBeginData) \ 105 (*tess->callBeginData)((a),tess->polygon 105 (*tess->callBeginData)((a),tess->polygonData); \ 106 else (*tess->callBegin)((a)); 106 else (*tess->callBegin)((a)); 107 107 108 #define CALL_VERTEX_OR_VERTEX_DATA(a) \ 108 #define CALL_VERTEX_OR_VERTEX_DATA(a) \ 109 if (tess->callVertexData != &__gl_noVertexD 109 if (tess->callVertexData != &__gl_noVertexData) \ 110 (*tess->callVertexData)((a),tess->polygo 110 (*tess->callVertexData)((a),tess->polygonData); \ 111 else (*tess->callVertex)((a)); 111 else (*tess->callVertex)((a)); 112 112 113 #define CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA(a) \ 113 #define CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA(a) \ 114 if (tess->callEdgeFlagData != &__gl_noEdgeF 114 if (tess->callEdgeFlagData != &__gl_noEdgeFlagData) \ 115 (*tess->callEdgeFlagData)((a),tess->poly 115 (*tess->callEdgeFlagData)((a),tess->polygonData); \ 116 else (*tess->callEdgeFlag)((a)); 116 else (*tess->callEdgeFlag)((a)); 117 117 118 #define CALL_END_OR_END_DATA() \ 118 #define CALL_END_OR_END_DATA() \ 119 if (tess->callEndData != &__gl_noEndData) \ 119 if (tess->callEndData != &__gl_noEndData) \ 120 (*tess->callEndData)(tess->polygonData); 120 (*tess->callEndData)(tess->polygonData); \ 121 else (*tess->callEnd)(); 121 else (*tess->callEnd)(); 122 122 123 #define CALL_COMBINE_OR_COMBINE_DATA(a,b,c,d) 123 #define CALL_COMBINE_OR_COMBINE_DATA(a,b,c,d) \ 124 if (tess->callCombineData != &__gl_noCombin 124 if (tess->callCombineData != &__gl_noCombineData) \ 125 (*tess->callCombineData)((a),(b),(c),(d) 125 (*tess->callCombineData)((a),(b),(c),(d),tess->polygonData); \ 126 else (*tess->callCombine)((a),(b),(c),(d)); 126 else (*tess->callCombine)((a),(b),(c),(d)); 127 127 128 #define CALL_ERROR_OR_ERROR_DATA(a) \ 128 #define CALL_ERROR_OR_ERROR_DATA(a) \ 129 if (tess->callErrorData != &__gl_noErrorDat 129 if (tess->callErrorData != &__gl_noErrorData) \ 130 (*tess->callErrorData)((a),tess->polygon 130 (*tess->callErrorData)((a),tess->polygonData); \ 131 else (*tess->callError)((a)); 131 else (*tess->callError)((a)); 132 132 133 #endif 133 #endif