libqhull_r.h 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. /*<html><pre> -<a href="qh-qhull_r.htm"
  2. >-------------------------------</a><a name="TOP">-</a>
  3. libqhull_r.h
  4. user-level header file for using qhull.a library
  5. see qh-qhull_r.htm, qhull_ra.h
  6. Copyright (c) 1993-2020 The Geometry Center.
  7. $Id: //main/2019/qhull/src/libqhull_r/libqhull_r.h#16 $$Change: 3037 $
  8. $DateTime: 2020/09/03 17:28:32 $$Author: bbarber $
  9. includes function prototypes for libqhull_r.c, geom_r.c, global_r.c, io_r.c, user_r.c
  10. use mem_r.h for mem_r.c
  11. use qset_r.h for qset_r.c
  12. see unix_r.c for an example of using libqhull_r.h
  13. recompile qhull if you change this file
  14. */
  15. #ifndef qhDEFlibqhull
  16. #define qhDEFlibqhull 1
  17. /*=========================== -included files ==============*/
  18. /* user_r.h first for QHULL_CRTDBG */
  19. #include "user_r.h" /* user definable constants (e.g., realT). */
  20. #include "mem_r.h" /* Needed for qhT in libqhull_r.h */
  21. #include "qset_r.h" /* Needed for QHULL_LIB_CHECK */
  22. /* include stat_r.h after defining boolT. Needed for qhT in libqhull_r.h */
  23. #include <setjmp.h>
  24. #include <float.h>
  25. #include <limits.h>
  26. #include <time.h>
  27. #include <stdio.h>
  28. #ifndef __STDC__
  29. #ifndef __cplusplus
  30. #if !defined(_MSC_VER)
  31. #error Neither __STDC__ nor __cplusplus is defined. Please use strict ANSI C or C++ to compile
  32. #error Qhull. You may need to turn off compiler extensions in your project configuration. If
  33. #error your compiler is a standard C compiler, you can delete this warning from libqhull_r.h
  34. #endif
  35. #endif
  36. #endif
  37. /*============ constants and basic types ====================*/
  38. extern const char qh_version[]; /* defined in global_r.c */
  39. extern const char qh_version2[]; /* defined in global_r.c */
  40. /*-<a href="qh-geom_r.htm#TOC"
  41. >--------------------------------</a><a name="coordT">-</a>
  42. coordT
  43. coordinates and coefficients are stored as realT (i.e., double)
  44. notes:
  45. Qhull works well if realT is 'float'. If so joggle (QJ) is not effective.
  46. Could use 'float' for data and 'double' for calculations (realT vs. coordT)
  47. This requires many type casts, and adjusted error bounds.
  48. Also C compilers may do expressions in double anyway.
  49. */
  50. #define coordT realT
  51. /*-<a href="qh-geom_r.htm#TOC"
  52. >--------------------------------</a><a name="pointT">-</a>
  53. pointT
  54. a point is an array of coordinates, usually qh.hull_dim
  55. qh_pointid returns
  56. qh_IDnone if point==0 or qh is undefined
  57. qh_IDinterior for qh.interior_point
  58. qh_IDunknown if point is neither in qh.first_point... nor qh.other_points
  59. notes:
  60. qh.STOPcone and qh.STOPpoint assume that qh_IDunknown==-1 (other negative numbers indicate points)
  61. qh_IDunknown is also returned by getid_() for unknown facet, ridge, or vertex
  62. */
  63. #define pointT coordT
  64. typedef enum
  65. {
  66. qh_IDnone= -3, qh_IDinterior= -2, qh_IDunknown= -1
  67. }
  68. qh_pointT;
  69. /*-<a href="qh-qhull_r.htm#TOC"
  70. >--------------------------------</a><a name="flagT">-</a>
  71. flagT
  72. Boolean flag as a bit
  73. */
  74. #define flagT unsigned int
  75. /*-<a href="qh-qhull_r.htm#TOC"
  76. >--------------------------------</a><a name="boolT">-</a>
  77. boolT
  78. boolean value, either True or False
  79. notes:
  80. needed for portability
  81. Use qh_False/qh_True as synonyms
  82. */
  83. #define boolT unsigned int
  84. #ifdef False
  85. #undef False
  86. #endif
  87. #ifdef True
  88. #undef True
  89. #endif
  90. #define False 0
  91. #define True 1
  92. #define qh_False 0
  93. #define qh_True 1
  94. #include "stat_r.h" /* needs boolT */
  95. /*-<a href="qh-qhull_r.htm#TOC"
  96. >--------------------------------</a><a name="CENTERtype">-</a>
  97. qh_CENTER
  98. to distinguish facet->center
  99. */
  100. typedef enum
  101. {
  102. qh_ASnone= 0, /* If not MERGING and not VORONOI */
  103. qh_ASvoronoi, /* Set by qh_clearcenters on qh_prepare_output, or if not MERGING and VORONOI */
  104. qh_AScentrum /* If MERGING (assumed during merging) */
  105. }
  106. qh_CENTER;
  107. /*-<a href="qh-qhull_r.htm#TOC"
  108. >--------------------------------</a><a name="qh_PRINT">-</a>
  109. qh_PRINT
  110. output formats for printing (qh.PRINTout).
  111. 'Fa' 'FV' 'Fc' 'FC'
  112. notes:
  113. some of these names are similar to qhT names. The similar names are only
  114. used in switch statements in qh_printbegin() etc.
  115. */
  116. typedef enum {qh_PRINTnone= 0,
  117. qh_PRINTarea, qh_PRINTaverage, /* 'Fa' 'FV' 'Fc' 'FC' */
  118. qh_PRINTcoplanars, qh_PRINTcentrums,
  119. qh_PRINTfacets, qh_PRINTfacets_xridge, /* 'f' 'FF' 'G' 'FI' 'Fi' 'Fn' */
  120. qh_PRINTgeom, qh_PRINTids, qh_PRINTinner, qh_PRINTneighbors,
  121. qh_PRINTnormals, qh_PRINTouter, qh_PRINTmaple, /* 'n' 'Fo' 'i' 'm' 'Fm' 'FM', 'o' */
  122. qh_PRINTincidences, qh_PRINTmathematica, qh_PRINTmerges, qh_PRINToff,
  123. qh_PRINToptions, qh_PRINTpointintersect, /* 'FO' 'Fp' 'FP' 'p' 'FQ' 'FS' */
  124. qh_PRINTpointnearest, qh_PRINTpoints, qh_PRINTqhull, qh_PRINTsize,
  125. qh_PRINTsummary, qh_PRINTtriangles, /* 'Fs' 'Ft' 'Fv' 'FN' 'Fx' */
  126. qh_PRINTvertices, qh_PRINTvneighbors, qh_PRINTextremes,
  127. qh_PRINTEND} qh_PRINT;
  128. /*-<a href="qh-qhull_r.htm#TOC"
  129. >--------------------------------</a><a name="qh_ALL">-</a>
  130. qh_ALL
  131. argument flag for selecting everything
  132. */
  133. #define qh_ALL True
  134. #define qh_NOupper True /* argument for qh_findbest */
  135. #define qh_IScheckmax True /* argument for qh_findbesthorizon */
  136. #define qh_ISnewfacets True /* argument for qh_findbest */
  137. #define qh_RESETvisible True /* argument for qh_resetlists */
  138. /*-<a href="qh-qhull_r.htm#TOC"
  139. >--------------------------------</a><a name="qh_ERR">-</a>
  140. qh_ERR...
  141. Qhull exit status codes, for indicating errors
  142. See: MSG_ERROR (6000) and MSG_WARNING (7000) [user_r.h]
  143. */
  144. #define qh_ERRnone 0 /* no error occurred during qhull */
  145. #define qh_ERRinput 1 /* input inconsistency */
  146. #define qh_ERRsingular 2 /* singular input data, calls qh_printhelp_singular */
  147. #define qh_ERRprec 3 /* precision error, calls qh_printhelp_degenerate */
  148. #define qh_ERRmem 4 /* insufficient memory, matches mem_r.h */
  149. #define qh_ERRqhull 5 /* internal error detected, matches mem_r.h, calls qh_printhelp_internal */
  150. #define qh_ERRother 6 /* other error detected */
  151. #define qh_ERRtopology 7 /* topology error, maybe due to nearly adjacent vertices, calls qh_printhelp_topology */
  152. #define qh_ERRwide 8 /* wide facet error, maybe due to nearly adjacent vertices, calls qh_printhelp_wide */
  153. #define qh_ERRdebug 9 /* qh_errexit from debugging code */
  154. /*-<a href="qh-qhull_r.htm#TOC"
  155. >--------------------------------</a><a name="qh_FILEstderr">-</a>
  156. qh_FILEstderr
  157. Fake stderr to distinguish error output from normal output
  158. For C++ interface. Must redefine qh_fprintf_qhull
  159. */
  160. #define qh_FILEstderr ((FILE *)1)
  161. /* ============ -structures- ====================
  162. each of the following structures is defined by a typedef
  163. all realT and coordT fields occur at the beginning of a structure
  164. (otherwise space may be wasted due to alignment)
  165. define all flags together and pack into 32-bit number
  166. DEFqhT and DEFsetT are likewise defined in mem_r.h, qset_r.h, and stat_r.h
  167. */
  168. typedef struct vertexT vertexT;
  169. typedef struct ridgeT ridgeT;
  170. typedef struct facetT facetT;
  171. #ifndef DEFqhT
  172. #define DEFqhT 1
  173. typedef struct qhT qhT; /* defined below */
  174. #endif
  175. #ifndef DEFsetT
  176. #define DEFsetT 1
  177. typedef struct setT setT; /* defined in qset_r.h */
  178. #endif
  179. /*-<a href="qh-poly_r.htm#TOC"
  180. >--------------------------------</a><a name="facetT">-</a>
  181. facetT
  182. defines a facet
  183. notes:
  184. qhull() generates the hull as a list of facets.
  185. topological information:
  186. f.previous,next doubly-linked list of facets, next is always defined
  187. f.vertices set of vertices
  188. f.ridges set of ridges
  189. f.neighbors set of neighbors
  190. f.toporient True if facet has top-orientation (else bottom)
  191. geometric information:
  192. f.offset,normal hyperplane equation
  193. f.maxoutside offset to outer plane -- all points inside
  194. f.center centrum for testing convexity or Voronoi center for output
  195. f.simplicial True if facet is simplicial
  196. f.flipped True if facet does not include qh.interior_point
  197. for constructing hull:
  198. f.visible True if facet on list of visible facets (will be deleted)
  199. f.newfacet True if facet on list of newly created facets
  200. f.coplanarset set of points coplanar with this facet
  201. (includes near-inside points for later testing)
  202. f.outsideset set of points outside of this facet
  203. f.furthestdist distance to furthest point of outside set
  204. f.visitid marks visited facets during a loop
  205. f.replace replacement facet for to-be-deleted, visible facets
  206. f.samecycle,newcycle cycle of facets for merging into horizon facet
  207. see below for other flags and fields
  208. */
  209. /* QhullFacet.cpp -- Update static initializer list for s_empty_facet if add or remove fields */
  210. struct facetT {
  211. #if !qh_COMPUTEfurthest
  212. coordT furthestdist;/* distance to furthest point of outsideset */
  213. #endif
  214. #if qh_MAXoutside
  215. coordT maxoutside; /* max computed distance of point to facet
  216. Before QHULLfinished this is an approximation
  217. since maxdist not always set for qh_mergefacet
  218. Actual outer plane is +DISTround and
  219. computed outer plane is +2*DISTround.
  220. Initial maxoutside is qh.DISTround, otherwise distance tests need to account for DISTround */
  221. #endif
  222. coordT offset; /* exact offset of hyperplane from origin */
  223. coordT *normal; /* normal of hyperplane, hull_dim coefficients */
  224. /* if f.tricoplanar, shared with a neighbor */
  225. union { /* in order of testing */
  226. realT area; /* area of facet, only in io_r.c if f.isarea */
  227. facetT *replace; /* replacement facet for qh.NEWfacets with f.visible
  228. NULL if qh_mergedegen_redundant, interior, or !NEWfacets */
  229. facetT *samecycle; /* cycle of facets from the same visible/horizon intersection,
  230. if ->newfacet */
  231. facetT *newcycle; /* in horizon facet, current samecycle of new facets */
  232. facetT *trivisible; /* visible facet for ->tricoplanar facets during qh_triangulate() */
  233. facetT *triowner; /* owner facet for ->tricoplanar, !isarea facets w/ ->keepcentrum */
  234. }f;
  235. coordT *center; /* set according to qh.CENTERtype */
  236. /* qh_ASnone: no center (not MERGING) */
  237. /* qh_AScentrum: centrum for testing convexity (qh_getcentrum) */
  238. /* assumed qh_AScentrum while merging */
  239. /* qh_ASvoronoi: Voronoi center (qh_facetcenter) */
  240. /* after constructing the hull, it may be changed (qh_clearcenter) */
  241. /* if tricoplanar and !keepcentrum, shared with a neighbor */
  242. facetT *previous; /* previous facet in the facet_list or NULL, for C++ interface */
  243. facetT *next; /* next facet in the facet_list or facet_tail */
  244. setT *vertices; /* vertices for this facet, inverse sorted by ID
  245. if simplicial, 1st vertex was apex/furthest
  246. qh_reduce_vertices removes extraneous vertices via qh_remove_extravertices
  247. if f.visible, vertices may be on qh.del_vertices */
  248. setT *ridges; /* explicit ridges for nonsimplicial facets or nonsimplicial neighbors.
  249. For simplicial facets, neighbors define the ridges
  250. qh_makeridges() converts simplicial facets by creating ridges prior to merging
  251. If qh.NEWtentative, new facets have horizon ridge, but not vice versa
  252. if f.visible && qh.NEWfacets, ridges is empty */
  253. setT *neighbors; /* neighbors of the facet. Neighbors may be f.visible
  254. If simplicial, the kth neighbor is opposite the kth vertex and the
  255. first neighbor is the horizon facet for the first vertex.
  256. dupridges marked by qh_DUPLICATEridge (0x01) and qh_MERGEridge (0x02)
  257. if f.visible && qh.NEWfacets, neighbors is empty */
  258. setT *outsideset; /* set of points outside this facet
  259. if non-empty, last point is furthest
  260. if NARROWhull, includes coplanars (less than qh.MINoutside) for partitioning*/
  261. setT *coplanarset; /* set of points coplanar with this facet
  262. >= qh.min_vertex and <= facet->max_outside
  263. a point is assigned to the furthest facet
  264. if non-empty, last point is furthest away */
  265. unsigned int visitid; /* visit_id, for visiting all neighbors,
  266. all uses are independent */
  267. unsigned int id; /* unique identifier from qh.facet_id, 1..qh.facet_id, 0 is sentinel, printed as 'f%d' */
  268. unsigned int nummerge:9; /* number of merges */
  269. #define qh_MAXnummerge 511 /* 2^9-1 */
  270. /* 23 flags (at most 23 due to nummerge), printed by "flags:" in io_r.c */
  271. flagT tricoplanar:1; /* True if TRIangulate and simplicial and coplanar with a neighbor */
  272. /* all tricoplanars share the same apex */
  273. /* all tricoplanars share the same ->center, ->normal, ->offset, ->maxoutside */
  274. /* ->keepcentrum is true for the owner. It has the ->coplanareset */
  275. /* if ->degenerate, does not span facet (one logical ridge) */
  276. /* during qh_triangulate, f.trivisible points to original facet */
  277. flagT newfacet:1; /* True if facet on qh.newfacet_list (new/qh.first_newfacet or merged) */
  278. flagT visible:1; /* True if visible facet (will be deleted) */
  279. flagT toporient:1; /* True if created with top orientation
  280. after merging, use ridge orientation */
  281. flagT simplicial:1;/* True if simplicial facet, ->ridges may be implicit */
  282. flagT seen:1; /* used to perform operations only once, like visitid */
  283. flagT seen2:1; /* used to perform operations only once, like visitid */
  284. flagT flipped:1; /* True if facet is flipped */
  285. flagT upperdelaunay:1; /* True if facet is upper envelope of Delaunay triangulation */
  286. flagT notfurthest:1; /* True if last point of outsideset is not furthest */
  287. /*-------- flags primarily for output ---------*/
  288. flagT good:1; /* True if a facet marked good for output */
  289. flagT isarea:1; /* True if facet->f.area is defined */
  290. /*-------- flags for merging ------------------*/
  291. flagT dupridge:1; /* True if facet has one or more dupridge in a new facet (qh_matchneighbor),
  292. a dupridge has a subridge shared by more than one new facet */
  293. flagT mergeridge:1; /* True if facet or neighbor has a qh_MERGEridge (qh_mark_dupridges)
  294. ->normal defined for mergeridge and mergeridge2 */
  295. flagT mergeridge2:1; /* True if neighbor has a qh_MERGEridge (qh_mark_dupridges) */
  296. flagT coplanarhorizon:1; /* True if horizon facet is coplanar at last use */
  297. flagT mergehorizon:1; /* True if will merge into horizon (its first neighbor w/ f.coplanarhorizon). */
  298. flagT cycledone:1;/* True if mergecycle_all already done */
  299. flagT tested:1; /* True if facet convexity has been tested (false after merge */
  300. flagT keepcentrum:1; /* True if keep old centrum after a merge, or marks owner for ->tricoplanar
  301. Set by qh_updatetested if more than qh_MAXnewcentrum extra vertices
  302. Set by qh_mergefacet if |maxdist| > qh.WIDEfacet */
  303. flagT newmerge:1; /* True if facet is newly merged for reducevertices */
  304. flagT degenerate:1; /* True if facet is degenerate (degen_mergeset or ->tricoplanar) */
  305. flagT redundant:1; /* True if facet is redundant (degen_mergeset)
  306. Maybe merge degenerate and redundant to gain another flag */
  307. };
  308. /*-<a href="qh-poly_r.htm#TOC"
  309. >--------------------------------</a><a name="ridgeT">-</a>
  310. ridgeT
  311. defines a ridge
  312. notes:
  313. a ridge is hull_dim-1 simplex between two neighboring facets. If the
  314. facets are non-simplicial, there may be more than one ridge between
  315. two facets. E.G. a 4-d hypercube has two triangles between each pair
  316. of neighboring facets.
  317. topological information:
  318. vertices a set of vertices
  319. top,bottom neighboring facets with orientation
  320. geometric information:
  321. tested True if ridge is clearly convex
  322. nonconvex True if ridge is non-convex
  323. */
  324. /* QhullRidge.cpp -- Update static initializer list for s_empty_ridge if add or remove fields */
  325. struct ridgeT {
  326. setT *vertices; /* vertices belonging to this ridge, inverse sorted by ID
  327. NULL if a degen ridge (matchsame) */
  328. facetT *top; /* top facet for this ridge */
  329. facetT *bottom; /* bottom facet for this ridge
  330. ridge oriented by odd/even vertex order and top/bottom */
  331. unsigned int id; /* unique identifier. Same size as vertex_id, printed as 'r%d' */
  332. flagT seen:1; /* used to perform operations only once */
  333. flagT tested:1; /* True when ridge is tested for convexity by centrum or opposite vertices */
  334. flagT nonconvex:1; /* True if getmergeset detected a non-convex neighbor
  335. only one ridge between neighbors may have nonconvex */
  336. flagT mergevertex:1; /* True if pending qh_appendvertexmerge due to
  337. qh_maybe_duplicateridge or qh_maybe_duplicateridges
  338. disables check for duplicate vertices in qh_checkfacet */
  339. flagT mergevertex2:1; /* True if qh_drop_mergevertex of MRGvertices, printed but not used */
  340. flagT simplicialtop:1; /* True if top was simplicial (original vertices) */
  341. flagT simplicialbot:1; /* True if bottom was simplicial (original vertices)
  342. use qh_test_centrum_merge if top and bot, need to retest since centrum may change */
  343. };
  344. /*-<a href="qh-poly_r.htm#TOC"
  345. >--------------------------------</a><a name="vertexT">-</a>
  346. vertexT
  347. defines a vertex
  348. topological information:
  349. next,previous doubly-linked list of all vertices
  350. neighbors set of adjacent facets (only if qh.VERTEXneighbors)
  351. geometric information:
  352. point array of DIM3 coordinates
  353. */
  354. /* QhullVertex.cpp -- Update static initializer list for s_empty_vertex if add or remove fields */
  355. struct vertexT {
  356. vertexT *next; /* next vertex in vertex_list or vertex_tail */
  357. vertexT *previous; /* previous vertex in vertex_list or NULL, for C++ interface */
  358. pointT *point; /* hull_dim coordinates (coordT) */
  359. setT *neighbors; /* neighboring facets of vertex, qh_vertexneighbors()
  360. initialized in io_r.c or after first merge
  361. qh_update_vertices for qh_addpoint or qh_triangulate
  362. updated by merges
  363. qh_order_vertexneighbors by 2-d (orientation) 3-d (adjacency), n-d (f.visitid,id) */
  364. unsigned int id; /* unique identifier, 1..qh.vertex_id, 0 for sentinel, printed as 'r%d' */
  365. unsigned int visitid; /* for use with qh.vertex_visit, size must match */
  366. flagT seen:1; /* used to perform operations only once */
  367. flagT seen2:1; /* another seen flag */
  368. flagT deleted:1; /* vertex will be deleted via qh.del_vertices */
  369. flagT delridge:1; /* vertex belonged to a deleted ridge, cleared by qh_reducevertices */
  370. flagT newfacet:1; /* true if vertex is in a new facet
  371. vertex is on qh.newvertex_list and it has a facet on qh.newfacet_list
  372. or vertex is on qh.newvertex_list due to qh_newvertices while merging
  373. cleared by qh_resetlists */
  374. flagT partitioned:1; /* true if deleted vertex has been partitioned */
  375. };
  376. /*======= -global variables -qh ============================*/
  377. /*-<a href="qh-globa_r.htm#TOC"
  378. >--------------------------------</a><a name="qh">-</a>
  379. qhT
  380. All global variables for qhull are in qhT. It includes qhmemT, qhstatT, and rbox globals
  381. This version of Qhull is reentrant, but it is not thread-safe.
  382. Do not run separate threads on the same instance of qhT.
  383. QHULL_LIB_CHECK checks that a program and the corresponding
  384. qhull library were built with the same type of header files.
  385. QHULL_LIB_TYPE is QHULL_NON_REENTRANT, QHULL_QH_POINTER, or QHULL_REENTRANT
  386. */
  387. #define QHULL_NON_REENTRANT 0
  388. #define QHULL_QH_POINTER 1
  389. #define QHULL_REENTRANT 2
  390. #define QHULL_LIB_TYPE QHULL_REENTRANT
  391. #define QHULL_LIB_CHECK qh_lib_check(QHULL_LIB_TYPE, sizeof(qhT), sizeof(vertexT), sizeof(ridgeT), sizeof(facetT), sizeof(setT), sizeof(qhmemT));
  392. #define QHULL_LIB_CHECK_RBOX qh_lib_check(QHULL_LIB_TYPE, sizeof(qhT), sizeof(vertexT), sizeof(ridgeT), sizeof(facetT), 0, 0);
  393. struct qhT {
  394. /*-<a href="qh-globa_r.htm#TOC"
  395. >--------------------------------</a><a name="qh-const">-</a>
  396. qh constants
  397. configuration flags and constants for Qhull
  398. notes:
  399. The user configures Qhull by defining flags. They are
  400. copied into qh by qh_setflags(). qh-quick_r.htm#options defines the flags.
  401. */
  402. boolT ALLpoints; /* true 'Qs' if search all points for initial simplex */
  403. boolT ALLOWshort; /* true 'Qa' allow input with fewer or more points than coordinates */
  404. boolT ALLOWwarning; /* true 'Qw' if allow option warnings */
  405. boolT ALLOWwide; /* true 'Q12' if allow wide facets and wide dupridges, c.f. qh_WIDEmaxoutside */
  406. boolT ANGLEmerge; /* true 'Q1' if sort potential merges by type/angle instead of type/distance */
  407. boolT APPROXhull; /* true 'Wn' if MINoutside set */
  408. realT MINoutside; /* Minimum distance for an outside point ('Wn' or 2*qh.MINvisible) */
  409. boolT ANNOTATEoutput; /* true 'Ta' if annotate output with message codes */
  410. boolT ATinfinity; /* true 'Qz' if point num_points-1 is "at-infinity"
  411. for improving precision in Delaunay triangulations */
  412. boolT AVOIDold; /* true 'Q4' if avoid old->new merges */
  413. boolT BESToutside; /* true 'Qf' if partition points into best outsideset */
  414. boolT CDDinput; /* true 'Pc' if input uses CDD format (1.0/offset first) */
  415. boolT CDDoutput; /* true 'PC' if print normals in CDD format (offset first) */
  416. boolT CHECKduplicates; /* true 'Q15' if qh_maybe_duplicateridges after each qh_mergefacet */
  417. boolT CHECKfrequently; /* true 'Tc' if checking frequently */
  418. realT premerge_cos; /* 'A-n' cos_max when pre merging */
  419. realT postmerge_cos; /* 'An' cos_max when post merging */
  420. boolT DELAUNAY; /* true 'd' or 'v' if computing DELAUNAY triangulation */
  421. boolT DOintersections; /* true 'Gh' if print hyperplane intersections */
  422. int DROPdim; /* drops dim 'GDn' for 4-d -> 3-d output */
  423. boolT FLUSHprint; /* true 'Tf' if flush after qh_fprintf for segfaults */
  424. boolT FORCEoutput; /* true 'Po' if forcing output despite degeneracies */
  425. int GOODpoint; /* 'QGn' or 'QG-n' (n+1, n-1), good facet if visible from point n (or not) */
  426. pointT *GOODpointp; /* the actual point */
  427. boolT GOODthreshold; /* true 'Pd/PD' if qh.lower_threshold/upper_threshold defined
  428. set if qh.UPPERdelaunay (qh_initbuild)
  429. false if qh.SPLITthreshold */
  430. int GOODvertex; /* 'QVn' or 'QV-n' (n+1, n-1), good facet if vertex for point n (or not) */
  431. pointT *GOODvertexp; /* the actual point */
  432. boolT HALFspace; /* true 'Hn,n,n' if halfspace intersection */
  433. boolT ISqhullQh; /* Set by Qhull.cpp on initialization */
  434. int IStracing; /* 'Tn' trace execution, 0=none, 1=least, 4=most, -1=events */
  435. int KEEParea; /* 'PAn' number of largest facets to keep */
  436. boolT KEEPcoplanar; /* true 'Qc' if keeping nearest facet for coplanar points */
  437. boolT KEEPinside; /* true 'Qi' if keeping nearest facet for inside points
  438. set automatically if 'd Qc' */
  439. int KEEPmerge; /* 'PMn' number of facets to keep with most merges */
  440. realT KEEPminArea; /* 'PFn' minimum facet area to keep */
  441. realT MAXcoplanar; /* 'Un' max distance below a facet to be coplanar*/
  442. int MAXwide; /* 'QWn' max ratio for wide facet, otherwise error unless Q12-allow-wide */
  443. boolT MERGEexact; /* true 'Qx' if exact merges (concave, degen, dupridge, flipped)
  444. tested by qh_checkzero and qh_test_*_merge */
  445. boolT MERGEindependent; /* true if merging independent sets of coplanar facets. 'Q2' disables */
  446. boolT MERGING; /* true if exact-, pre- or post-merging, with angle and centrum tests */
  447. realT premerge_centrum; /* 'C-n' centrum_radius when pre merging. Default is round-off */
  448. realT postmerge_centrum; /* 'Cn' centrum_radius when post merging. Default is round-off */
  449. boolT MERGEpinched; /* true 'Q14' if merging pinched vertices due to dupridge */
  450. boolT MERGEvertices; /* true if merging redundant vertices, 'Q3' disables or qh.hull_dim > qh_DIMmergeVertex */
  451. realT MINvisible; /* 'Vn' min. distance for a facet to be visible */
  452. boolT NOnarrow; /* true 'Q10' if no special processing for narrow distributions */
  453. boolT NOnearinside; /* true 'Q8' if ignore near-inside points when partitioning, qh_check_points may fail */
  454. boolT NOpremerge; /* true 'Q0' if no defaults for C-0 or Qx */
  455. boolT ONLYgood; /* true 'Qg' if process points with good visible or horizon facets */
  456. boolT ONLYmax; /* true 'Qm' if only process points that increase max_outside */
  457. boolT PICKfurthest; /* true 'Q9' if process furthest of furthest points*/
  458. boolT POSTmerge; /* true if merging after buildhull ('Cn' or 'An') */
  459. boolT PREmerge; /* true if merging during buildhull ('C-n' or 'A-n') */
  460. /* NOTE: some of these names are similar to qh_PRINT names */
  461. boolT PRINTcentrums; /* true 'Gc' if printing centrums */
  462. boolT PRINTcoplanar; /* true 'Gp' if printing coplanar points */
  463. int PRINTdim; /* print dimension for Geomview output */
  464. boolT PRINTdots; /* true 'Ga' if printing all points as dots */
  465. boolT PRINTgood; /* true 'Pg' if printing good facets
  466. PGood set if 'd', 'PAn', 'PFn', 'PMn', 'QGn', 'QG-n', 'QVn', or 'QV-n' */
  467. boolT PRINTinner; /* true 'Gi' if printing inner planes */
  468. boolT PRINTneighbors; /* true 'PG' if printing neighbors of good facets */
  469. boolT PRINTnoplanes; /* true 'Gn' if printing no planes */
  470. boolT PRINToptions1st; /* true 'FO' if printing options to stderr */
  471. boolT PRINTouter; /* true 'Go' if printing outer planes */
  472. boolT PRINTprecision; /* false 'Pp' if not reporting precision problems */
  473. qh_PRINT PRINTout[qh_PRINTEND]; /* list of output formats to print */
  474. boolT PRINTridges; /* true 'Gr' if print ridges */
  475. boolT PRINTspheres; /* true 'Gv' if print vertices as spheres */
  476. boolT PRINTstatistics; /* true 'Ts' if printing statistics to stderr */
  477. boolT PRINTsummary; /* true 's' if printing summary to stderr */
  478. boolT PRINTtransparent; /* true 'Gt' if print transparent outer ridges */
  479. boolT PROJECTdelaunay; /* true if DELAUNAY, no readpoints() and
  480. need projectinput() for Delaunay in qh_init_B */
  481. int PROJECTinput; /* number of projected dimensions 'bn:0Bn:0' */
  482. boolT RANDOMdist; /* true 'Rn' if randomly change distplane and setfacetplane */
  483. realT RANDOMfactor; /* maximum random perturbation */
  484. realT RANDOMa; /* qh_randomfactor is randr * RANDOMa + RANDOMb */
  485. realT RANDOMb;
  486. boolT RANDOMoutside; /* true 'Qr' if select a random outside point */
  487. int REPORTfreq; /* 'TFn' buildtracing reports every n facets */
  488. int REPORTfreq2; /* tracemerging reports every REPORTfreq/2 facets */
  489. int RERUN; /* 'TRn' rerun qhull n times (qh.build_cnt) */
  490. int ROTATErandom; /* 'QRn' n<-1 random seed, n==-1 time is seed, n==0 random rotation by time, n>0 rotate input */
  491. boolT SCALEinput; /* true 'Qbk' if scaling input */
  492. boolT SCALElast; /* true 'Qbb' if scale last coord to max prev coord */
  493. boolT SETroundoff; /* true 'En' if qh.DISTround is predefined */
  494. boolT SKIPcheckmax; /* true 'Q5' if skip qh_check_maxout, qh_check_points may fail */
  495. boolT SKIPconvex; /* true 'Q6' if skip convexity testing during pre-merge */
  496. boolT SPLITthresholds; /* true 'Pd/PD' if upper_/lower_threshold defines a region
  497. else qh.GOODthresholds
  498. set if qh.DELAUNAY (qh_initbuild)
  499. used only for printing (!for qh.ONLYgood) */
  500. int STOPadd; /* 'TAn' 1+n for stop after adding n vertices */
  501. int STOPcone; /* 'TCn' 1+n for stopping after cone for point n */
  502. /* also used by qh_build_withresart for err exit*/
  503. int STOPpoint; /* 'TVn' 'TV-n' 1+n for stopping after/before(-)
  504. adding point n */
  505. int TESTpoints; /* 'QTn' num of test points after qh.num_points. Test points always coplanar. */
  506. boolT TESTvneighbors; /* true 'Qv' if test vertex neighbors at end */
  507. int TRACElevel; /* 'Tn' conditional IStracing level */
  508. int TRACElastrun; /* qh.TRACElevel applies to last qh.RERUN */
  509. int TRACEpoint; /* 'TPn' start tracing when point n is a vertex, use qh_IDunknown (-1) after qh_buildhull and qh_postmerge */
  510. realT TRACEdist; /* 'TWn' start tracing when merge distance too big */
  511. int TRACEmerge; /* 'TMn' start tracing before this merge */
  512. boolT TRIangulate; /* true 'Qt' if triangulate non-simplicial facets */
  513. boolT TRInormals; /* true 'Q11' if triangulate duplicates ->normal and ->center (sets Qt) */
  514. boolT UPPERdelaunay; /* true 'Qu' if computing furthest-site Delaunay */
  515. boolT USEstdout; /* true 'Tz' if using stdout instead of stderr */
  516. boolT VERIFYoutput; /* true 'Tv' if verify output at end of qhull */
  517. boolT VIRTUALmemory; /* true 'Q7' if depth-first processing in buildhull */
  518. boolT VORONOI; /* true 'v' if computing Voronoi diagram, also sets qh.DELAUNAY */
  519. /*--------input constants ---------*/
  520. realT AREAfactor; /* 1/(hull_dim-1)! for converting det's to area */
  521. boolT DOcheckmax; /* true if calling qh_check_maxout (!qh.SKIPcheckmax && qh.MERGING) */
  522. char *feasible_string; /* feasible point 'Hn,n,n' for halfspace intersection */
  523. coordT *feasible_point; /* as coordinates, both malloc'd */
  524. boolT GETarea; /* true 'Fa', 'FA', 'FS', 'PAn', 'PFn' if compute facet area/Voronoi volume in io_r.c */
  525. boolT KEEPnearinside; /* true if near-inside points in coplanarset */
  526. int hull_dim; /* dimension of hull, set by initbuffers */
  527. int input_dim; /* dimension of input, set by initbuffers */
  528. int num_points; /* number of input points */
  529. pointT *first_point; /* array of input points, see POINTSmalloc */
  530. boolT POINTSmalloc; /* true if qh.first_point/num_points allocated */
  531. pointT *input_points; /* copy of original qh.first_point for input points for qh_joggleinput */
  532. boolT input_malloc; /* true if qh.input_points malloc'd */
  533. char qhull_command[256];/* command line that invoked this program */
  534. int qhull_commandsiz2; /* size of qhull_command at qh_clear_outputflags */
  535. char rbox_command[256]; /* command line that produced the input points */
  536. char qhull_options[512];/* descriptive list of options */
  537. int qhull_optionlen; /* length of last line */
  538. int qhull_optionsiz; /* size of qhull_options at qh_build_withrestart */
  539. int qhull_optionsiz2; /* size of qhull_options at qh_clear_outputflags */
  540. int run_id; /* non-zero, random identifier for this instance of qhull */
  541. boolT VERTEXneighbors; /* true if maintaining vertex neighbors */
  542. boolT ZEROcentrum; /* true if 'C-0' or 'C-0 Qx' and not post-merging or 'A-n'. Sets ZEROall_ok */
  543. realT *upper_threshold; /* don't print if facet->normal[k]>=upper_threshold[k]
  544. must set either GOODthreshold or SPLITthreshold
  545. if qh.DELAUNAY, default is 0.0 for upper envelope (qh_initbuild) */
  546. realT *lower_threshold; /* don't print if facet->normal[k] <=lower_threshold[k] */
  547. realT *upper_bound; /* scale point[k] to new upper bound */
  548. realT *lower_bound; /* scale point[k] to new lower bound
  549. project if both upper_ and lower_bound == 0 */
  550. /*-<a href="qh-globa_r.htm#TOC"
  551. >--------------------------------</a><a name="qh-prec">-</a>
  552. qh precision constants
  553. precision constants for Qhull
  554. notes:
  555. qh_detroundoff [geom2_r.c] computes the maximum roundoff error for distance
  556. and other computations. It also sets default values for the
  557. qh constants above.
  558. */
  559. realT ANGLEround; /* max round off error for angles */
  560. realT centrum_radius; /* max centrum radius for convexity ('Cn' + 2*qh.DISTround) */
  561. realT cos_max; /* max cosine for convexity (roundoff added) */
  562. realT DISTround; /* max round off error for distances, qh.SETroundoff ('En') overrides qh_distround */
  563. realT MAXabs_coord; /* max absolute coordinate */
  564. realT MAXlastcoord; /* max last coordinate for qh_scalelast */
  565. realT MAXoutside; /* max target for qh.max_outside/f.maxoutside, base for qh_RATIO...
  566. recomputed at qh_addpoint, unrelated to qh_MAXoutside */
  567. realT MAXsumcoord; /* max sum of coordinates */
  568. realT MAXwidth; /* max rectilinear width of point coordinates */
  569. realT MINdenom_1; /* min. abs. value for 1/x */
  570. realT MINdenom; /* use divzero if denominator < MINdenom */
  571. realT MINdenom_1_2; /* min. abs. val for 1/x that allows normalization */
  572. realT MINdenom_2; /* use divzero if denominator < MINdenom_2 */
  573. realT MINlastcoord; /* min. last coordinate for qh_scalelast */
  574. realT *NEARzero; /* hull_dim array for near zero in gausselim */
  575. realT NEARinside; /* keep points for qh_check_maxout if close to facet */
  576. realT ONEmerge; /* max distance for merging simplicial facets */
  577. realT outside_err; /* application's epsilon for coplanar points
  578. qh_check_bestdist() qh_check_points() reports error if point outside */
  579. realT WIDEfacet; /* size of wide facet for skipping ridge in
  580. area computation and locking centrum */
  581. boolT NARROWhull; /* set in qh_initialhull if angle < qh_MAXnarrow */
  582. /*-<a href="qh-globa_r.htm#TOC"
  583. >--------------------------------</a><a name="qh-codetern">-</a>
  584. qh internal constants
  585. internal constants for Qhull
  586. */
  587. char qhull[sizeof("qhull")]; /* "qhull" for checking ownership while debugging */
  588. jmp_buf errexit; /* exit label for qh_errexit, defined by setjmp() and NOerrexit */
  589. char jmpXtra[40]; /* extra bytes in case jmp_buf is defined wrong by compiler */
  590. jmp_buf restartexit; /* restart label for qh_errexit, defined by setjmp() and ALLOWrestart */
  591. char jmpXtra2[40]; /* extra bytes in case jmp_buf is defined wrong by compiler*/
  592. FILE * fin; /* pointer to input file, init by qh_initqhull_start2 */
  593. FILE * fout; /* pointer to output file */
  594. FILE * ferr; /* pointer to error file */
  595. pointT *interior_point; /* center point of the initial simplex*/
  596. int normal_size; /* size in bytes for facet normals and point coords */
  597. int center_size; /* size in bytes for Voronoi centers */
  598. int TEMPsize; /* size for small, temporary sets (in quick mem) */
  599. /*-<a href="qh-globa_r.htm#TOC"
  600. >--------------------------------</a><a name="qh-lists">-</a>
  601. qh facet and vertex lists
  602. defines lists of facets, new facets, visible facets, vertices, and
  603. new vertices. Includes counts, next ids, and trace ids.
  604. see:
  605. qh_resetlists()
  606. */
  607. facetT *facet_list; /* first facet */
  608. facetT *facet_tail; /* end of facet_list (dummy facet with id 0 and next==NULL) */
  609. facetT *facet_next; /* next facet for buildhull()
  610. previous facets do not have outside sets
  611. NARROWhull: previous facets may have coplanar outside sets for qh_outcoplanar */
  612. facetT *newfacet_list; /* list of new facets to end of facet_list
  613. qh_postmerge sets newfacet_list to facet_list */
  614. facetT *visible_list; /* list of visible facets preceding newfacet_list,
  615. end of visible list if !facet->visible, same as newfacet_list
  616. qh_findhorizon sets visible_list at end of facet_list
  617. qh_willdelete prepends to visible_list
  618. qh_triangulate appends mirror facets to visible_list at end of facet_list
  619. qh_postmerge sets visible_list to facet_list
  620. qh_deletevisible deletes the visible facets */
  621. int num_visible; /* current number of visible facets */
  622. unsigned int tracefacet_id; /* set at init, then can print whenever */
  623. facetT *tracefacet; /* set in newfacet/mergefacet, undone in delfacet and qh_errexit */
  624. unsigned int traceridge_id; /* set at init, then can print whenever */
  625. ridgeT *traceridge; /* set in newridge, undone in delridge, errexit, errexit2, makenew_nonsimplicial, mergecycle_ridges */
  626. unsigned int tracevertex_id; /* set at buildtracing, can print whenever */
  627. vertexT *tracevertex; /* set in newvertex, undone in delvertex and qh_errexit */
  628. vertexT *vertex_list; /* list of all vertices, to vertex_tail */
  629. vertexT *vertex_tail; /* end of vertex_list (dummy vertex with ID 0, next NULL) */
  630. vertexT *newvertex_list; /* list of vertices in newfacet_list, to vertex_tail
  631. all vertices have 'newfacet' set */
  632. int num_facets; /* number of facets in facet_list
  633. includes visible faces (num_visible) */
  634. int num_vertices; /* number of vertices in facet_list */
  635. int num_outside; /* number of points in outsidesets (for tracing and RANDOMoutside)
  636. includes coplanar outsideset points for NARROWhull/qh_outcoplanar() */
  637. int num_good; /* number of good facets (after qh_findgood_all or qh_markkeep) */
  638. unsigned int facet_id; /* ID of next, new facet from newfacet() */
  639. unsigned int ridge_id; /* ID of next, new ridge from newridge() */
  640. unsigned int vertex_id; /* ID of next, new vertex from newvertex() */
  641. unsigned int first_newfacet; /* ID of first_newfacet for qh_buildcone, or 0 if none */
  642. /*-<a href="qh-globa_r.htm#TOC"
  643. >--------------------------------</a><a name="qh-var">-</a>
  644. qh global variables
  645. defines minimum and maximum distances, next visit ids, several flags,
  646. and other global variables.
  647. initialize in qh_initbuild or qh_maxmin if used in qh_buildhull
  648. */
  649. unsigned long hulltime; /* ignore time to set up input and randomize */
  650. /* use 'unsigned long' to avoid wrap-around errors */
  651. boolT ALLOWrestart; /* true if qh_joggle_restart can use qh.restartexit */
  652. int build_cnt; /* number of calls to qh_initbuild */
  653. qh_CENTER CENTERtype; /* current type of facet->center, qh_CENTER */
  654. int furthest_id; /* pointid of furthest point, for tracing */
  655. int last_errcode; /* last errcode from qh_fprintf, reset in qh_build_withrestart */
  656. facetT *GOODclosest; /* closest facet to GOODthreshold in qh_findgood */
  657. pointT *coplanar_apex; /* last apex declared a coplanar point by qh_getpinchedmerges, prevents infinite loop */
  658. boolT hasAreaVolume; /* true if totarea, totvol was defined by qh_getarea */
  659. boolT hasTriangulation; /* true if triangulation created by qh_triangulate */
  660. boolT isRenameVertex; /* true during qh_merge_pinchedvertices, disables duplicate ridge vertices in qh_checkfacet */
  661. realT JOGGLEmax; /* set 'QJn' if randomly joggle input. 'QJ'/'QJ0.0' sets default (qh_detjoggle) */
  662. boolT maxoutdone; /* set qh_check_maxout(), cleared by qh_addpoint() */
  663. realT max_outside; /* maximum distance from a point to a facet,
  664. before roundoff, not simplicial vertices
  665. actual outer plane is +DISTround and
  666. computed outer plane is +2*DISTround */
  667. realT max_vertex; /* maximum distance (>0) from vertex to a facet,
  668. before roundoff, due to a merge */
  669. realT min_vertex; /* minimum distance (<0) from vertex to a facet,
  670. before roundoff, due to a merge
  671. if qh.JOGGLEmax, qh_makenewplanes sets it
  672. recomputed if qh.DOcheckmax, default -qh.DISTround */
  673. boolT NEWfacets; /* true while visible facets invalid due to new or merge
  674. from qh_makecone/qh_attachnewfacets to qh_resetlists */
  675. boolT NEWtentative; /* true while new facets are tentative due to !qh.IGNOREpinched or qh.ONLYgood
  676. from qh_makecone to qh_attachnewfacets */
  677. boolT findbestnew; /* true if partitioning calls qh_findbestnew */
  678. boolT findbest_notsharp; /* true if new facets are at least 90 degrees */
  679. boolT NOerrexit; /* true if qh.errexit is not available, cleared after setjmp. See qh.ERREXITcalled */
  680. realT PRINTcradius; /* radius for printing centrums */
  681. realT PRINTradius; /* radius for printing vertex spheres and points */
  682. boolT POSTmerging; /* true when post merging */
  683. int printoutvar; /* temporary variable for qh_printbegin, etc. */
  684. int printoutnum; /* number of facets printed */
  685. unsigned int repart_facetid; /* previous facetid to prevent recursive qh_partitioncoplanar+qh_partitionpoint */
  686. int retry_addpoint; /* number of retries of qh_addpoint due to merging pinched vertices */
  687. boolT QHULLfinished; /* True after qhull() is finished */
  688. realT totarea; /* 'FA': total facet area computed by qh_getarea, hasAreaVolume */
  689. realT totvol; /* 'FA': total volume computed by qh_getarea, hasAreaVolume */
  690. unsigned int visit_id; /* unique ID for searching neighborhoods, */
  691. unsigned int vertex_visit; /* unique ID for searching vertices, reset with qh_buildtracing */
  692. boolT WAScoplanar; /* True if qh_partitioncoplanar (qh_check_maxout) */
  693. boolT ZEROall_ok; /* True if qh_checkzero always succeeds */
  694. /*-<a href="qh-globa_r.htm#TOC"
  695. >--------------------------------</a><a name="qh-set">-</a>
  696. qh global sets
  697. defines sets for merging, initial simplex, hashing, extra input points,
  698. and deleted vertices
  699. */
  700. setT *facet_mergeset; /* temporary set of merges to be done */
  701. setT *degen_mergeset; /* temporary set of degenerate and redundant merges */
  702. setT *vertex_mergeset; /* temporary set of vertex merges */
  703. setT *hash_table; /* hash table for matching ridges in qh_matchfacets
  704. size is setsize() */
  705. setT *other_points; /* additional points */
  706. setT *del_vertices; /* vertices to partition and delete with visible
  707. facets. v.deleted is set for checkfacet */
  708. /*-<a href="qh-globa_r.htm#TOC"
  709. >--------------------------------</a><a name="qh-buf">-</a>
  710. qh global buffers
  711. defines buffers for maxtrix operations, input, and error messages
  712. */
  713. coordT *gm_matrix; /* (dim+1)Xdim matrix for geom_r.c */
  714. coordT **gm_row; /* array of gm_matrix rows */
  715. char* line; /* malloc'd input line of maxline+1 chars */
  716. int maxline;
  717. coordT *half_space; /* malloc'd input array for halfspace (qh.normal_size+coordT) */
  718. coordT *temp_malloc; /* malloc'd input array for points */
  719. /*-<a href="qh-globa_r.htm#TOC"
  720. >--------------------------------</a><a name="qh-static">-</a>
  721. qh static variables
  722. defines static variables for individual functions
  723. notes:
  724. do not use 'static' within a function. Multiple instances of qhull
  725. may exist.
  726. do not assume zero initialization, 'QPn' may cause a restart
  727. */
  728. boolT ERREXITcalled; /* true during qh_errexit (prevents duplicate calls). see qh.NOerrexit */
  729. boolT firstcentrum; /* for qh_printcentrum */
  730. boolT old_randomdist; /* save RANDOMdist flag during io, tracing, or statistics */
  731. setT *coplanarfacetset; /* set of coplanar facets for searching qh_findbesthorizon() */
  732. realT last_low; /* qh_scalelast parameters for qh_setdelaunay */
  733. realT last_high;
  734. realT last_newhigh;
  735. realT lastcpu; /* for qh_buildtracing */
  736. int lastfacets; /* last qh.num_facets */
  737. int lastmerges; /* last zzval_(Ztotmerge) */
  738. int lastplanes; /* last zzval_(Zsetplane) */
  739. int lastdist; /* last zzval_(Zdistplane) */
  740. unsigned int lastreport; /* last qh.facet_id */
  741. int mergereport; /* for qh_tracemerging */
  742. setT *old_tempstack; /* for saving qh->qhmem.tempstack in save_qhull */
  743. int ridgeoutnum; /* number of ridges for 4OFF output (qh_printbegin,etc) */
  744. /*-<a href="qh-globa_r.htm#TOC"
  745. >--------------------------------</a><a name="qh-const">-</a>
  746. qh memory management, rbox globals, and statistics
  747. Replaces global data structures defined for libqhull
  748. */
  749. int last_random; /* Last random number from qh_rand (random_r.c) */
  750. jmp_buf rbox_errexit; /* errexit from rboxlib_r.c, defined by qh_rboxpoints() only */
  751. char jmpXtra3[40]; /* extra bytes in case jmp_buf is defined wrong by compiler */
  752. int rbox_isinteger;
  753. double rbox_out_offset;
  754. void * cpp_object; /* C++ pointer. Currently used by RboxPoints.qh_fprintf_rbox */
  755. void * cpp_other; /* C++ pointer. Reserved for other users */
  756. void * cpp_user; /* C++ pointer. Currently used by QhullUser.qh_fprintf */
  757. /* Last, otherwise zero'd by qh_initqhull_start2 (global_r.c */
  758. qhmemT qhmem; /* Qhull managed memory (mem_r.h) */
  759. /* After qhmem because its size depends on the number of statistics */
  760. qhstatT qhstat; /* Qhull statistics (stat_r.h) */
  761. };
  762. /*=========== -macros- =========================*/
  763. /*-<a href="qh-poly_r.htm#TOC"
  764. >--------------------------------</a><a name="otherfacet_">-</a>
  765. otherfacet_(ridge, facet)
  766. return neighboring facet for a ridge in facet
  767. */
  768. #define otherfacet_(ridge, facet) \
  769. (((ridge)->top == (facet)) ? (ridge)->bottom : (ridge)->top)
  770. /*-<a href="qh-poly_r.htm#TOC"
  771. >--------------------------------</a><a name="getid_">-</a>
  772. getid_(p)
  773. return int ID for facet, ridge, or vertex
  774. return qh_IDunknown(-1) if NULL
  775. return 0 if facet_tail or vertex_tail
  776. */
  777. #define getid_(p) ((p) ? (int)((p)->id) : qh_IDunknown)
  778. /*============== FORALL macros ===================*/
  779. /*-<a href="qh-poly_r.htm#TOC"
  780. >--------------------------------</a><a name="FORALLfacets">-</a>
  781. FORALLfacets { ... }
  782. assign 'facet' to each facet in qh.facet_list
  783. notes:
  784. uses 'facetT *facet;'
  785. assumes last facet is a sentinel
  786. assumes qh defined
  787. see:
  788. FORALLfacet_( facetlist )
  789. */
  790. #define FORALLfacets for (facet=qh->facet_list;facet && facet->next;facet=facet->next)
  791. /*-<a href="qh-poly_r.htm#TOC"
  792. >--------------------------------</a><a name="FORALLpoints">-</a>
  793. FORALLpoints { ... }
  794. assign 'point' to each point in qh.first_point, qh.num_points
  795. notes:
  796. assumes qh defined
  797. declare:
  798. coordT *point, *pointtemp;
  799. */
  800. #define FORALLpoints FORALLpoint_(qh, qh->first_point, qh->num_points)
  801. /*-<a href="qh-poly_r.htm#TOC"
  802. >--------------------------------</a><a name="FORALLpoint_">-</a>
  803. FORALLpoint_(qh, points, num) { ... }
  804. assign 'point' to each point in points array of num points
  805. declare:
  806. coordT *point, *pointtemp;
  807. */
  808. #define FORALLpoint_(qh, points, num) for (point=(points), \
  809. pointtemp= (points)+qh->hull_dim*(num); point < pointtemp; point += qh->hull_dim)
  810. /*-<a href="qh-poly_r.htm#TOC"
  811. >--------------------------------</a><a name="FORALLvertices">-</a>
  812. FORALLvertices { ... }
  813. assign 'vertex' to each vertex in qh.vertex_list
  814. declare:
  815. vertexT *vertex;
  816. notes:
  817. assumes qh.vertex_list terminated by NULL or a sentinel (v.next==NULL)
  818. assumes qh defined
  819. */
  820. #define FORALLvertices for (vertex=qh->vertex_list;vertex && vertex->next;vertex= vertex->next)
  821. /*-<a href="qh-poly_r.htm#TOC"
  822. >--------------------------------</a><a name="FOREACHfacet_">-</a>
  823. FOREACHfacet_( facets ) { ... }
  824. assign 'facet' to each facet in facets
  825. declare:
  826. facetT *facet, **facetp;
  827. notes:
  828. assumes set is not modified
  829. see:
  830. <a href="qset_r.h#FOREACHsetelement_">FOREACHsetelement_</a>
  831. */
  832. #define FOREACHfacet_(facets) FOREACHsetelement_(facetT, facets, facet)
  833. /*-<a href="qh-poly_r.htm#TOC"
  834. >--------------------------------</a><a name="FOREACHneighbor_">-</a>
  835. FOREACHneighbor_( facet ) { ... }
  836. assign 'neighbor' to each neighbor in facet->neighbors
  837. FOREACHneighbor_( vertex ) { ... }
  838. assign 'neighbor' to each neighbor in vertex->neighbors
  839. declare:
  840. facetT *neighbor, **neighborp;
  841. notes:
  842. assumes set is not modified
  843. see:
  844. <a href="qset_r.h#FOREACHsetelement_">FOREACHsetelement_</a>
  845. */
  846. #define FOREACHneighbor_(facet) FOREACHsetelement_(facetT, facet->neighbors, neighbor)
  847. /*-<a href="qh-poly_r.htm#TOC"
  848. >--------------------------------</a><a name="FOREACHpoint_">-</a>
  849. FOREACHpoint_( points ) { ... }
  850. assign 'point' to each point in points set
  851. declare:
  852. pointT *point, **pointp;
  853. notes:
  854. assumes set is not modified
  855. see:
  856. <a href="qset_r.h#FOREACHsetelement_">FOREACHsetelement_</a>
  857. */
  858. #define FOREACHpoint_(points) FOREACHsetelement_(pointT, points, point)
  859. /*-<a href="qh-poly_r.htm#TOC"
  860. >--------------------------------</a><a name="FOREACHridge_">-</a>
  861. FOREACHridge_( ridges ) { ... }
  862. assign 'ridge' to each ridge in ridges set
  863. declare:
  864. ridgeT *ridge, **ridgep;
  865. notes:
  866. assumes set is not modified
  867. see:
  868. <a href="qset_r.h#FOREACHsetelement_">FOREACHsetelement_</a>
  869. */
  870. #define FOREACHridge_(ridges) FOREACHsetelement_(ridgeT, ridges, ridge)
  871. /*-<a href="qh-poly_r.htm#TOC"
  872. >--------------------------------</a><a name="FOREACHvertex_">-</a>
  873. FOREACHvertex_( vertices ) { ... }
  874. assign 'vertex' to each vertex in vertices set
  875. declare:
  876. vertexT *vertex, **vertexp;
  877. notes:
  878. assumes set is not modified
  879. see:
  880. <a href="qset_r.h#FOREACHsetelement_">FOREACHsetelement_</a>
  881. */
  882. #define FOREACHvertex_(vertices) FOREACHsetelement_(vertexT, vertices,vertex)
  883. /*-<a href="qh-poly_r.htm#TOC"
  884. >--------------------------------</a><a name="FOREACHfacet_i_">-</a>
  885. FOREACHfacet_i_(qh, facets ) { ... }
  886. assign 'facet' and 'facet_i' for each facet in facets set
  887. declare:
  888. facetT *facet;
  889. int facet_n, facet_i;
  890. see:
  891. <a href="qset_r.h#FOREACHsetelement_i_">FOREACHsetelement_i_</a>
  892. */
  893. #define FOREACHfacet_i_(qh, facets) FOREACHsetelement_i_(qh, facetT, facets, facet)
  894. /*-<a href="qh-poly_r.htm#TOC"
  895. >--------------------------------</a><a name="FOREACHneighbor_i_">-</a>
  896. FOREACHneighbor_i_(qh, facet ) { ... }
  897. assign 'neighbor' and 'neighbor_i' for each neighbor in facet->neighbors
  898. declare:
  899. facetT *neighbor;
  900. int neighbor_n, neighbor_i;
  901. notes:
  902. see <a href="qset_r.h#FOREACHsetelement_i_">FOREACHsetelement_i_</a>
  903. for facet neighbors of vertex, need to define a new macro
  904. */
  905. #define FOREACHneighbor_i_(qh, facet) FOREACHsetelement_i_(qh, facetT, facet->neighbors, neighbor)
  906. /*-<a href="qh-poly_r.htm#TOC"
  907. >--------------------------------</a><a name="FOREACHpoint_i_">-</a>
  908. FOREACHpoint_i_(qh, points ) { ... }
  909. assign 'point' and 'point_i' for each point in points set
  910. declare:
  911. pointT *point;
  912. int point_n, point_i;
  913. see:
  914. <a href="qset_r.h#FOREACHsetelement_i_">FOREACHsetelement_i_</a>
  915. */
  916. #define FOREACHpoint_i_(qh, points) FOREACHsetelement_i_(qh, pointT, points, point)
  917. /*-<a href="qh-poly_r.htm#TOC"
  918. >--------------------------------</a><a name="FOREACHridge_i_">-</a>
  919. FOREACHridge_i_(qh, ridges ) { ... }
  920. assign 'ridge' and 'ridge_i' for each ridge in ridges set
  921. declare:
  922. ridgeT *ridge;
  923. int ridge_n, ridge_i;
  924. see:
  925. <a href="qset_r.h#FOREACHsetelement_i_">FOREACHsetelement_i_</a>
  926. */
  927. #define FOREACHridge_i_(qh, ridges) FOREACHsetelement_i_(qh, ridgeT, ridges, ridge)
  928. /*-<a href="qh-poly_r.htm#TOC"
  929. >--------------------------------</a><a name="FOREACHvertex_i_">-</a>
  930. FOREACHvertex_i_(qh, vertices ) { ... }
  931. assign 'vertex' and 'vertex_i' for each vertex in vertices set
  932. declare:
  933. vertexT *vertex;
  934. int vertex_n, vertex_i;
  935. see:
  936. <a href="qset_r.h#FOREACHsetelement_i_">FOREACHsetelement_i_</a>
  937. */
  938. #define FOREACHvertex_i_(qh, vertices) FOREACHsetelement_i_(qh, vertexT, vertices, vertex)
  939. #ifdef __cplusplus
  940. extern "C" {
  941. #endif
  942. /********* -libqhull_r.c prototypes (duplicated from qhull_ra.h) **********************/
  943. void qh_qhull(qhT *qh);
  944. boolT qh_addpoint(qhT *qh, pointT *furthest, facetT *facet, boolT checkdist);
  945. void qh_errexit2(qhT *qh, int exitcode, facetT *facet, facetT *otherfacet);
  946. void qh_printsummary(qhT *qh, FILE *fp);
  947. /********* -user_r.c prototypes (alphabetical) **********************/
  948. void qh_errexit(qhT *qh, int exitcode, facetT *facet, ridgeT *ridge);
  949. void qh_errprint(qhT *qh, const char* string, facetT *atfacet, facetT *otherfacet, ridgeT *atridge, vertexT *atvertex);
  950. int qh_new_qhull(qhT *qh, int dim, int numpoints, coordT *points, boolT ismalloc,
  951. char *qhull_cmd, FILE *outfile, FILE *errfile);
  952. int qh_new_qhull_feaspoint(qhT *qh, int dim, int numpoints, coordT *points, boolT ismalloc,
  953. char *qhull_cmd, FILE *outfile, FILE *errfile, coordT* feaspoint);
  954. void qh_printfacetlist(qhT *qh, facetT *facetlist, setT *facets, boolT printall);
  955. void qh_printhelp_degenerate(qhT *qh, FILE *fp);
  956. void qh_printhelp_internal(qhT *qh, FILE *fp);
  957. void qh_printhelp_narrowhull(qhT *qh, FILE *fp, realT minangle);
  958. void qh_printhelp_singular(qhT *qh, FILE *fp);
  959. void qh_printhelp_topology(qhT *qh, FILE *fp);
  960. void qh_printhelp_wide(qhT *qh, FILE *fp);
  961. void qh_user_memsizes(qhT *qh);
  962. /********* -usermem_r.c prototypes (alphabetical) **********************/
  963. void qh_exit(int exitcode);
  964. void qh_fprintf_stderr(int msgcode, const char *fmt, ... );
  965. void qh_free(void *mem);
  966. void *qh_malloc(size_t size);
  967. /********* -userprintf_r.c and userprintf_rbox_r.c prototypes **********************/
  968. void qh_fprintf(qhT *qh, FILE *fp, int msgcode, const char *fmt, ... );
  969. void qh_fprintf_rbox(qhT *qh, FILE *fp, int msgcode, const char *fmt, ... );
  970. /***** -geom_r.c/geom2_r.c/random_r.c prototypes (duplicated from geom_r.h, random_r.h) ****************/
  971. facetT *qh_findbest(qhT *qh, pointT *point, facetT *startfacet,
  972. boolT bestoutside, boolT newfacets, boolT noupper,
  973. realT *dist, boolT *isoutside, int *numpart);
  974. facetT *qh_findbestnew(qhT *qh, pointT *point, facetT *startfacet,
  975. realT *dist, boolT bestoutside, boolT *isoutside, int *numpart);
  976. boolT qh_gram_schmidt(qhT *qh, int dim, realT **rows);
  977. void qh_outerinner(qhT *qh, facetT *facet, realT *outerplane, realT *innerplane);
  978. void qh_printsummary(qhT *qh, FILE *fp);
  979. void qh_projectinput(qhT *qh);
  980. void qh_randommatrix(qhT *qh, realT *buffer, int dim, realT **row);
  981. void qh_rotateinput(qhT *qh, realT **rows);
  982. void qh_scaleinput(qhT *qh);
  983. void qh_setdelaunay(qhT *qh, int dim, int count, pointT *points);
  984. coordT *qh_sethalfspace_all(qhT *qh, int dim, int count, coordT *halfspaces, pointT *feasible);
  985. /***** -global_r.c prototypes (alphabetical) ***********************/
  986. unsigned long qh_clock(qhT *qh);
  987. void qh_checkflags(qhT *qh, char *command, char *hiddenflags);
  988. void qh_clear_outputflags(qhT *qh);
  989. void qh_freebuffers(qhT *qh);
  990. void qh_freeqhull(qhT *qh, boolT allmem);
  991. void qh_init_A(qhT *qh, FILE *infile, FILE *outfile, FILE *errfile, int argc, char *argv[]);
  992. void qh_init_B(qhT *qh, coordT *points, int numpoints, int dim, boolT ismalloc);
  993. void qh_init_qhull_command(qhT *qh, int argc, char *argv[]);
  994. void qh_initbuffers(qhT *qh, coordT *points, int numpoints, int dim, boolT ismalloc);
  995. void qh_initflags(qhT *qh, char *command);
  996. void qh_initqhull_buffers(qhT *qh);
  997. void qh_initqhull_globals(qhT *qh, coordT *points, int numpoints, int dim, boolT ismalloc);
  998. void qh_initqhull_mem(qhT *qh);
  999. void qh_initqhull_outputflags(qhT *qh);
  1000. void qh_initqhull_start(qhT *qh, FILE *infile, FILE *outfile, FILE *errfile);
  1001. void qh_initqhull_start2(qhT *qh, FILE *infile, FILE *outfile, FILE *errfile);
  1002. void qh_initthresholds(qhT *qh, char *command);
  1003. void qh_lib_check(int qhullLibraryType, int qhTsize, int vertexTsize, int ridgeTsize, int facetTsize, int setTsize, int qhmemTsize);
  1004. void qh_option(qhT *qh, const char *option, int *i, realT *r);
  1005. void qh_zero(qhT *qh, FILE *errfile);
  1006. /***** -io_r.c prototypes (duplicated from io_r.h) ***********************/
  1007. void qh_dfacet(qhT *qh, unsigned int id);
  1008. void qh_dvertex(qhT *qh, unsigned int id);
  1009. void qh_printneighborhood(qhT *qh, FILE *fp, qh_PRINT format, facetT *facetA, facetT *facetB, boolT printall);
  1010. void qh_produce_output(qhT *qh);
  1011. coordT *qh_readpoints(qhT *qh, int *numpoints, int *dimension, boolT *ismalloc);
  1012. /********* -mem_r.c prototypes (duplicated from mem_r.h) **********************/
  1013. void qh_meminit(qhT *qh, FILE *ferr);
  1014. void qh_memfreeshort(qhT *qh, int *curlong, int *totlong);
  1015. /********* -poly_r.c/poly2_r.c prototypes (duplicated from poly_r.h) **********************/
  1016. void qh_check_output(qhT *qh);
  1017. void qh_check_points(qhT *qh);
  1018. setT *qh_facetvertices(qhT *qh, facetT *facetlist, setT *facets, boolT allfacets);
  1019. facetT *qh_findbestfacet(qhT *qh, pointT *point, boolT bestoutside,
  1020. realT *bestdist, boolT *isoutside);
  1021. vertexT *qh_nearvertex(qhT *qh, facetT *facet, pointT *point, realT *bestdistp);
  1022. pointT *qh_point(qhT *qh, int id);
  1023. setT *qh_pointfacet(qhT *qh /* qh.facet_list */);
  1024. int qh_pointid(qhT *qh, pointT *point);
  1025. setT *qh_pointvertex(qhT *qh /* qh.facet_list */);
  1026. void qh_setvoronoi_all(qhT *qh);
  1027. void qh_triangulate(qhT *qh /* qh.facet_list */);
  1028. /********* -rboxlib_r.c prototypes **********************/
  1029. int qh_rboxpoints(qhT *qh, char* rbox_command);
  1030. void qh_errexit_rbox(qhT *qh, int exitcode);
  1031. /********* -stat_r.c prototypes (duplicated from stat_r.h) **********************/
  1032. void qh_collectstatistics(qhT *qh);
  1033. void qh_printallstatistics(qhT *qh, FILE *fp, const char *string);
  1034. #ifdef __cplusplus
  1035. } /* extern "C" */
  1036. #endif
  1037. #endif /* qhDEFlibqhull */