Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
11 KiB

  1. #ifndef __mesh_h_
  2. #define __mesh_h_
  3. /*
  4. ** Copyright 1994, Silicon Graphics, Inc.
  5. ** All Rights Reserved.
  6. **
  7. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8. ** the contents of this file may not be disclosed to third parties, copied or
  9. ** duplicated in any form, in whole or in part, without the prior written
  10. ** permission of Silicon Graphics, Inc.
  11. **
  12. ** RESTRICTED RIGHTS LEGEND:
  13. ** Use, duplication or disclosure by the Government is subject to restrictions
  14. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17. ** rights reserved under the Copyright Laws of the United States.
  18. **
  19. ** Author: Eric Veach, July 1994.
  20. */
  21. #ifdef NT
  22. #include <glos.h>
  23. #endif
  24. #include <GL/glu.h>
  25. typedef struct GLUmesh GLUmesh;
  26. typedef struct GLUvertex GLUvertex;
  27. typedef struct GLUface GLUface;
  28. typedef struct GLUhalfEdge GLUhalfEdge;
  29. typedef struct ActiveRegion ActiveRegion; /* Internal data */
  30. /* The mesh structure is similar in spirit, notation, and operations
  31. * to the "quad-edge" structure (see L. Guibas and J. Stolfi, Primitives
  32. * for the manipulation of general subdivisions and the computation of
  33. * Voronoi diagrams, ACM Transactions on Graphics, 4(2):74-123, April 1985).
  34. * For a simplified description, see the course notes for CS348a,
  35. * "Mathematical Foundations of Computer Graphics", available at the
  36. * Stanford bookstore (and taught during the fall quarter).
  37. * The implementation also borrows a tiny subset of the graph-based approach
  38. * use in Mantyla's Geometric Work Bench (see M. Mantyla, An Introduction
  39. * to Sold Modeling, Computer Science Press, Rockville, Maryland, 1988).
  40. *
  41. * The fundamental data structure is the "half-edge". Two half-edges
  42. * go together to make an edge, but they point in opposite directions.
  43. * Each half-edge has a pointer to its mate (the "symmetric" half-edge Sym),
  44. * its origin vertex (Org), the face on its left side (Lface), and the
  45. * adjacent half-edges in the CCW direction around the origin vertex
  46. * (Onext) and around the left face (Lnext). There is also a "next"
  47. * pointer for the global edge list (see below).
  48. *
  49. * The notation used for mesh navigation:
  50. * Sym = the mate of a half-edge (same edge, but opposite direction)
  51. * Onext = edge CCW around origin vertex (keep same origin)
  52. * Dnext = edge CCW around destination vertex (keep same dest)
  53. * Lnext = edge CCW around left face (dest becomes new origin)
  54. * Rnext = edge CCW around right face (origin becomes new dest)
  55. *
  56. * "prev" means to substitute CW for CCW in the definitions above.
  57. *
  58. * The mesh keeps global lists of all vertices, faces, and edges,
  59. * stored as doubly-linked circular lists with a dummy header node.
  60. * The mesh stores pointers to these dummy headers (vHead, fHead, eHead).
  61. *
  62. * The circular edge list is special; since half-edges always occur
  63. * in pairs (e and e->Sym), each half-edge stores a pointer in only
  64. * one direction. Starting at eHead and following the e->next pointers
  65. * will visit each *edge* once (ie. e or e->Sym, but not both).
  66. * e->Sym stores a pointer in the opposite direction, thus it is
  67. * always true that e->Sym->next->Sym->next == e.
  68. *
  69. * Each vertex has a pointer to next and previous vertices in the
  70. * circular list, and a pointer to a half-edge with this vertex as
  71. * the origin (NULL if this is the dummy header). There is also a
  72. * field "data" for client data.
  73. *
  74. * Each face has a pointer to the next and previous faces in the
  75. * circular list, and a pointer to a half-edge with this face as
  76. * the left face (NULL if this is the dummy header). There is also
  77. * a field "data" for client data.
  78. *
  79. * Note that what we call a "face" is really a loop; faces may consist
  80. * of more than one loop (ie. not simply connected), but there is no
  81. * record of this in the data structure. The mesh may consist of
  82. * several disconnected regions, so it may not be possible to visit
  83. * the entire mesh by starting at a half-edge and traversing the edge
  84. * structure.
  85. *
  86. * The mesh does NOT support isolated vertices; a vertex is deleted along
  87. * with its last edge. Similarly when two faces are merged, one of the
  88. * faces is deleted (see __gl_meshDelete below). For mesh operations,
  89. * all face (loop) and vertex pointers must not be NULL. However, once
  90. * mesh manipulation is finished, __gl_MeshZapFace can be used to delete
  91. * faces of the mesh, one at a time. All external faces can be "zapped"
  92. * before the mesh is returned to the client; then a NULL face indicates
  93. * a region which is not part of the output polygon.
  94. */
  95. struct GLUvertex {
  96. GLUvertex *next; /* next vertex (never NULL) */
  97. GLUvertex *prev; /* previous vertex (never NULL) */
  98. GLUhalfEdge *anEdge; /* a half-edge with this origin */
  99. void *data; /* client's data */
  100. /* Internal data (keep hidden) */
  101. GLdouble coords[3]; /* vertex location in 3D */
  102. GLdouble s, t; /* projection onto the sweep plane */
  103. long pqHandle; /* to allow deletion from priority queue */
  104. };
  105. struct GLUface {
  106. GLUface *next; /* next face (never NULL) */
  107. GLUface *prev; /* previous face (never NULL) */
  108. GLUhalfEdge *anEdge; /* a half edge with this left face */
  109. void *data; /* room for client's data */
  110. /* Internal data (keep hidden) */
  111. GLUface *trail; /* "stack" for conversion to strips */
  112. GLboolean marked; /* flag for conversion to strips */
  113. GLboolean inside; /* this face is in the polygon interior */
  114. };
  115. struct GLUhalfEdge {
  116. GLUhalfEdge *next; /* doubly-linked list (prev==Sym->next) */
  117. GLUhalfEdge *Sym; /* same edge, opposite direction */
  118. GLUhalfEdge *Onext; /* next edge CCW around origin */
  119. GLUhalfEdge *Lnext; /* next edge CCW around left face */
  120. GLUvertex *Org; /* origin vertex (Overtex too long) */
  121. GLUface *Lface; /* left face */
  122. /* Internal data (keep hidden) */
  123. ActiveRegion *activeRegion; /* a region with this upper edge (sweep.c) */
  124. int winding; /* change in winding number when crossing
  125. from the right face to the left face */
  126. };
  127. #define Rface Sym->Lface
  128. #define Dst Sym->Org
  129. #define Oprev Sym->Lnext
  130. #define Lprev Onext->Sym
  131. #define Dprev Lnext->Sym
  132. #define Rprev Sym->Onext
  133. #define Dnext Rprev->Sym /* 3 pointers */
  134. #define Rnext Oprev->Sym /* 3 pointers */
  135. struct GLUmesh {
  136. GLUvertex vHead; /* dummy header for vertex list */
  137. GLUface fHead; /* dummy header for face list */
  138. GLUhalfEdge eHead; /* dummy header for edge list */
  139. GLUhalfEdge eHeadSym; /* and its symmetric counterpart */
  140. };
  141. /* The mesh operations below have three motivations: completeness,
  142. * convenience, and efficiency. The basic mesh operations are MakeEdge,
  143. * Splice, and Delete. All the other edge operations can be implemented
  144. * in terms of these. The other operations are provided for convenience
  145. * and/or efficiency.
  146. *
  147. * When a face is split or a vertex is added, they are inserted into the
  148. * global list *before* the existing vertex or face (ie. e->Org or e->Lface).
  149. * This makes it easier to process all vertices or faces in the global lists
  150. * without worrying about processing the same data twice. As a convenience,
  151. * when a face is split, the "inside" flag is copied from the old face.
  152. * Other internal data (v->data, v->activeRegion, f->data, f->marked,
  153. * f->trail, e->winding) is set to zero.
  154. *
  155. * ********************** Basic Edge Operations **************************
  156. *
  157. * __gl_meshMakeEdge( mesh ) creates one edge, two vertices, and a loop.
  158. * The loop (face) consists of the two new half-edges.
  159. *
  160. * __gl_meshSplice( eOrg, eDst ) is the basic operation for changing the
  161. * mesh connectivity and topology. It changes the mesh so that
  162. * eOrg->Onext <- OLD( eDst->Onext )
  163. * eDst->Onext <- OLD( eOrg->Onext )
  164. * where OLD(...) means the value before the meshSplice operation.
  165. *
  166. * This can have two effects on the vertex structure:
  167. * - if eOrg->Org != eDst->Org, the two vertices are merged together
  168. * - if eOrg->Org == eDst->Org, the origin is split into two vertices
  169. * In both cases, eDst->Org is changed and eOrg->Org is untouched.
  170. *
  171. * Similarly (and independently) for the face structure,
  172. * - if eOrg->Lface == eDst->Lface, one loop is split into two
  173. * - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one
  174. * In both cases, eDst->Lface is changed and eOrg->Lface is unaffected.
  175. *
  176. * __gl_meshDelete( eDel ) removes the edge eDel. There are several cases:
  177. * if (eDel->Lface != eDel->Rface), we join two loops into one; the loop
  178. * eDel->Lface is deleted. Otherwise, we are splitting one loop into two;
  179. * the newly created loop will contain eDel->Dst. If the deletion of eDel
  180. * would create isolated vertices, those are deleted as well.
  181. *
  182. * ********************** Other Edge Operations **************************
  183. *
  184. * __gl_meshAddEdgeVertex( eOrg ) creates a new edge eNew such that
  185. * eNew == eOrg->Lnext, and eNew->Dst is a newly created vertex.
  186. * eOrg and eNew will have the same left face.
  187. *
  188. * __gl_meshSplitEdge( eOrg ) splits eOrg into two edges eOrg and eNew,
  189. * such that eNew == eOrg->Lnext. The new vertex is eOrg->Dst == eNew->Org.
  190. * eOrg and eNew will have the same left face.
  191. *
  192. * __gl_meshConnect( eOrg, eDst ) creates a new edge from eOrg->Dst
  193. * to eDst->Org, and returns the corresponding half-edge eNew.
  194. * If eOrg->Lface == eDst->Lface, this splits one loop into two,
  195. * and the newly created loop is eNew->Lface. Otherwise, two disjoint
  196. * loops are merged into one, and the loop eDst->Lface is destroyed.
  197. *
  198. * ************************ Other Operations *****************************
  199. *
  200. * __gl_meshNewMesh() creates a new mesh with no edges, no vertices,
  201. * and no loops (what we usually call a "face").
  202. *
  203. * __gl_meshUnion( mesh1, mesh2 ) forms the union of all structures in
  204. * both meshes, and returns the new mesh (the old meshes are destroyed).
  205. *
  206. * __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh.
  207. *
  208. * __gl_meshZapFace( fZap ) destroys a face and removes it from the
  209. * global face list. All edges of fZap will have a NULL pointer as their
  210. * left face. Any edges which also have a NULL pointer as their right face
  211. * are deleted entirely (along with any isolated vertices this produces).
  212. * An entire mesh can be deleted by zapping its faces, one at a time,
  213. * in any order. Zapped faces cannot be used in further mesh operations!
  214. *
  215. * __gl_meshCheckMesh( mesh ) checks a mesh for self-consistency.
  216. */
  217. GLUhalfEdge *__gl_meshMakeEdge( GLUmesh *mesh );
  218. void __gl_meshSplice( GLUhalfEdge *eOrg, GLUhalfEdge *eDst );
  219. void __gl_meshDelete( GLUhalfEdge *eDel );
  220. GLUhalfEdge *__gl_meshAddEdgeVertex( GLUhalfEdge *eOrg );
  221. GLUhalfEdge *__gl_meshSplitEdge( GLUhalfEdge *eOrg );
  222. GLUhalfEdge *__gl_meshConnect( GLUhalfEdge *eOrg, GLUhalfEdge *eDst );
  223. GLUmesh *__gl_meshNewMesh( void );
  224. GLUmesh *__gl_meshUnion( GLUmesh *mesh1, GLUmesh *mesh2 );
  225. void __gl_meshDeleteMesh( GLUmesh *mesh );
  226. void __gl_meshZapFace( GLUface *fZap );
  227. #ifdef NDEBUG
  228. #define __gl_meshCheckMesh( mesh )
  229. #else
  230. void __gl_meshCheckMesh( GLUmesh *mesh );
  231. #endif
  232. #endif