mipoly.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included
  9. in all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  14. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  16. OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall
  18. not be used in advertising or otherwise to promote the sale, use or
  19. other dealings in this Software without prior written authorization
  20. from The Open Group.
  21. */
  22. /*
  23. * fill.h
  24. *
  25. * Created by Brian Kelleher; Oct 1985
  26. *
  27. * Include file for filled polygon routines.
  28. *
  29. * These are the data structures needed to scan
  30. * convert regions. Two different scan conversion
  31. * methods are available -- the even-odd method, and
  32. * the winding number method.
  33. * The even-odd rule states that a point is inside
  34. * the polygon if a ray drawn from that point in any
  35. * direction will pass through an odd number of
  36. * path segments.
  37. * By the winding number rule, a point is decided
  38. * to be inside the polygon if a ray drawn from that
  39. * point in any direction passes through a different
  40. * number of clockwise and counter-clockwise path
  41. * segments.
  42. *
  43. * These data structures are adapted somewhat from
  44. * the algorithm in (Foley/Van Dam) for scan converting
  45. * polygons.
  46. * The basic algorithm is to start at the top (smallest y)
  47. * of the polygon, stepping down to the bottom of
  48. * the polygon by incrementing the y coordinate. We
  49. * keep a list of edges which the current scanline crosses,
  50. * sorted by x. This list is called the Active Edge Table (AET)
  51. * As we change the y-coordinate, we update each entry in
  52. * in the active edge table to reflect the edges new xcoord.
  53. * This list must be sorted at each scanline in case
  54. * two edges intersect.
  55. * We also keep a data structure known as the Edge Table (ET),
  56. * which keeps track of all the edges which the current
  57. * scanline has not yet reached. The ET is basically a
  58. * list of ScanLineList structures containing a list of
  59. * edges which are entered at a given scanline. There is one
  60. * ScanLineList per scanline at which an edge is entered.
  61. * When we enter a new edge, we move it from the ET to the AET.
  62. *
  63. * From the AET, we can implement the even-odd rule as in
  64. * (Foley/Van Dam).
  65. * The winding number rule is a little trickier. We also
  66. * keep the EdgeTableEntries in the AET linked by the
  67. * nextWETE (winding EdgeTableEntry) link. This allows
  68. * the edges to be linked just as before for updating
  69. * purposes, but only uses the edges linked by the nextWETE
  70. * link as edges representing spans of the polygon to
  71. * drawn (as with the even-odd rule).
  72. */
  73. /*
  74. * for the winding number rule
  75. */
  76. #define CLOCKWISE 1
  77. #define COUNTERCLOCKWISE -1
  78. typedef struct _EdgeTableEntry {
  79. int ymax; /* ycoord at which we exit this edge. */
  80. BRESINFO bres; /* Bresenham info to run the edge */
  81. struct _EdgeTableEntry *next; /* next in the list */
  82. struct _EdgeTableEntry *back; /* for insertion sort */
  83. struct _EdgeTableEntry *nextWETE; /* for winding num rule */
  84. int ClockWise; /* flag for winding number rule */
  85. } EdgeTableEntry;
  86. typedef struct _ScanLineList{
  87. int scanline; /* the scanline represented */
  88. EdgeTableEntry *edgelist; /* header node */
  89. struct _ScanLineList *next; /* next in the list */
  90. } ScanLineList;
  91. typedef struct {
  92. int ymax; /* ymax for the polygon */
  93. int ymin; /* ymin for the polygon */
  94. ScanLineList scanlines; /* header node */
  95. } EdgeTable;
  96. /*
  97. * Here is a struct to help with storage allocation
  98. * so we can allocate a big chunk at a time, and then take
  99. * pieces from this heap when we need to.
  100. */
  101. #define SLLSPERBLOCK 25
  102. typedef struct _ScanLineListBlock {
  103. ScanLineList SLLs[SLLSPERBLOCK];
  104. struct _ScanLineListBlock *next;
  105. } ScanLineListBlock;
  106. /*
  107. * number of points to buffer before sending them off
  108. * to scanlines() : Must be an even number
  109. */
  110. #define NUMPTSTOBUFFER 200
  111. /*
  112. *
  113. * a few macros for the inner loops of the fill code where
  114. * performance considerations don't allow a procedure call.
  115. *
  116. * Evaluate the given edge at the given scanline.
  117. * If the edge has expired, then we leave it and fix up
  118. * the active edge table; otherwise, we increment the
  119. * x value to be ready for the next scanline.
  120. * The winding number rule is in effect, so we must notify
  121. * the caller when the edge has been removed so he
  122. * can reorder the Winding Active Edge Table.
  123. */
  124. #define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
  125. if (pAET->ymax == y) { /* leaving this edge */ \
  126. pPrevAET->next = pAET->next; \
  127. pAET = pPrevAET->next; \
  128. fixWAET = 1; \
  129. if (pAET) \
  130. pAET->back = pPrevAET; \
  131. } \
  132. else { \
  133. BRESINCRPGONSTRUCT(pAET->bres); \
  134. pPrevAET = pAET; \
  135. pAET = pAET->next; \
  136. } \
  137. }
  138. /*
  139. * Evaluate the given edge at the given scanline.
  140. * If the edge has expired, then we leave it and fix up
  141. * the active edge table; otherwise, we increment the
  142. * x value to be ready for the next scanline.
  143. * The even-odd rule is in effect.
  144. */
  145. #define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
  146. if (pAET->ymax == y) { /* leaving this edge */ \
  147. pPrevAET->next = pAET->next; \
  148. pAET = pPrevAET->next; \
  149. if (pAET) \
  150. pAET->back = pPrevAET; \
  151. } \
  152. else { \
  153. BRESINCRPGONSTRUCT(pAET->bres); \
  154. pPrevAET = pAET; \
  155. pAET = pAET->next; \
  156. } \
  157. }
  158. /* mipolyutil.c */
  159. extern Bool miInsertEdgeInET(
  160. EdgeTable * /*ET*/,
  161. EdgeTableEntry * /*ETE*/,
  162. int /*scanline*/,
  163. ScanLineListBlock ** /*SLLBlock*/,
  164. int * /*iSLLBlock*/
  165. );
  166. extern Bool miCreateETandAET(
  167. int /*count*/,
  168. DDXPointPtr /*pts*/,
  169. EdgeTable * /*ET*/,
  170. EdgeTableEntry * /*AET*/,
  171. EdgeTableEntry * /*pETEs*/,
  172. ScanLineListBlock * /*pSLLBlock*/
  173. );
  174. extern void miloadAET(
  175. EdgeTableEntry * /*AET*/,
  176. EdgeTableEntry * /*ETEs*/
  177. );
  178. extern void micomputeWAET(
  179. EdgeTableEntry * /*AET*/
  180. );
  181. extern int miInsertionSort(
  182. EdgeTableEntry * /*AET*/
  183. );
  184. extern void miFreeStorage(
  185. ScanLineListBlock * /*pSLLBlock*/
  186. );