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