Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Triangle/Triangle.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Triangle.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: class for triangle, originally the code of Jonathan Shewchuk
33 // but heavily modified.
34 // original file header below
35 //
36 ////////////////////////////////////////////////////////////////////////////////
37 /*****************************************************************************/
38 /* */
39 /* (triangle.h) */
40 /* */
41 /* Include file for programs that call Triangle. */
42 /* */
43 /* Accompanies Triangle Version 1.6 */
44 /* July 28, 2005 */
45 /* */
46 /* Copyright 1996, 2005 */
47 /* Jonathan Richard Shewchuk */
48 /* 2360 Woolsey #H */
49 /* Berkeley, California 94705-1927 */
50 /* jrs@cs.berkeley.edu */
51 /* */
52 /*****************************************************************************/
53 #ifndef NEKTAR_MESHUTILS_TRIANGLE_DT_H
54 #define NEKTAR_MESHUTILS_TRIANGLE_DT_H
55 
56 #include <boost/shared_ptr.hpp>
57 
60 
61 namespace Nektar
62 {
63 namespace NekMeshUtils
64 {
65 
66 /* For efficiency, a variety of data structures are allocated in bulk. The */
67 /* following constants determine how many of each structure is allocated */
68 /* at once. */
69 
70 #define TRIPERBLOCK 4092 /* Number of triangles allocated at once. */
71 #define SUBSEGPERBLOCK 508 /* Number of subsegments allocated at once. */
72 #define VERTEXPERBLOCK 4092 /* Number of vertices allocated at once. */
73 #define VIRUSPERBLOCK 1020 /* Number of virus triangles allocated at once. */
74 /* Number of encroached subsegments allocated at once. */
75 #define BADSUBSEGPERBLOCK 252
76 /* Number of skinny triangles allocated at once. */
77 #define BADTRIPERBLOCK 4092
78 /* Number of flipped triangles allocated at once. */
79 #define FLIPSTACKERPERBLOCK 252
80 /* Number of splay tree nodes allocated at once. */
81 #define SPLAYNODEPERBLOCK 508
82 
83 /* The vertex types. A DEADVERTEX has been deleted entirely. An */
84 /* UNDEADVERTEX is not part of the mesh, but is written to the output */
85 /* .node file and affects the node indexing in the other output files. */
86 
87 #define INPUTVERTEX 0
88 #define SEGMENTVERTEX 1
89 #define FREEVERTEX 2
90 #define DEADVERTEX -32768
91 #define UNDEADVERTEX -32767
92 
93 /* Two constants for algorithms based on random sampling. Both constants */
94 /* have been chosen empirically to optimize their respective algorithms. */
95 
96 /* Used for the point location scheme of Mucke, Saias, and Zhu, to decide */
97 /* how large a random sample of triangles to inspect. */
98 
99 #define SAMPLEFACTOR 11
100 
101 /* Used in Fortune's sweepline Delaunay algorithm to determine what fraction */
102 /* of boundary edges should be maintained in the splay tree for point */
103 /* location on the front. */
104 
105 #define SAMPLERATE 10
106 
107 /* A number that speaks for itself, every kissable digit. */
108 
109 #define PI 3.141592653589793238462643383279502884197169399375105820974944592308
110 
111 /* Another fave. */
112 
113 #define SQUAREROOTTWO 1.4142135623730950488016887242096980785696718753769480732
114 
115 /* And here's one for those of you who are intimidated by math. */
116 
117 #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333
118 
119 /********* Mesh manipulation primitives begin here *********/
120 /** **/
121 /** **/
122 
123 /********* Primitives for triangles *********/
124 /* */
125 /* */
126 
127 /* decode() converts a pointer to an oriented triangle. The orientation is */
128 /* extracted from the two least significant bits of the pointer. */
129 
130 #define decode(ptr, otri) \
131  (otri).orient = (int)((unsigned long)(ptr) & (unsigned long)3l); \
132  (otri).tri = \
133  (triangle *)((unsigned long)(ptr) ^ (unsigned long)(otri).orient)
134 
135 /* encode() compresses an oriented triangle into a single pointer. It */
136 /* relies on the assumption that all triangles are aligned to four-byte */
137 /* boundaries, so the two least significant bits of (otri).tri are zero. */
138 
139 #define encode(otri) \
140  (triangle)((unsigned long)(otri).tri | (unsigned long)(otri).orient)
141 
142 /* The following handle manipulation primitives are all described by Guibas */
143 /* and Stolfi. However, Guibas and Stolfi use an edge-based data */
144 /* structure, whereas I use a triangle-based data structure. */
145 
146 /* sym() finds the abutting triangle, on the same edge. Note that the edge */
147 /* direction is necessarily reversed, because the handle specified by an */
148 /* oriented triangle is directed counterclockwise around the triangle. */
149 
150 #define sym(otri1, otri2) \
151  ptr = (otri1).tri[(otri1).orient]; \
152  decode(ptr, otri2);
153 
154 #define symself(otri) \
155  ptr = (otri).tri[(otri).orient]; \
156  decode(ptr, otri);
157 
158 /* lnext() finds the next edge (counterclockwise) of a triangle. */
159 
160 #define lnext(otri1, otri2) \
161  (otri2).tri = (otri1).tri; \
162  (otri2).orient = plus1mod3[(otri1).orient]
163 
164 #define lnextself(otri) (otri).orient = plus1mod3[(otri).orient]
165 
166 /* lprev() finds the previous edge (clockwise) of a triangle. */
167 
168 #define lprev(otri1, otri2) \
169  (otri2).tri = (otri1).tri; \
170  (otri2).orient = minus1mod3[(otri1).orient]
171 
172 #define lprevself(otri) (otri).orient = minus1mod3[(otri).orient]
173 
174 /* onext() spins counterclockwise around a vertex; that is, it finds the */
175 /* next edge with the same origin in the counterclockwise direction. This */
176 /* edge is part of a different triangle. */
177 
178 #define onext(otri1, otri2) \
179  lprev(otri1, otri2); \
180  symself(otri2);
181 
182 #define onextself(otri) \
183  lprevself(otri); \
184  symself(otri);
185 
186 /* oprev() spins clockwise around a vertex; that is, it finds the next edge */
187 /* with the same origin in the clockwise direction. This edge is part of */
188 /* a different triangle. */
189 
190 #define oprev(otri1, otri2) \
191  sym(otri1, otri2); \
192  lnextself(otri2);
193 
194 #define oprevself(otri) \
195  symself(otri); \
196  lnextself(otri);
197 
198 /* dnext() spins counterclockwise around a vertex; that is, it finds the */
199 /* next edge with the same destination in the counterclockwise direction. */
200 /* This edge is part of a different triangle. */
201 
202 #define dnext(otri1, otri2) \
203  sym(otri1, otri2); \
204  lprevself(otri2);
205 
206 #define dnextself(otri) \
207  symself(otri); \
208  lprevself(otri);
209 
210 /* dprev() spins clockwise around a vertex; that is, it finds the next edge */
211 /* with the same destination in the clockwise direction. This edge is */
212 /* part of a different triangle. */
213 
214 #define dprev(otri1, otri2) \
215  lnext(otri1, otri2); \
216  symself(otri2);
217 
218 #define dprevself(otri) \
219  lnextself(otri); \
220  symself(otri);
221 
222 /* rnext() moves one edge counterclockwise about the adjacent triangle. */
223 /* (It's best understood by reading Guibas and Stolfi. It involves */
224 /* changing triangles twice.) */
225 
226 #define rnext(otri1, otri2) \
227  sym(otri1, otri2); \
228  lnextself(otri2); \
229  symself(otri2);
230 
231 #define rnextself(otri) \
232  symself(otri); \
233  lnextself(otri); \
234  symself(otri);
235 
236 /* rprev() moves one edge clockwise about the adjacent triangle. */
237 /* (It's best understood by reading Guibas and Stolfi. It involves */
238 /* changing triangles twice.) */
239 
240 #define rprev(otri1, otri2) \
241  sym(otri1, otri2); \
242  lprevself(otri2); \
243  symself(otri2);
244 
245 #define rprevself(otri) \
246  symself(otri); \
247  lprevself(otri); \
248  symself(otri);
249 
250 /* These primitives determine or set the origin, destination, or apex of a */
251 /* triangle. */
252 
253 #define org(otri, vertexptr) \
254  vertexptr = (vertex)(otri).tri[plus1mod3[(otri).orient] + 3]
255 
256 #define dest(otri, vertexptr) \
257  vertexptr = (vertex)(otri).tri[minus1mod3[(otri).orient] + 3]
258 
259 #define apex(otri, vertexptr) vertexptr = (vertex)(otri).tri[(otri).orient + 3]
260 
261 #define setorg(otri, vertexptr) \
262  (otri).tri[plus1mod3[(otri).orient] + 3] = (triangle)vertexptr
263 
264 #define setdest(otri, vertexptr) \
265  (otri).tri[minus1mod3[(otri).orient] + 3] = (triangle)vertexptr
266 
267 #define setapex(otri, vertexptr) \
268  (otri).tri[(otri).orient + 3] = (triangle)vertexptr
269 
270 /* Bond two triangles together. */
271 
272 #define bond(otri1, otri2) \
273  (otri1).tri[(otri1).orient] = encode(otri2); \
274  (otri2).tri[(otri2).orient] = encode(otri1)
275 
276 /* Dissolve a bond (from one side). Note that the other triangle will still */
277 /* think it's connected to this triangle. Usually, however, the other */
278 /* triangle is being deleted entirely, or bonded to another triangle, so */
279 /* it doesn't matter. */
280 
281 #define dissolve(otri) (otri).tri[(otri).orient] = (triangle)m->dummytri
282 
283 /* Copy an oriented triangle. */
284 
285 #define otricopy(otri1, otri2) \
286  (otri2).tri = (otri1).tri; \
287  (otri2).orient = (otri1).orient
288 
289 /* Test for equality of oriented triangles. */
290 
291 #define otriequal(otri1, otri2) \
292  (((otri1).tri == (otri2).tri) && ((otri1).orient == (otri2).orient))
293 
294 /* Primitives to infect or cure a triangle with the virus. These rely on */
295 /* the assumption that all subsegments are aligned to four-byte boundaries.*/
296 
297 #define infect(otri) \
298  (otri).tri[6] = (triangle)((unsigned long)(otri).tri[6] | (unsigned long)2l)
299 
300 #define uninfect(otri) \
301  (otri).tri[6] = \
302  (triangle)((unsigned long)(otri).tri[6] & ~(unsigned long)2l)
303 
304 /* Test a triangle for viral infection. */
305 
306 #define infected(otri) \
307  (((unsigned long)(otri).tri[6] & (unsigned long)2l) != 0l)
308 
309 /* Check or set a triangle's attributes. */
310 
311 #define elemattribute(otri, attnum) \
312  ((double *)(otri).tri)[m->elemattribindex + (attnum)]
313 
314 #define setelemattribute(otri, attnum, value) \
315  ((double *)(otri).tri)[m->elemattribindex + (attnum)] = value
316 
317 /* Check or set a triangle's maximum area bound. */
318 
319 #define areabound(otri) ((double *)(otri).tri)[m->areaboundindex]
320 
321 #define setareabound(otri, value) \
322  ((double *)(otri).tri)[m->areaboundindex] = value
323 
324 /* Check or set a triangle's deallocation. Its second pointer is set to */
325 /* NULL to indicate that it is not allocated. (Its first pointer is used */
326 /* for the stack of dead items.) Its fourth pointer (its first vertex) */
327 /* is set to NULL in case a `badtriang' structure points to it. */
328 
329 #define deadtri(tria) ((tria)[1] == (triangle)NULL)
330 
331 #define killtri(tria) \
332  (tria)[1] = (triangle)NULL; \
333  (tria)[3] = (triangle)NULL
334 
335 /********* Primitives for subsegments *********/
336 /* */
337 /* */
338 
339 /* sdecode() converts a pointer to an oriented subsegment. The orientation */
340 /* is extracted from the least significant bit of the pointer. The two */
341 /* least significant bits (one for orientation, one for viral infection) */
342 /* are masked out to produce the double pointer. */
343 
344 #define sdecode(sptr, osub) \
345  (osub).ssorient = (int)((unsigned long)(sptr) & (unsigned long)1l); \
346  (osub).ss = (subseg *)((unsigned long)(sptr) & ~(unsigned long)3l)
347 
348 /* sencode() compresses an oriented subsegment into a single pointer. It */
349 /* relies on the assumption that all subsegments are aligned to two-byte */
350 /* boundaries, so the least significant bit of (osub).ss is zero. */
351 
352 #define sencode(osub) \
353  (subseg)((unsigned long)(osub).ss | (unsigned long)(osub).ssorient)
354 
355 /* ssym() toggles the orientation of a subsegment. */
356 
357 #define ssym(osub1, osub2) \
358  (osub2).ss = (osub1).ss; \
359  (osub2).ssorient = 1 - (osub1).ssorient
360 
361 #define ssymself(osub) (osub).ssorient = 1 - (osub).ssorient
362 
363 /* spivot() finds the other subsegment (from the same segment) that shares */
364 /* the same origin. */
365 
366 #define spivot(osub1, osub2) \
367  sptr = (osub1).ss[(osub1).ssorient]; \
368  sdecode(sptr, osub2)
369 
370 #define spivotself(osub) \
371  sptr = (osub).ss[(osub).ssorient]; \
372  sdecode(sptr, osub)
373 
374 /* snext() finds the next subsegment (from the same segment) in sequence; */
375 /* one whose origin is the input subsegment's destination. */
376 
377 #define snext(osub1, osub2) \
378  sptr = (osub1).ss[1 - (osub1).ssorient]; \
379  sdecode(sptr, osub2)
380 
381 #define snextself(osub) \
382  sptr = (osub).ss[1 - (osub).ssorient]; \
383  sdecode(sptr, osub)
384 
385 /* These primitives determine or set the origin or destination of a */
386 /* subsegment or the segment that includes it. */
387 
388 #define sorg(osub, vertexptr) vertexptr = (vertex)(osub).ss[2 + (osub).ssorient]
389 
390 #define sdest(osub, vertexptr) \
391  vertexptr = (vertex)(osub).ss[3 - (osub).ssorient]
392 
393 #define setsorg(osub, vertexptr) \
394  (osub).ss[2 + (osub).ssorient] = (subseg)vertexptr
395 
396 #define setsdest(osub, vertexptr) \
397  (osub).ss[3 - (osub).ssorient] = (subseg)vertexptr
398 
399 #define segorg(osub, vertexptr) \
400  vertexptr = (vertex)(osub).ss[4 + (osub).ssorient]
401 
402 #define segdest(osub, vertexptr) \
403  vertexptr = (vertex)(osub).ss[5 - (osub).ssorient]
404 
405 #define setsegorg(osub, vertexptr) \
406  (osub).ss[4 + (osub).ssorient] = (subseg)vertexptr
407 
408 #define setsegdest(osub, vertexptr) \
409  (osub).ss[5 - (osub).ssorient] = (subseg)vertexptr
410 
411 /* These primitives read or set a boundary marker. Boundary markers are */
412 /* used to hold user-defined tags for setting boundary conditions in */
413 /* finite element solvers. */
414 
415 #define mark(osub) (*(int *)((osub).ss + 8))
416 
417 #define setmark(osub, value) *(int *)((osub).ss + 8) = value
418 
419 /* Bond two subsegments together. */
420 
421 #define sbond(osub1, osub2) \
422  (osub1).ss[(osub1).ssorient] = sencode(osub2); \
423  (osub2).ss[(osub2).ssorient] = sencode(osub1)
424 
425 /* Dissolve a subsegment bond (from one side). Note that the other */
426 /* subsegment will still think it's connected to this subsegment. */
427 
428 #define sdissolve(osub) (osub).ss[(osub).ssorient] = (subseg)m->dummysub
429 
430 /* Copy a subsegment. */
431 
432 #define subsegcopy(osub1, osub2) \
433  (osub2).ss = (osub1).ss; \
434  (osub2).ssorient = (osub1).ssorient
435 
436 /* Test for equality of subsegments. */
437 
438 #define subsegequal(osub1, osub2) \
439  (((osub1).ss == (osub2).ss) && ((osub1).ssorient == (osub2).ssorient))
440 
441 /* Check or set a subsegment's deallocation. Its second pointer is set to */
442 /* NULL to indicate that it is not allocated. (Its first pointer is used */
443 /* for the stack of dead items.) Its third pointer (its first vertex) */
444 /* is set to NULL in case a `badsubseg' structure points to it. */
445 
446 #define deadsubseg(sub) ((sub)[1] == (subseg)NULL)
447 
448 #define killsubseg(sub) \
449  (sub)[1] = (subseg)NULL; \
450  (sub)[2] = (subseg)NULL
451 
452 /********* Primitives for interacting triangles and subsegments *********/
453 /* */
454 /* */
455 
456 /* tspivot() finds a subsegment abutting a triangle. */
457 
458 #define tspivot(otri, osub) \
459  sptr = (subseg)(otri).tri[6 + (otri).orient]; \
460  sdecode(sptr, osub)
461 
462 /* stpivot() finds a triangle abutting a subsegment. It requires that the */
463 /* variable `ptr' of type `triangle' be defined. */
464 
465 #define stpivot(osub, otri) \
466  ptr = (triangle)(osub).ss[6 + (osub).ssorient]; \
467  decode(ptr, otri)
468 
469 /* Bond a triangle to a subsegment. */
470 
471 #define tsbond(otri, osub) \
472  (otri).tri[6 + (otri).orient] = (triangle)sencode(osub); \
473  (osub).ss[6 + (osub).ssorient] = (subseg)encode(otri)
474 
475 /* Dissolve a bond (from the triangle side). */
476 
477 #define tsdissolve(otri) (otri).tri[6 + (otri).orient] = (triangle)m->dummysub
478 
479 /* Dissolve a bond (from the subsegment side). */
480 
481 #define stdissolve(osub) (osub).ss[6 + (osub).ssorient] = (subseg)m->dummytri
482 
483 /********* Primitives for vertices *********/
484 /* */
485 /* */
486 
487 #define vertexmark(vx) ((int *)(vx))[m->vertexmarkindex]
488 
489 #define setvertexmark(vx, value) ((int *)(vx))[m->vertexmarkindex] = value
490 
491 #define vertextype(vx) ((int *)(vx))[m->vertexmarkindex + 1]
492 
493 #define setvertextype(vx, value) ((int *)(vx))[m->vertexmarkindex + 1] = value
494 
495 #define vertex2tri(vx) ((triangle *)(vx))[m->vertex2triindex]
496 
497 #define setvertex2tri(vx, value) ((triangle *)(vx))[m->vertex2triindex] = value
498 
499 /** **/
500 /** **/
501 /********* Mesh manipulation primitives end here *********/
502 
504 {
505  double *pointlist; /* In / out */
506  double *pointattributelist; /* In / out */
507  int *pointmarkerlist; /* In / out */
508  int numberofpoints; /* In / out */
509  int numberofpointattributes; /* In / out */
510 
511  int *trianglelist; /* In / out */
512  double *triangleattributelist; /* In / out */
513  double *trianglearealist; /* In only */
514  int *neighborlist; /* Out only */
515  int numberoftriangles; /* In / out */
516  int numberofcorners; /* In / out */
517  int numberoftriangleattributes; /* In / out */
518 
519  int *segmentlist; /* In / out */
520  int *segmentmarkerlist; /* In / out */
521  int numberofsegments; /* In / out */
522 
523  double *holelist; /* In / pointer to array copied out */
524  int numberofholes; /* In / copied out */
525 
526  double *regionlist; /* In / pointer to array copied out */
527  int numberofregions; /* In / copied out */
528 
529  int *edgelist; /* Out only */
530  int *edgemarkerlist; /* Not used with Voronoi diagram; out only */
531  double *normlist; /* Used only with Voronoi diagram; out only */
532  int numberofedges; /* Out only */
533 };
534 
535 /* Labels that signify the result of point location. The result of a */
536 /* search indicates that the point falls in the interior of a triangle, on */
537 /* an edge, on a vertex, or outside the mesh. */
538 
540 {
545 };
546 
547 /* Labels that signify the result of vertex insertion. The result indicates */
548 /* that the vertex was inserted with complete success, was inserted but */
549 /* encroaches upon a subsegment, was not inserted because it lies on a */
550 /* segment, or was not inserted because another vertex occupies the same */
551 /* location. */
552 
554 {
559 };
560 
561 /* Labels that signify the result of direction finding. The result */
562 /* indicates that a segment connecting the two query points falls within */
563 /* the direction triangle, along the left edge of the direction triangle, */
564 /* or along the right edge of the direction triangle. */
565 
567 {
571 };
572 
573 /*****************************************************************************/
574 /* */
575 /* The basic mesh data structures */
576 /* */
577 /* There are three: vertices, triangles, and subsegments (abbreviated */
578 /* `subseg'). These three data structures, linked by pointers, comprise */
579 /* the mesh. A vertex simply represents a mesh vertex and its properties. */
580 /* A triangle is a triangle. A subsegment is a special data structure used */
581 /* to represent an impenetrable edge of the mesh (perhaps on the outer */
582 /* boundary, on the boundary of a hole, or part of an internal boundary */
583 /* separating two triangulated regions). Subsegments represent boundaries, */
584 /* defined by the user, that triangles may not lie across. */
585 /* */
586 /* A triangle consists of a list of three vertices, a list of three */
587 /* adjoining triangles, a list of three adjoining subsegments (when */
588 /* segments exist), an arbitrary number of optional user-defined */
589 /* floating-point attributes, and an optional area constraint. The latter */
590 /* is an upper bound on the permissible area of each triangle in a region, */
591 /* used for mesh refinement. */
592 /* */
593 /* For a triangle on a boundary of the mesh, some or all of the neighboring */
594 /* triangles may not be present. For a triangle in the interior of the */
595 /* mesh, often no neighboring subsegments are present. Such absent */
596 /* triangles and subsegments are never represented by NULL pointers; they */
597 /* are represented by two special records: `dummytri', the triangle that */
598 /* fills "outer space", and `dummysub', the omnipresent subsegment. */
599 /* `dummytri' and `dummysub' are used for several reasons; for instance, */
600 /* they can be dereferenced and their contents examined without violating */
601 /* protected memory. */
602 /* */
603 /* However, it is important to understand that a triangle includes other */
604 /* information as well. The pointers to adjoining vertices, triangles, and */
605 /* subsegments are ordered in a way that indicates their geometric relation */
606 /* to each other. Furthermore, each of these pointers contains orientation */
607 /* information. Each pointer to an adjoining triangle indicates which face */
608 /* of that triangle is contacted. Similarly, each pointer to an adjoining */
609 /* subsegment indicates which side of that subsegment is contacted, and how */
610 /* the subsegment is oriented relative to the triangle. */
611 /* */
612 /* The data structure representing a subsegment may be thought to be */
613 /* abutting the edge of one or two triangle data structures: either */
614 /* sandwiched between two triangles, or resting against one triangle on an */
615 /* exterior boundary or hole boundary. */
616 /* */
617 /* A subsegment consists of a list of four vertices--the vertices of the */
618 /* subsegment, and the vertices of the segment it is a part of--a list of */
619 /* two adjoining subsegments, and a list of two adjoining triangles. One */
620 /* of the two adjoining triangles may not be present (though there should */
621 /* always be one), and neighboring subsegments might not be present. */
622 /* Subsegments also store a user-defined integer "boundary marker". */
623 /* Typically, this integer is used to indicate what boundary conditions are */
624 /* to be applied at that location in a finite element simulation. */
625 /* */
626 /* Like triangles, subsegments maintain information about the relative */
627 /* orientation of neighboring objects. */
628 /* */
629 /* Vertices are relatively simple. A vertex is a list of floating-point */
630 /* numbers, starting with the x, and y coordinates, followed by an */
631 /* arbitrary number of optional user-defined floating-point attributes, */
632 /* followed by an integer boundary marker. During the segment insertion */
633 /* phase, there is also a pointer from each vertex to a triangle that may */
634 /* contain it. Each pointer is not always correct, but when one is, it */
635 /* speeds up segment insertion. These pointers are assigned values once */
636 /* at the beginning of the segment insertion phase, and are not used or */
637 /* updated except during this phase. Edge flipping during segment */
638 /* insertion will render some of them incorrect. Hence, don't rely upon */
639 /* them for anything. */
640 /* */
641 /* Other than the exception mentioned above, vertices have no information */
642 /* about what triangles, subfacets, or subsegments they are linked to. */
643 /* */
644 /*****************************************************************************/
645 
646 /*****************************************************************************/
647 /* */
648 /* Handles */
649 /* */
650 /* The oriented triangle (`otri') and oriented subsegment (`osub') data */
651 /* structures defined below do not themselves store any part of the mesh. */
652 /* The mesh itself is made of `triangle's, `subseg's, and `vertex's. */
653 /* */
654 /* Oriented triangles and oriented subsegments will usually be referred to */
655 /* as "handles." A handle is essentially a pointer into the mesh; it */
656 /* allows you to "hold" one particular part of the mesh. Handles are used */
657 /* to specify the regions in which one is traversing and modifying the mesh.*/
658 /* A single `triangle' may be held by many handles, or none at all. (The */
659 /* latter case is not a memory leak, because the triangle is still */
660 /* connected to other triangles in the mesh.) */
661 /* */
662 /* An `otri' is a handle that holds a triangle. It holds a specific edge */
663 /* of the triangle. An `osub' is a handle that holds a subsegment. It */
664 /* holds either the left or right side of the subsegment. */
665 /* */
666 /* Navigation about the mesh is accomplished through a set of mesh */
667 /* manipulation primitives, further below. Many of these primitives take */
668 /* a handle and produce a new handle that holds the mesh near the first */
669 /* handle. Other primitives take two handles and glue the corresponding */
670 /* parts of the mesh together. The orientation of the handles is */
671 /* important. For instance, when two triangles are glued together by the */
672 /* bond() primitive, they are glued at the edges on which the handles lie. */
673 /* */
674 /* Because vertices have no information about which triangles they are */
675 /* attached to, I commonly represent a vertex by use of a handle whose */
676 /* origin is the vertex. A single handle can simultaneously represent a */
677 /* triangle, an edge, and a vertex. */
678 /* */
679 /*****************************************************************************/
680 
681 /* The triangle data structure. Each triangle contains three pointers to */
682 /* adjoining triangles, plus three pointers to vertices, plus three */
683 /* pointers to subsegments (declared below; these pointers are usually */
684 /* `dummysub'). It may or may not also contain user-defined attributes */
685 /* and/or a floating-point "area constraint." It may also contain extra */
686 /* pointers for nodes, when the user asks for high-order elements. */
687 /* Because the size and structure of a `triangle' is not decided until */
688 /* runtime, I haven't simply declared the type `triangle' as a struct. */
689 
690 typedef double **triangle; /* Really: typedef triangle *triangle */
691 
692 /* An oriented triangle: includes a pointer to a triangle and orientation. */
693 /* The orientation denotes an edge of the triangle. Hence, there are */
694 /* three possible orientations. By convention, each edge always points */
695 /* counterclockwise about the corresponding triangle. */
696 
697 struct otri
698 {
699  triangle *tri;
700  int orient; /* Ranges from 0 to 2. */
701 };
702 
703 /* The subsegment data structure. Each subsegment contains two pointers to */
704 /* adjoining subsegments, plus four pointers to vertices, plus two */
705 /* pointers to adjoining triangles, plus one boundary marker, plus one */
706 /* segment number. */
707 
708 typedef double **subseg; /* Really: typedef subseg *subseg */
709 
710 /* An oriented subsegment: includes a pointer to a subsegment and an */
711 /* orientation. The orientation denotes a side of the edge. Hence, there */
712 /* are two possible orientations. By convention, the edge is always */
713 /* directed so that the "side" denoted is the right side of the edge. */
714 
715 struct osub
716 {
717  subseg *ss;
718  int ssorient; /* Ranges from 0 to 1. */
719 };
720 
721 /* The vertex data structure. Each vertex is actually an array of doubles. */
722 /* The number of doubles is unknown until runtime. An integer boundary */
723 /* marker, and sometimes a pointer to a triangle, is appended after the */
724 /* doubles. */
725 
726 typedef double *vertex;
727 
728 /* A queue used to store encroached subsegments. Each subsegment's vertices */
729 /* are stored so that we can check whether a subsegment is still the same. */
730 
731 struct badsubseg
732 {
733  subseg encsubseg; /* An encroached subsegment. */
734  vertex subsegorg, subsegdest; /* Its two vertices. */
735 };
736 
737 /* A queue used to store bad triangles. The key is the square of the cosine */
738 /* of the smallest angle of the triangle. Each triangle's vertices are */
739 /* stored so that one can check whether a triangle is still the same. */
740 
741 struct badtriang
742 {
743  triangle poortri; /* A skinny or too-large triangle. */
744  double key; /* cos^2 of smallest (apical) angle. */
745  vertex triangorg, triangdest, triangapex; /* Its three vertices. */
746  struct badtriang *nexttriang; /* Pointer to next bad triangle. */
747 };
748 
749 /* A stack of triangles flipped during the most recent vertex insertion. */
750 /* The stack is used to undo the vertex insertion if the vertex encroaches */
751 /* upon a subsegment. */
752 
754 {
755  triangle flippedtri; /* A recently flipped triangle. */
756  struct flipstacker *prevflip; /* Previous flip in the stack. */
757 };
758 
759 /* A node in a heap used to store events for the sweepline Delaunay */
760 /* algorithm. Nodes do not point directly to their parents or children in */
761 /* the heap. Instead, each node knows its position in the heap, and can */
762 /* look up its parent and children in a separate array. The `eventptr' */
763 /* points either to a `vertex' or to a triangle (in encoded format, so */
764 /* that an orientation is included). In the latter case, the origin of */
765 /* the oriented triangle is the apex of a "circle event" of the sweepline */
766 /* algorithm. To distinguish site events from circle events, all circle */
767 /* events are given an invalid (smaller than `xmin') x-coordinate `xkey'. */
768 
769 struct event
770 {
771  double xkey, ykey; /* Coordinates of the event. */
772  void *eventptr; /* Can be a vertex or the location of a circle event. */
773  int heapposition; /* Marks this event's position in the heap. */
774 };
775 
776 /* A node in the splay tree. Each node holds an oriented ghost triangle */
777 /* that represents a boundary edge of the growing triangulation. When a */
778 /* circle event covers two boundary edges with a triangle, so that they */
779 /* are no longer boundary edges, those edges are not immediately deleted */
780 /* from the tree; rather, they are lazily deleted when they are next */
781 /* encountered. (Since only a random sample of boundary edges are kept */
782 /* in the tree, lazy deletion is faster.) `keydest' is used to verify */
783 /* that a triangle is still the same as when it entered the splay tree; if */
784 /* it has been rotated (due to a circle event), it no longer represents a */
785 /* boundary edge and should be deleted. */
786 
787 struct splaynode
788 {
789  struct otri keyedge; /* Lprev of an edge on the front. */
790  vertex keydest; /* Used to verify that splay node is still live. */
791  struct splaynode *lchild, *rchild; /* Children in splay tree. */
792 };
793 
794 /* A type used to allocate memory. firstblock is the first block of items. */
795 /* nowblock is the block from which items are currently being allocated. */
796 /* nextitem points to the next slab of free memory for an item. */
797 /* deaditemstack is the head of a linked list (stack) of deallocated items */
798 /* that can be recycled. unallocateditems is the number of items that */
799 /* remain to be allocated from nowblock. */
800 /* */
801 /* Traversal is the process of walking through the entire list of items, and */
802 /* is separate from allocation. Note that a traversal will visit items on */
803 /* the "deaditemstack" stack as well as live items. pathblock points to */
804 /* the block currently being traversed. pathitem points to the next item */
805 /* to be traversed. pathitemsleft is the number of items that remain to */
806 /* be traversed in pathblock. */
807 /* */
808 /* alignbytes determines how new records should be aligned in memory. */
809 /* itembytes is the length of a record in bytes (after rounding up). */
810 /* itemsperblock is the number of items allocated at once in a single */
811 /* block. itemsfirstblock is the number of items in the first block, */
812 /* which can vary from the others. items is the number of currently */
813 /* allocated items. maxitems is the maximum number of items that have */
814 /* been allocated at once; it is the current number of items plus the */
815 /* number of records kept on deaditemstack. */
816 
818 {
819  void **firstblock, **nowblock;
820  void *nextitem;
822  void **pathblock;
823  void *pathitem;
831 };
832 
833 /* Mesh data structure. Triangle operates on only one mesh, but the mesh */
834 /* structure is used (instead of global variables) to allow reentrancy. */
835 
836 struct mesh
837 {
838 
839  /* Variables used to allocate memory for triangles, subsegments, vertices,
840  */
841  /* viri (triangles being eaten), encroached segments, bad (skinny or too
842  */
843  /* large) triangles, and splay tree nodes. */
844 
848  struct memorypool viri;
853 
854  /* Variables that maintain the bad triangle queues. The queues are */
855  /* ordered from 4095 (highest priority) to 0 (lowest priority). */
856 
857  struct badtriang *queuefront[4096];
858  struct badtriang *queuetail[4096];
859  int nextnonemptyq[4096];
861 
862  /* Variable that maintains the stack of recently flipped triangles. */
863 
865 
866  /* Other variables. */
867 
868  double xmin, xmax, ymin, ymax; /* x and y bounds. */
869  double xminextreme; /* Nonexistent x value used as a flag in sweepline. */
870  int invertices; /* Number of input vertices. */
871  int inelements; /* Number of input triangles. */
872  int insegments; /* Number of input segments. */
873  int holes; /* Number of input holes. */
874  int regions; /* Number of input regions. */
875  int undeads; /* Number of input vertices that don't appear in the mesh. */
876  long edges; /* Number of output edges. */
877  int mesh_dim; /* Dimension (ought to be 2). */
878  int nextras; /* Number of attributes per vertex. */
879  int eextras; /* Number of attributes per triangle. */
880  long hullsize; /* Number of edges in convex hull. */
881  int steinerleft; /* Number of Steiner points not yet used. */
882  int vertexmarkindex; /* Index to find boundary marker of a vertex. */
883  int vertex2triindex; /* Index to find a triangle adjacent to a vertex. */
884  int highorderindex; /* Index to find extra nodes for high-order elements. */
885  int elemattribindex; /* Index to find attributes of a triangle. */
886  int areaboundindex; /* Index to find area bound of a triangle. */
887  int checksegments; /* Are there segments in the triangulation yet? */
888  int checkquality; /* Has quality triangulation begun yet? */
889  int readnodefile; /* Has a .node file been read? */
890  long samples; /* Number of random samples for point location. */
891 
892  long incirclecount; /* Number of incircle tests performed. */
893  long counterclockcount; /* Number of counterclockwise tests performed. */
894  long orient3dcount; /* Number of 3D orientation tests performed. */
895  long hyperbolacount; /* Number of right-of-hyperbola tests performed. */
896  long circumcentercount; /* Number of circumcenter calculations performed. */
897  long circletopcount; /* Number of circle top calculations performed. */
898 
899  /* Triangular bounding box vertices. */
900 
902 
903  /* Pointer to the `triangle' that occupies all of "outer space." */
904 
905  triangle *dummytri;
906  triangle *dummytribase; /* Keep base address so we can free() it later. */
907 
908  /* Pointer to the omnipresent subsegment. Referenced by any triangle or */
909  /* subsegment that isn't really connected to a subsegment at that */
910  /* location. */
911 
912  subseg *dummysub;
913  subseg *dummysubbase; /* Keep base address so we can free() it later. */
914 
915  /* Pointer to a recently visited triangle. Improves point location if */
916  /* proximate vertices are inserted sequentially. */
917 
918  struct otri recenttri;
919 
920 }; /* End of `struct mesh'. */
921 
922 /* Data structure for command line switches and file names. This structure */
923 /* is used (instead of global variables) to allow reentrancy. */
924 
925 struct behavior
926 {
927 
928  /* Switches for the triangulator. */
929  /* poly: -p switch. */
930  /* quality: -q switch. */
931  /* minangle: minimum angle bound, specified after -q switch. */
932  /* goodangle: cosine squared of minangle. */
933  /* offconstant: constant used to place off-center Steiner points. */
934  /* usertest: -u switch. */ //pretend to use this one to make triangle do its own calcs
935  /* weighted: 1 for -w switch, 2 for -W switch. jettison: -j switch */
936  /* nobisect: count of how often -Y switch is selected. */
937  /* usesegments: -p, -r, -q, or -c switch; determines whether segments are
938  */
939  /* used at all. */
940  /* */
941  /* Read the instructions to find out the meaning of these switches. */
942 
946  int nobisect;
948 
949 }; /* End of `struct behavior'. */
950 
952 {
953 public:
955 
956  void triangulate(char *);
957  void trifree(void *memptr);
958 
959  struct triangulateio in,out;
960 
961 private:
962  int triunsuitable(vertex triorg, vertex tridest, vertex triapex, double area);
963  void triexit(int status);
964  void *trimalloc(int size);
965  void internalerror();
966  void parsecommandline(int argc, char **argv, struct behavior *b);
967  void poolzero(struct memorypool *pool);
968  void poolrestart(struct memorypool *pool);
969  void pooldeinit(struct memorypool *pool);
970  void *poolalloc(struct memorypool *pool);
971  void pooldealloc(struct memorypool *pool, void *dyingitem);
972  void traversalinit(struct memorypool *pool);
973  void *traverse(struct memorypool *pool);
974  void initializevertexpool(struct mesh *m, struct behavior *b);
975  void initializetrisubpools(struct mesh *m, struct behavior *b);
976  void triangledealloc(struct mesh *m, triangle *dyingtriangle);
977  triangle *triangletraverse(struct mesh *m);
978  void subsegdealloc(struct mesh *m, subseg *dyingsubseg);
979  subseg *subsegtraverse(struct mesh *m);
980  void vertexdealloc(struct mesh *m, vertex dyingvertex);
981  vertex vertextraverse(struct mesh *m);
982  void badsubsegdealloc(struct mesh *m, struct badsubseg *dyingseg);
983  struct badsubseg *badsubsegtraverse(struct mesh *m);
984  vertex getvertex(struct mesh *m, struct behavior *b, int number);
985  void triangledeinit(struct mesh *m, struct behavior *b);
986  void maketriangle(struct mesh *m, struct behavior *b, struct otri *newotri);
987  void makesubseg(struct mesh *m, struct osub *newsubseg);
988  void exactinit();
989  int scale_expansion_zeroelimTRI(int elen, double *e, double b, double *h);
990  double estimateTRI(int elen, double *e);
991  double counterclockwise(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc);
992  double counterclockwiseadapt(vertex pa, vertex pb, vertex pc, double detsum);
993  void poolinit(struct memorypool *pool, int bytecount, int itemcount, int firstitemcount, int alignment);
994  void dummyinit(struct mesh *m, struct behavior *b, int trianglebytes, int subsegbytes);
995  double incircleadaptTRI(vertex pa, vertex pb, vertex pc, vertex pd, double permanent);
996  double incircle(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc, vertex pd);
997  void triangleinit(struct mesh *m);
998  unsigned long randomnation(unsigned int choices);
999  struct badtriang *dequeuebadtriang(struct mesh *m);
1000  void testtriangle(struct mesh *m, struct behavior *b, struct otri *testtri);
1001  void makevertexmap(struct mesh *m, struct behavior *b);
1002  void flip(struct mesh *m, struct behavior *b, struct otri *flipedge);
1003  void unflip(struct mesh *m, struct behavior *b, struct otri *flipedge);
1004  int fast_expansion_sum_zeroelimTRI(int elen, double *e, int flen, double *f, double *h);
1005  double orient3dadapt(vertex pa, vertex pb, vertex pc, vertex pd, double aheight, double bheight, double cheight, double dheight, double permanent);
1006  double orient3d(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc, vertex pd, double aheight, double bheight, double cheight, double dheight);
1007  double nonregular(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc, vertex pd);
1008  void findcircumcenter(struct mesh *m, struct behavior *b, vertex torg, vertex tdest, vertex tapex, vertex circumcenter, double *xi, double *eta, int offcenter);
1009  void enqueuebadtriang(struct mesh *m, struct behavior *b, struct badtriang *badtri);
1010  void enqueuebadtri(struct mesh *m, struct behavior *b, struct otri *enqtri, double minedge, vertex enqapex, vertex enqorg, vertex enqdest);
1011  int checkseg4encroach(struct mesh *m, struct behavior *b, struct osub *testsubseg);
1012  enum locateresult preciselocate(struct mesh *m, struct behavior *b, vertex searchpoint, struct otri *searchtri, int stopatsubsegment);
1013  enum locateresult locate(struct mesh *m, struct behavior *b, vertex searchpoint, struct otri *searchtri);
1014  void insertsubseg(struct mesh *m, struct behavior *b, struct otri *tri, int subsegmark);
1015  enum insertvertexresult insertvertex(struct mesh *m, struct behavior *b, vertex newvertex, struct otri *searchtri, struct osub *splitseg, int segmentflaws, int triflaws);
1016  void triangulatepolygon(struct mesh *m, struct behavior *b, struct otri *firstedge, struct otri *lastedge, int edgecount, int doflip, int triflaws);
1017  void deletevertex(struct mesh *m, struct behavior *b, struct otri *deltri);
1018  void undovertex(struct mesh *m, struct behavior *b);
1019  void vertexsort(vertex *sortarray, unsigned int arraysize);
1020  void vertexmedian(vertex *sortarray, int arraysize, int median, int axis);
1021  void alternateaxes(vertex *sortarray, int arraysize, int axis);
1022  long removeghosts(struct mesh *m, struct behavior *b, struct otri *startghost);
1023  long divconqdelaunay(struct mesh *m, struct behavior *b);
1024  long delaunay(struct mesh *m, struct behavior *b);
1025  void mergehulls(struct mesh *m, struct behavior *b, struct otri *farleft, struct otri *innerleft, struct otri *innerright, struct otri *farright, int axis);
1026  void divconqrecurse(struct mesh *m, struct behavior *b, vertex *sortarray, int vertices, int axis, struct otri *farleft, struct otri *farright);
1027  enum finddirectionresult finddirection(struct mesh *m, struct behavior *b, struct otri *searchtri, vertex searchpoint);
1028  void segmentintersection(struct mesh *m, struct behavior *b, struct otri *splittri, struct osub *splitsubseg, vertex endpoint2);
1029  int scoutsegment(struct mesh *m, struct behavior *b, struct otri *searchtri, vertex endpoint2, int newmark);
1030  void conformingedge(struct mesh *m, struct behavior *b, vertex endpoint1, vertex endpoint2, int newmark);
1031  void delaunayfixup(struct mesh *m, struct behavior *b, struct otri *fixuptri, int leftside);
1032  void constrainededge(struct mesh *m, struct behavior *b, struct otri *starttri, vertex endpoint2, int newmark);
1033  void insertsegment(struct mesh *m, struct behavior *b, vertex endpoint1, vertex endpoint2, int newmark);
1034  void markhull(struct mesh *m, struct behavior *b);
1035  void formskeleton(struct mesh *m, struct behavior *b, int *segmentlist, int *segmentmarkerlist, int numberofsegments);
1036  void infecthull(struct mesh *m, struct behavior *b);
1037  void plague(struct mesh *m, struct behavior *b);
1038  void regionplague(struct mesh *m, struct behavior *b, double attribute, double area);
1039  void carveholes(struct mesh *m, struct behavior *b, double *holelist, int holes, double *regionlist, int regions);
1040  void tallyencs(struct mesh *m, struct behavior *b);
1041  void precisionerror();
1042  void splitencsegs(struct mesh *m, struct behavior *b, int triflaws);
1043  void tallyfaces(struct mesh *m, struct behavior *b);
1044  void splittriangle(struct mesh *m, struct behavior *b, struct badtriang *badtri);
1045  void enforcequality(struct mesh *m, struct behavior *b);
1046  void transfernodes(struct mesh *m, struct behavior *b, double *pointlist, double *pointattriblist, int *pointmarkerlist, int numberofpoints, int numberofpointattribs);
1047  void writenodes(struct mesh *m, struct behavior *b, double **pointlist, double **pointattriblist, int **pointmarkerlist);
1048  void numbernodes(struct mesh *m, struct behavior *b);
1049  void writeelements(struct mesh *m, struct behavior *b, int **trianglelist, double **triangleattriblist);
1050  void writepoly(struct mesh *m, struct behavior *b, int **segmentlist, int **segmentmarkerlist);
1051 
1052  /* Global constants. */
1053 
1054  double splitter; /* Used to split double factors for exact multiplication. */
1055  double epsilon; /* Floating-point machine epsilon. */
1060 
1061  /* Random number seed is not constant, but I've made it global anyway. */
1062 
1063  unsigned long randomseed; /* Current random number seed. */
1064 
1065  /* Fast lookup arrays to speed some of the mesh manipulation primitives. */
1066 
1067  int plus1mod3[3];
1068  int minus1mod3[3];
1069 };
1070 
1071 }
1072 }
1073 #endif
void triangledeinit(struct mesh *m, struct behavior *b)
void badsubsegdealloc(struct mesh *m, struct badsubseg *dyingseg)
struct badtriang * dequeuebadtriang(struct mesh *m)
struct flipstacker * lastflip
void alternateaxes(vertex *sortarray, int arraysize, int axis)
void vertexmedian(vertex *sortarray, int arraysize, int median, int axis)
void writepoly(struct mesh *m, struct behavior *b, int **segmentlist, int **segmentmarkerlist)
void writenodes(struct mesh *m, struct behavior *b, double **pointlist, double **pointattriblist, int **pointmarkerlist)
void tallyencs(struct mesh *m, struct behavior *b)
void formskeleton(struct mesh *m, struct behavior *b, int *segmentlist, int *segmentmarkerlist, int numberofsegments)
void vertexsort(vertex *sortarray, unsigned int arraysize)
void writeelements(struct mesh *m, struct behavior *b, int **trianglelist, double **triangleattriblist)
void subsegdealloc(struct mesh *m, subseg *dyingsubseg)
double incircle(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc, vertex pd)
void pooldeinit(struct memorypool *pool)
unsigned long randomnation(unsigned int choices)
void * traverse(struct memorypool *pool)
int triunsuitable(vertex triorg, vertex tridest, vertex triapex, double area)
struct badsubseg * badsubsegtraverse(struct mesh *m)
void * poolalloc(struct memorypool *pool)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
struct badtriang * queuetail[4096]
void maketriangle(struct mesh *m, struct behavior *b, struct otri *newotri)
void makevertexmap(struct mesh *m, struct behavior *b)
void poolinit(struct memorypool *pool, int bytecount, int itemcount, int firstitemcount, int alignment)
void poolzero(struct memorypool *pool)
void carveholes(struct mesh *m, struct behavior *b, double *holelist, int holes, double *regionlist, int regions)
void triangulatepolygon(struct mesh *m, struct behavior *b, struct otri *firstedge, struct otri *lastedge, int edgecount, int doflip, int triflaws)
enum insertvertexresult insertvertex(struct mesh *m, struct behavior *b, vertex newvertex, struct otri *searchtri, struct osub *splitseg, int segmentflaws, int triflaws)
void enqueuebadtriang(struct mesh *m, struct behavior *b, struct badtriang *badtri)
double orient3dadapt(vertex pa, vertex pb, vertex pc, vertex pd, double aheight, double bheight, double cheight, double dheight, double permanent)
void traversalinit(struct memorypool *pool)
void triangledealloc(struct mesh *m, triangle *dyingtriangle)
void initializevertexpool(struct mesh *m, struct behavior *b)
void insertsegment(struct mesh *m, struct behavior *b, vertex endpoint1, vertex endpoint2, int newmark)
long delaunay(struct mesh *m, struct behavior *b)
void testtriangle(struct mesh *m, struct behavior *b, struct otri *testtri)
struct badtriang * queuefront[4096]
vertex getvertex(struct mesh *m, struct behavior *b, int number)
void vertexdealloc(struct mesh *m, vertex dyingvertex)
void enqueuebadtri(struct mesh *m, struct behavior *b, struct otri *enqtri, double minedge, vertex enqapex, vertex enqorg, vertex enqdest)
void unflip(struct mesh *m, struct behavior *b, struct otri *flipedge)
void segmentintersection(struct mesh *m, struct behavior *b, struct otri *splittri, struct osub *splitsubseg, vertex endpoint2)
void mergehulls(struct mesh *m, struct behavior *b, struct otri *farleft, struct otri *innerleft, struct otri *innerright, struct otri *farright, int axis)
void numbernodes(struct mesh *m, struct behavior *b)
void flip(struct mesh *m, struct behavior *b, struct otri *flipedge)
long removeghosts(struct mesh *m, struct behavior *b, struct otri *startghost)
void markhull(struct mesh *m, struct behavior *b)
void insertsubseg(struct mesh *m, struct behavior *b, struct otri *tri, int subsegmark)
void divconqrecurse(struct mesh *m, struct behavior *b, vertex *sortarray, int vertices, int axis, struct otri *farleft, struct otri *farright)
double counterclockwiseadapt(vertex pa, vertex pb, vertex pc, double detsum)
void delaunayfixup(struct mesh *m, struct behavior *b, struct otri *fixuptri, int leftside)
enum locateresult preciselocate(struct mesh *m, struct behavior *b, vertex searchpoint, struct otri *searchtri, int stopatsubsegment)
long divconqdelaunay(struct mesh *m, struct behavior *b)
double counterclockwise(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc)
int fast_expansion_sum_zeroelimTRI(int elen, double *e, int flen, double *f, double *h)
double orient3d(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc, vertex pd, double aheight, double bheight, double cheight, double dheight)
void plague(struct mesh *m, struct behavior *b)
void poolrestart(struct memorypool *pool)
int scale_expansion_zeroelimTRI(int elen, double *e, double b, double *h)
void transfernodes(struct mesh *m, struct behavior *b, double *pointlist, double *pointattriblist, int *pointmarkerlist, int numberofpoints, int numberofpointattribs)
double nonregular(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc, vertex pd)
void splittriangle(struct mesh *m, struct behavior *b, struct badtriang *badtri)
void undovertex(struct mesh *m, struct behavior *b)
triangle * triangletraverse(struct mesh *m)
void deletevertex(struct mesh *m, struct behavior *b, struct otri *deltri)
enum finddirectionresult finddirection(struct mesh *m, struct behavior *b, struct otri *searchtri, vertex searchpoint)
void splitencsegs(struct mesh *m, struct behavior *b, int triflaws)
void constrainededge(struct mesh *m, struct behavior *b, struct otri *starttri, vertex endpoint2, int newmark)
void infecthull(struct mesh *m, struct behavior *b)
void enforcequality(struct mesh *m, struct behavior *b)
void dummyinit(struct mesh *m, struct behavior *b, int trianglebytes, int subsegbytes)
struct memorypool flipstackers
void makesubseg(struct mesh *m, struct osub *newsubseg)
int checkseg4encroach(struct mesh *m, struct behavior *b, struct osub *testsubseg)
void initializetrisubpools(struct mesh *m, struct behavior *b)
struct memorypool badtriangles
void tallyfaces(struct mesh *m, struct behavior *b)
double incircleadaptTRI(vertex pa, vertex pb, vertex pc, vertex pd, double permanent)
void findcircumcenter(struct mesh *m, struct behavior *b, vertex torg, vertex tdest, vertex tapex, vertex circumcenter, double *xi, double *eta, int offcenter)
enum locateresult locate(struct mesh *m, struct behavior *b, vertex searchpoint, struct otri *searchtri)
int scoutsegment(struct mesh *m, struct behavior *b, struct otri *searchtri, vertex endpoint2, int newmark)
void pooldealloc(struct memorypool *pool, void *dyingitem)
void conformingedge(struct mesh *m, struct behavior *b, vertex endpoint1, vertex endpoint2, int newmark)
void regionplague(struct mesh *m, struct behavior *b, double attribute, double area)
void parsecommandline(int argc, char **argv, struct behavior *b)