merge_r.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*<html><pre> -<a href="qh-merge_r.htm"
  2. >-------------------------------</a><a name="TOP">-</a>
  3. merge_r.h
  4. header file for merge_r.c
  5. see qh-merge_r.htm and merge_r.c
  6. Copyright (c) 1993-2020 C.B. Barber.
  7. $Id: //main/2019/qhull/src/libqhull_r/merge_r.h#2 $$Change: 2953 $
  8. $DateTime: 2020/05/21 22:05:32 $$Author: bbarber $
  9. */
  10. #ifndef qhDEFmerge
  11. #define qhDEFmerge 1
  12. #include "libqhull_r.h"
  13. /*============ -constants- ==============*/
  14. /*-<a href="qh-merge_r.htm#TOC"
  15. >--------------------------------</a><a name="qh_ANGLEnone">-</a>
  16. qh_ANGLEnone
  17. indicates missing angle for mergeT->angle
  18. */
  19. #define qh_ANGLEnone 2.0
  20. /*-<a href="qh-merge_r.htm#TOC"
  21. >--------------------------------</a><a name="MRG">-</a>
  22. MRG... (mergeType)
  23. indicates the type of a merge (mergeT->type)
  24. MRGcoplanar...MRGtwisted set by qh_test_centrum_merge, qh_test_nonsimplicial_merge
  25. */
  26. typedef enum { /* must match mergetypes[] */
  27. MRGnone= 0,
  28. /* MRGcoplanar..MRGtwisted go into qh.facet_mergeset for qh_all_merges
  29. qh_compare_facetmerge selects lower mergetypes for merging first */
  30. MRGcoplanar, /* (1) centrum coplanar if centrum ('Cn') or vertex not clearly above or below neighbor */
  31. MRGanglecoplanar, /* (2) angle coplanar if angle ('An') is coplanar */
  32. MRGconcave, /* (3) concave ridge */
  33. MRGconcavecoplanar, /* (4) concave and coplanar ridge, one side concave, other side coplanar */
  34. MRGtwisted, /* (5) twisted ridge, both concave and convex, facet1 is wider */
  35. /* MRGflip go into qh.facet_mergeset for qh_flipped_merges */
  36. MRGflip, /* (6) flipped facet if qh.interior_point is above facet, w/ facet1 == facet2 */
  37. /* MRGdupridge go into qh.facet_mergeset for qh_forcedmerges */
  38. MRGdupridge, /* (7) dupridge if more than two neighbors. Set by qh_mark_dupridges for qh_MERGEridge */
  39. /* MRGsubridge and MRGvertices go into vertex_mergeset */
  40. MRGsubridge, /* (8) merge pinched vertex to remove the subridge of a MRGdupridge */
  41. MRGvertices, /* (9) merge pinched vertex to remove a facet's ridges with the same vertices */
  42. /* MRGdegen, MRGredundant, and MRGmirror go into qh.degen_mergeset */
  43. MRGdegen, /* (10) degenerate facet (!enough neighbors) facet1 == facet2 */
  44. MRGredundant, /* (11) redundant facet (vertex subset) */
  45. /* merge_degenredundant assumes degen < redundant */
  46. MRGmirror, /* (12) mirror facets: same vertices due to null facets in qh_triangulate
  47. f.redundant for both facets*/
  48. /* MRGcoplanarhorizon for qh_mergecycle_all only */
  49. MRGcoplanarhorizon, /* (13) new facet coplanar with the horizon (qh_mergecycle_all) */
  50. ENDmrg
  51. } mergeType;
  52. /*-<a href="qh-merge_r.htm#TOC"
  53. >--------------------------------</a><a name="qh_MERGEapex">-</a>
  54. qh_MERGEapex
  55. flag for qh_mergefacet() to indicate an apex merge
  56. */
  57. #define qh_MERGEapex True
  58. /*============ -structures- ====================*/
  59. /*-<a href="qh-merge_r.htm#TOC"
  60. >--------------------------------</a><a name="mergeT">-</a>
  61. mergeT
  62. structure used to merge facets
  63. */
  64. typedef struct mergeT mergeT;
  65. struct mergeT { /* initialize in qh_appendmergeset */
  66. realT angle; /* cosine of angle between normals of facet1 and facet2,
  67. null value and right angle is 0.0, coplanar is 1.0, narrow is -1.0 */
  68. realT distance; /* absolute value of distance between vertices, centrum and facet, or vertex and facet */
  69. facetT *facet1; /* will merge facet1 into facet2 */
  70. facetT *facet2;
  71. vertexT *vertex1; /* will merge vertext1 into vertex2 for MRGsubridge or MRGvertices */
  72. vertexT *vertex2;
  73. ridgeT *ridge1; /* the duplicate ridges resolved by MRGvertices */
  74. ridgeT *ridge2; /* merge is deleted if either ridge is deleted (qh_delridge) */
  75. mergeType mergetype;
  76. };
  77. /*=========== -macros- =========================*/
  78. /*-<a href="qh-merge_r.htm#TOC"
  79. >--------------------------------</a><a name="FOREACHmerge_">-</a>
  80. FOREACHmerge_( merges ) {...}
  81. assign 'merge' to each merge in merges
  82. notes:
  83. uses 'mergeT *merge, **mergep;'
  84. if qh_mergefacet(),
  85. restart or use qh_setdellast() since qh.facet_mergeset may change
  86. see <a href="qset_r.h#FOREACHsetelement_">FOREACHsetelement_</a>
  87. */
  88. #define FOREACHmerge_(merges) FOREACHsetelement_(mergeT, merges, merge)
  89. /*-<a href="qh-poly_r.htm#TOC"
  90. >--------------------------------</a><a name="FOREACHmergeA_">-</a>
  91. FOREACHmergeA_( vertices ) { ... }
  92. assign 'mergeA' to each merge in merges
  93. notes:
  94. uses 'mergeT *mergeA, *mergeAp;'
  95. see <a href="qset_r.h#FOREACHsetelement_">FOREACHsetelement_</a>
  96. */
  97. #define FOREACHmergeA_(merges) FOREACHsetelement_(mergeT, merges, mergeA)
  98. /*-<a href="qh-poly_r.htm#TOC"
  99. >--------------------------------</a><a name="FOREACHmerge_i_">-</a>
  100. FOREACHmerge_i_(qh, vertices ) { ... }
  101. assign 'merge' and 'merge_i' for each merge in mergeset
  102. declare:
  103. mergeT *merge;
  104. int merge_n, merge_i;
  105. see:
  106. <a href="qset_r.h#FOREACHsetelement_i_">FOREACHsetelement_i_</a>
  107. */
  108. #define FOREACHmerge_i_(qh, mergeset) FOREACHsetelement_i_(qh, mergeT, mergeset, merge)
  109. /*============ prototypes in alphabetical order after pre/postmerge =======*/
  110. #ifdef __cplusplus
  111. extern "C" {
  112. #endif
  113. void qh_premerge(qhT *qh, int apexpointid, realT maxcentrum, realT maxangle);
  114. void qh_postmerge(qhT *qh, const char *reason, realT maxcentrum, realT maxangle,
  115. boolT vneighbors);
  116. void qh_all_merges(qhT *qh, boolT othermerge, boolT vneighbors);
  117. void qh_all_vertexmerges(qhT *qh, int apexpointid, facetT *facet, facetT **retryfacet);
  118. void qh_appendmergeset(qhT *qh, facetT *facet, facetT *neighbor, mergeType mergetype, coordT dist, realT angle);
  119. void qh_appendvertexmerge(qhT *qh, vertexT *vertex, vertexT *destination, mergeType mergetype, realT distance, ridgeT *ridge1, ridgeT *ridge2);
  120. setT *qh_basevertices(qhT *qh, facetT *samecycle);
  121. void qh_check_dupridge(qhT *qh, facetT *facet1, realT dist1, facetT *facet2, realT dist2);
  122. void qh_checkconnect(qhT *qh /* qh.new_facets */);
  123. void qh_checkdelfacet(qhT *qh, facetT *facet, setT *mergeset);
  124. void qh_checkdelridge(qhT *qh /* qh.visible_facets, vertex_mergeset */);
  125. boolT qh_checkzero(qhT *qh, boolT testall);
  126. int qh_compare_anglemerge(const void *p1, const void *p2);
  127. int qh_compare_facetmerge(const void *p1, const void *p2);
  128. int qh_comparevisit(const void *p1, const void *p2);
  129. void qh_copynonconvex(qhT *qh, ridgeT *atridge);
  130. void qh_degen_redundant_facet(qhT *qh, facetT *facet);
  131. void qh_drop_mergevertex(qhT *qh, mergeT *merge);
  132. void qh_delridge_merge(qhT *qh, ridgeT *ridge);
  133. vertexT *qh_find_newvertex(qhT *qh, vertexT *oldvertex, setT *vertices, setT *ridges);
  134. vertexT *qh_findbest_pinchedvertex(qhT *qh, mergeT *merge, vertexT *apex, vertexT **pinchedp, realT *distp /* qh.newfacet_list */);
  135. vertexT *qh_findbest_ridgevertex(qhT *qh, ridgeT *ridge, vertexT **pinchedp, coordT *distp);
  136. void qh_findbest_test(qhT *qh, boolT testcentrum, facetT *facet, facetT *neighbor,
  137. facetT **bestfacet, realT *distp, realT *mindistp, realT *maxdistp);
  138. facetT *qh_findbestneighbor(qhT *qh, facetT *facet, realT *distp, realT *mindistp, realT *maxdistp);
  139. void qh_flippedmerges(qhT *qh, facetT *facetlist, boolT *wasmerge);
  140. void qh_forcedmerges(qhT *qh, boolT *wasmerge);
  141. void qh_freemergesets(qhT *qh);
  142. void qh_getmergeset(qhT *qh, facetT *facetlist);
  143. void qh_getmergeset_initial(qhT *qh, facetT *facetlist);
  144. boolT qh_getpinchedmerges(qhT *qh, vertexT *apex, coordT maxdupdist, boolT *iscoplanar /* qh.newfacet_list, vertex_mergeset */);
  145. boolT qh_hasmerge(setT *mergeset, mergeType type, facetT *facetA, facetT *facetB);
  146. void qh_hashridge(qhT *qh, setT *hashtable, int hashsize, ridgeT *ridge, vertexT *oldvertex);
  147. ridgeT *qh_hashridge_find(qhT *qh, setT *hashtable, int hashsize, ridgeT *ridge,
  148. vertexT *vertex, vertexT *oldvertex, int *hashslot);
  149. void qh_initmergesets(qhT *qh);
  150. void qh_makeridges(qhT *qh, facetT *facet);
  151. void qh_mark_dupridges(qhT *qh, facetT *facetlist, boolT allmerges);
  152. void qh_maybe_duplicateridge(qhT *qh, ridgeT *ridge);
  153. void qh_maybe_duplicateridges(qhT *qh, facetT *facet);
  154. void qh_maydropneighbor(qhT *qh, facetT *facet);
  155. int qh_merge_degenredundant(qhT *qh);
  156. void qh_merge_nonconvex(qhT *qh, facetT *facet1, facetT *facet2, mergeType mergetype);
  157. void qh_merge_pinchedvertices(qhT *qh, int apexpointid /* qh.newfacet_list */);
  158. void qh_merge_twisted(qhT *qh, facetT *facet1, facetT *facet2);
  159. void qh_mergecycle(qhT *qh, facetT *samecycle, facetT *newfacet);
  160. void qh_mergecycle_all(qhT *qh, facetT *facetlist, boolT *wasmerge);
  161. void qh_mergecycle_facets(qhT *qh, facetT *samecycle, facetT *newfacet);
  162. void qh_mergecycle_neighbors(qhT *qh, facetT *samecycle, facetT *newfacet);
  163. void qh_mergecycle_ridges(qhT *qh, facetT *samecycle, facetT *newfacet);
  164. void qh_mergecycle_vneighbors(qhT *qh, facetT *samecycle, facetT *newfacet);
  165. void qh_mergefacet(qhT *qh, facetT *facet1, facetT *facet2, mergeType mergetype, realT *mindist, realT *maxdist, boolT mergeapex);
  166. void qh_mergefacet2d(qhT *qh, facetT *facet1, facetT *facet2);
  167. void qh_mergeneighbors(qhT *qh, facetT *facet1, facetT *facet2);
  168. void qh_mergeridges(qhT *qh, facetT *facet1, facetT *facet2);
  169. void qh_mergesimplex(qhT *qh, facetT *facet1, facetT *facet2, boolT mergeapex);
  170. void qh_mergevertex_del(qhT *qh, vertexT *vertex, facetT *facet1, facetT *facet2);
  171. void qh_mergevertex_neighbors(qhT *qh, facetT *facet1, facetT *facet2);
  172. void qh_mergevertices(qhT *qh, setT *vertices1, setT **vertices);
  173. setT *qh_neighbor_intersections(qhT *qh, vertexT *vertex);
  174. setT *qh_neighbor_vertices(qhT *qh, vertexT *vertex, setT *subridge);
  175. void qh_neighbor_vertices_facet(qhT *qh, vertexT *vertexA, facetT *facet, setT **vertices);
  176. void qh_newvertices(qhT *qh, setT *vertices);
  177. mergeT *qh_next_vertexmerge(qhT *qh);
  178. facetT *qh_opposite_horizonfacet(qhT *qh, mergeT *merge, vertexT **vertex);
  179. boolT qh_reducevertices(qhT *qh);
  180. vertexT *qh_redundant_vertex(qhT *qh, vertexT *vertex);
  181. boolT qh_remove_extravertices(qhT *qh, facetT *facet);
  182. void qh_remove_mergetype(qhT *qh, setT *mergeset, mergeType type);
  183. void qh_rename_adjacentvertex(qhT *qh, vertexT *oldvertex, vertexT *newvertex, realT dist);
  184. vertexT *qh_rename_sharedvertex(qhT *qh, vertexT *vertex, facetT *facet);
  185. boolT qh_renameridgevertex(qhT *qh, ridgeT *ridge, vertexT *oldvertex, vertexT *newvertex);
  186. void qh_renamevertex(qhT *qh, vertexT *oldvertex, vertexT *newvertex, setT *ridges,
  187. facetT *oldfacet, facetT *neighborA);
  188. boolT qh_test_appendmerge(qhT *qh, facetT *facet, facetT *neighbor, boolT simplicial);
  189. void qh_test_degen_neighbors(qhT *qh, facetT *facet);
  190. boolT qh_test_centrum_merge(qhT *qh, facetT *facet, facetT *neighbor, realT angle, boolT okangle);
  191. boolT qh_test_nonsimplicial_merge(qhT *qh, facetT *facet, facetT *neighbor, realT angle, boolT okangle);
  192. void qh_test_redundant_neighbors(qhT *qh, facetT *facet);
  193. boolT qh_test_vneighbors(qhT *qh /* qh.newfacet_list */);
  194. void qh_tracemerge(qhT *qh, facetT *facet1, facetT *facet2, mergeType mergetype);
  195. void qh_tracemerging(qhT *qh);
  196. void qh_undo_newfacets(qhT *qh);
  197. void qh_updatetested(qhT *qh, facetT *facet1, facetT *facet2);
  198. setT *qh_vertexridges(qhT *qh, vertexT *vertex, boolT allneighbors);
  199. void qh_vertexridges_facet(qhT *qh, vertexT *vertex, facetT *facet, setT **ridges);
  200. void qh_willdelete(qhT *qh, facetT *facet, facetT *replace);
  201. #ifdef __cplusplus
  202. } /* extern "C" */
  203. #endif
  204. #endif /* qhDEFmerge */