53 #ifndef NEKTAR_MESHUTILS_TRIANGLE_DT_H
54 #define NEKTAR_MESHUTILS_TRIANGLE_DT_H
56 #include <boost/shared_ptr.hpp>
63 namespace NekMeshUtils
70 #define TRIPERBLOCK 4092
71 #define SUBSEGPERBLOCK 508
72 #define VERTEXPERBLOCK 4092
73 #define VIRUSPERBLOCK 1020
75 #define BADSUBSEGPERBLOCK 252
77 #define BADTRIPERBLOCK 4092
79 #define FLIPSTACKERPERBLOCK 252
81 #define SPLAYNODEPERBLOCK 508
88 #define SEGMENTVERTEX 1
90 #define DEADVERTEX -32768
91 #define UNDEADVERTEX -32767
99 #define SAMPLEFACTOR 11
105 #define SAMPLERATE 10
109 #define PI 3.141592653589793238462643383279502884197169399375105820974944592308
113 #define SQUAREROOTTWO 1.4142135623730950488016887242096980785696718753769480732
117 #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333
130 #define decode(ptr, otri) \
131 (otri).orient = (int)((unsigned long)(ptr) & (unsigned long)3l); \
133 (triangle *)((unsigned long)(ptr) ^ (unsigned long)(otri).orient)
139 #define encode(otri) \
140 (triangle)((unsigned long)(otri).tri | (unsigned long)(otri).orient)
150 #define sym(otri1, otri2) \
151 ptr = (otri1).tri[(otri1).orient]; \
154 #define symself(otri) \
155 ptr = (otri).tri[(otri).orient]; \
160 #define lnext(otri1, otri2) \
161 (otri2).tri = (otri1).tri; \
162 (otri2).orient = plus1mod3[(otri1).orient]
164 #define lnextself(otri) (otri).orient = plus1mod3[(otri).orient]
168 #define lprev(otri1, otri2) \
169 (otri2).tri = (otri1).tri; \
170 (otri2).orient = minus1mod3[(otri1).orient]
172 #define lprevself(otri) (otri).orient = minus1mod3[(otri).orient]
178 #define onext(otri1, otri2) \
179 lprev(otri1, otri2); \
182 #define onextself(otri) \
190 #define oprev(otri1, otri2) \
194 #define oprevself(otri) \
202 #define dnext(otri1, otri2) \
206 #define dnextself(otri) \
214 #define dprev(otri1, otri2) \
215 lnext(otri1, otri2); \
218 #define dprevself(otri) \
226 #define rnext(otri1, otri2) \
231 #define rnextself(otri) \
240 #define rprev(otri1, otri2) \
245 #define rprevself(otri) \
253 #define org(otri, vertexptr) \
254 vertexptr = (vertex)(otri).tri[plus1mod3[(otri).orient] + 3]
256 #define dest(otri, vertexptr) \
257 vertexptr = (vertex)(otri).tri[minus1mod3[(otri).orient] + 3]
259 #define apex(otri, vertexptr) vertexptr = (vertex)(otri).tri[(otri).orient + 3]
261 #define setorg(otri, vertexptr) \
262 (otri).tri[plus1mod3[(otri).orient] + 3] = (triangle)vertexptr
264 #define setdest(otri, vertexptr) \
265 (otri).tri[minus1mod3[(otri).orient] + 3] = (triangle)vertexptr
267 #define setapex(otri, vertexptr) \
268 (otri).tri[(otri).orient + 3] = (triangle)vertexptr
272 #define bond(otri1, otri2) \
273 (otri1).tri[(otri1).orient] = encode(otri2); \
274 (otri2).tri[(otri2).orient] = encode(otri1)
281 #define dissolve(otri) (otri).tri[(otri).orient] = (triangle)m->dummytri
285 #define otricopy(otri1, otri2) \
286 (otri2).tri = (otri1).tri; \
287 (otri2).orient = (otri1).orient
291 #define otriequal(otri1, otri2) \
292 (((otri1).tri == (otri2).tri) && ((otri1).orient == (otri2).orient))
297 #define infect(otri) \
298 (otri).tri[6] = (triangle)((unsigned long)(otri).tri[6] | (unsigned long)2l)
300 #define uninfect(otri) \
302 (triangle)((unsigned long)(otri).tri[6] & ~(unsigned long)2l)
306 #define infected(otri) \
307 (((unsigned long)(otri).tri[6] & (unsigned long)2l) != 0l)
311 #define elemattribute(otri, attnum) \
312 ((double *)(otri).tri)[m->elemattribindex + (attnum)]
314 #define setelemattribute(otri, attnum, value) \
315 ((double *)(otri).tri)[m->elemattribindex + (attnum)] = value
319 #define areabound(otri) ((double *)(otri).tri)[m->areaboundindex]
321 #define setareabound(otri, value) \
322 ((double *)(otri).tri)[m->areaboundindex] = value
329 #define deadtri(tria) ((tria)[1] == (triangle)NULL)
331 #define killtri(tria) \
332 (tria)[1] = (triangle)NULL; \
333 (tria)[3] = (triangle)NULL
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)
352 #define sencode(osub) \
353 (subseg)((unsigned long)(osub).ss | (unsigned long)(osub).ssorient)
357 #define ssym(osub1, osub2) \
358 (osub2).ss = (osub1).ss; \
359 (osub2).ssorient = 1 - (osub1).ssorient
361 #define ssymself(osub) (osub).ssorient = 1 - (osub).ssorient
366 #define spivot(osub1, osub2) \
367 sptr = (osub1).ss[(osub1).ssorient]; \
370 #define spivotself(osub) \
371 sptr = (osub).ss[(osub).ssorient]; \
377 #define snext(osub1, osub2) \
378 sptr = (osub1).ss[1 - (osub1).ssorient]; \
381 #define snextself(osub) \
382 sptr = (osub).ss[1 - (osub).ssorient]; \
388 #define sorg(osub, vertexptr) vertexptr = (vertex)(osub).ss[2 + (osub).ssorient]
390 #define sdest(osub, vertexptr) \
391 vertexptr = (vertex)(osub).ss[3 - (osub).ssorient]
393 #define setsorg(osub, vertexptr) \
394 (osub).ss[2 + (osub).ssorient] = (subseg)vertexptr
396 #define setsdest(osub, vertexptr) \
397 (osub).ss[3 - (osub).ssorient] = (subseg)vertexptr
399 #define segorg(osub, vertexptr) \
400 vertexptr = (vertex)(osub).ss[4 + (osub).ssorient]
402 #define segdest(osub, vertexptr) \
403 vertexptr = (vertex)(osub).ss[5 - (osub).ssorient]
405 #define setsegorg(osub, vertexptr) \
406 (osub).ss[4 + (osub).ssorient] = (subseg)vertexptr
408 #define setsegdest(osub, vertexptr) \
409 (osub).ss[5 - (osub).ssorient] = (subseg)vertexptr
415 #define mark(osub) (*(int *)((osub).ss + 8))
417 #define setmark(osub, value) *(int *)((osub).ss + 8) = value
421 #define sbond(osub1, osub2) \
422 (osub1).ss[(osub1).ssorient] = sencode(osub2); \
423 (osub2).ss[(osub2).ssorient] = sencode(osub1)
428 #define sdissolve(osub) (osub).ss[(osub).ssorient] = (subseg)m->dummysub
432 #define subsegcopy(osub1, osub2) \
433 (osub2).ss = (osub1).ss; \
434 (osub2).ssorient = (osub1).ssorient
438 #define subsegequal(osub1, osub2) \
439 (((osub1).ss == (osub2).ss) && ((osub1).ssorient == (osub2).ssorient))
446 #define deadsubseg(sub) ((sub)[1] == (subseg)NULL)
448 #define killsubseg(sub) \
449 (sub)[1] = (subseg)NULL; \
450 (sub)[2] = (subseg)NULL
458 #define tspivot(otri, osub) \
459 sptr = (subseg)(otri).tri[6 + (otri).orient]; \
465 #define stpivot(osub, otri) \
466 ptr = (triangle)(osub).ss[6 + (osub).ssorient]; \
471 #define tsbond(otri, osub) \
472 (otri).tri[6 + (otri).orient] = (triangle)sencode(osub); \
473 (osub).ss[6 + (osub).ssorient] = (subseg)encode(otri)
477 #define tsdissolve(otri) (otri).tri[6 + (otri).orient] = (triangle)m->dummysub
481 #define stdissolve(osub) (osub).ss[6 + (osub).ssorient] = (subseg)m->dummytri
487 #define vertexmark(vx) ((int *)(vx))[m->vertexmarkindex]
489 #define setvertexmark(vx, value) ((int *)(vx))[m->vertexmarkindex] = value
491 #define vertextype(vx) ((int *)(vx))[m->vertexmarkindex + 1]
493 #define setvertextype(vx, value) ((int *)(vx))[m->vertexmarkindex + 1] = value
495 #define vertex2tri(vx) ((triangle *)(vx))[m->vertex2triindex]
497 #define setvertex2tri(vx, value) ((triangle *)(vx))[m->vertex2triindex] = value
962 int triunsuitable(vertex triorg, vertex tridest, vertex triapex,
double area);
993 void poolinit(
struct memorypool *pool,
int bytecount,
int itemcount,
int firstitemcount,
int alignment);
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);
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);
1008 void findcircumcenter(
struct mesh *m,
struct behavior *b, vertex torg, vertex tdest, vertex tapex, vertex circumcenter,
double *xi,
double *eta,
int offcenter);
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);
1035 void formskeleton(
struct mesh *m,
struct behavior *b,
int *segmentlist,
int *segmentmarkerlist,
int numberofsegments);
1039 void carveholes(
struct mesh *m,
struct behavior *b,
double *holelist,
int holes,
double *regionlist,
int regions);
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);
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)
int numberoftriangleattributes
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 memorypool subsegs
struct memorypool triangles
void * trimalloc(int size)
struct badtriang * queuetail[4096]
void maketriangle(struct mesh *m, struct behavior *b, struct otri *newotri)
struct triangulateio in out
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)
struct splaynode * rchild
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)
struct memorypool badsubsegs
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 trifree(void *memptr)
double estimateTRI(int elen, double *e)
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)
struct memorypool splaynodes
int numberofpointattributes
struct memorypool vertices
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)
void triangleinit(struct mesh *m)
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)
double * pointattributelist
void plague(struct mesh *m, struct behavior *b)
double * triangleattributelist
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)
double * trianglearealist
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)
struct badtriang * nexttriang
int checkseg4encroach(struct mesh *m, struct behavior *b, struct osub *testsubseg)
vertex vertextraverse(struct mesh *m)
void initializetrisubpools(struct mesh *m, struct behavior *b)
struct memorypool badtriangles
void tallyfaces(struct mesh *m, struct behavior *b)
struct flipstacker * prevflip
subseg * subsegtraverse(struct mesh *m)
struct splaynode * lchild
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)