📄 triangle.c
字号:
REAL resulterrbound;REAL ccwerrboundA, ccwerrboundB, ccwerrboundC;REAL iccerrboundA, iccerrboundB, iccerrboundC;REAL o3derrboundA, o3derrboundB, o3derrboundC;/* Random number seed is not constant, but I've made it global anyway. */unsigned long randomseed; /* Current random number seed. *//* Mesh data structure. Triangle operates on only one mesh, but the mesh *//* structure is used (instead of global variables) to allow reentrancy. */struct mesh {/* Variables used to allocate memory for triangles, subsegments, vertices, *//* viri (triangles being eaten), encroached segments, bad (skinny or too *//* large) triangles, and splay tree nodes. */ struct memorypool triangles; struct memorypool subsegs; struct memorypool vertices; struct memorypool viri; struct memorypool badsubsegs; struct memorypool badtriangles; struct memorypool flipstackers; struct memorypool splaynodes;/* Variables that maintain the bad triangle queues. The queues are *//* ordered from 4095 (highest priority) to 0 (lowest priority). */ struct badtriang *queuefront[4096]; struct badtriang *queuetail[4096]; int nextnonemptyq[4096]; int firstnonemptyq;/* Variable that maintains the stack of recently flipped triangles. */ struct flipstacker *lastflip;/* Other variables. */ REAL xmin, xmax, ymin, ymax; /* x and y bounds. */ REAL xminextreme; /* Nonexistent x value used as a flag in sweepline. */ int invertices; /* Number of input vertices. */ int inelements; /* Number of input triangles. */ int insegments; /* Number of input segments. */ int holes; /* Number of input holes. */ int regions; /* Number of input regions. */ int undeads; /* Number of input vertices that don't appear in the mesh. */ long edges; /* Number of output edges. */ int mesh_dim; /* Dimension (ought to be 2). */ int nextras; /* Number of attributes per vertex. */ int eextras; /* Number of attributes per triangle. */ long hullsize; /* Number of edges in convex hull. */ int steinerleft; /* Number of Steiner points not yet used. */ int vertexmarkindex; /* Index to find boundary marker of a vertex. */ int vertex2triindex; /* Index to find a triangle adjacent to a vertex. */ int highorderindex; /* Index to find extra nodes for high-order elements. */ int elemattribindex; /* Index to find attributes of a triangle. */ int areaboundindex; /* Index to find area bound of a triangle. */ int checksegments; /* Are there segments in the triangulation yet? */ int checkquality; /* Has quality triangulation begun yet? */ int readnodefile; /* Has a .node file been read? */ long samples; /* Number of random samples for point location. */ long incirclecount; /* Number of incircle tests performed. */ long counterclockcount; /* Number of counterclockwise tests performed. */ long orient3dcount; /* Number of 3D orientation tests performed. */ long hyperbolacount; /* Number of right-of-hyperbola tests performed. */ long circumcentercount; /* Number of circumcenter calculations performed. */ long circletopcount; /* Number of circle top calculations performed. *//* Triangular bounding box vertices. */ vertex infvertex1, infvertex2, infvertex3;/* Pointer to the `triangle' that occupies all of "outer space." */ triangle *dummytri; triangle *dummytribase; /* Keep base address so we can free() it later. *//* Pointer to the omnipresent subsegment. Referenced by any triangle or *//* subsegment that isn't really connected to a subsegment at that *//* location. */ subseg *dummysub; subseg *dummysubbase; /* Keep base address so we can free() it later. *//* Pointer to a recently visited triangle. Improves point location if *//* proximate vertices are inserted sequentially. */ struct otri recenttri;}; /* End of `struct mesh'. *//* Data structure for command line switches and file names. This structure *//* is used (instead of global variables) to allow reentrancy. */struct behavior {/* Switches for the triangulator. *//* poly: -p switch. refine: -r switch. *//* quality: -q switch. *//* minangle: minimum angle bound, specified after -q switch. *//* goodangle: cosine squared of minangle. *//* offconstant: constant used to place off-center Steiner points. *//* vararea: -a switch without number. *//* fixedarea: -a switch with number. *//* maxarea: maximum area bound, specified after -a switch. *//* usertest: -u switch. *//* regionattrib: -A switch. convex: -c switch. *//* weighted: 1 for -w switch, 2 for -W switch. jettison: -j switch *//* firstnumber: inverse of -z switch. All items are numbered starting *//* from `firstnumber'. *//* edgesout: -e switch. voronoi: -v switch. *//* neighbors: -n switch. geomview: -g switch. *//* nobound: -B switch. nopolywritten: -P switch. *//* nonodewritten: -N switch. noelewritten: -E switch. *//* noiterationnum: -I switch. noholes: -O switch. *//* noexact: -X switch. *//* order: element order, specified after -o switch. *//* nobisect: count of how often -Y switch is selected. *//* steiner: maximum number of Steiner points, specified after -S switch. *//* incremental: -i switch. sweepline: -F switch. *//* dwyer: inverse of -l switch. *//* splitseg: -s switch. *//* conformdel: -D switch. docheck: -C switch. *//* quiet: -Q switch. verbose: count of how often -V switch is selected. *//* usesegments: -p, -r, -q, or -c switch; determines whether segments are *//* used at all. *//* *//* Read the instructions to find out the meaning of these switches. */ int poly, refine, quality, vararea, fixedarea, usertest; int regionattrib, convex, weighted, jettison; int firstnumber; int edgesout, voronoi, neighbors, geomview; int nobound, nopolywritten, nonodewritten, noelewritten, noiterationnum; int noholes, noexact, conformdel; int incremental, sweepline, dwyer; int splitseg; int docheck; int quiet, verbose; int usesegments; int order; int nobisect; int steiner; REAL minangle, goodangle, offconstant; REAL maxarea;/* Variables for file names. */#ifndef TRILIBRARY char innodefilename[FILENAMESIZE]; char inelefilename[FILENAMESIZE]; char inpolyfilename[FILENAMESIZE]; char areafilename[FILENAMESIZE]; char outnodefilename[FILENAMESIZE]; char outelefilename[FILENAMESIZE]; char outpolyfilename[FILENAMESIZE]; char edgefilename[FILENAMESIZE]; char vnodefilename[FILENAMESIZE]; char vedgefilename[FILENAMESIZE]; char neighborfilename[FILENAMESIZE]; char offfilename[FILENAMESIZE];#endif /* not TRILIBRARY */}; /* End of `struct behavior'. *//*****************************************************************************//* *//* Mesh manipulation primitives. Each triangle contains three pointers to *//* other triangles, with orientations. Each pointer points not to the *//* first byte of a triangle, but to one of the first three bytes of a *//* triangle. It is necessary to extract both the triangle itself and the *//* orientation. To save memory, I keep both pieces of information in one *//* pointer. To make this possible, I assume that all triangles are aligned *//* to four-byte boundaries. The decode() routine below decodes a pointer, *//* extracting an orientation (in the range 0 to 2) and a pointer to the *//* beginning of a triangle. The encode() routine compresses a pointer to a *//* triangle and an orientation into a single pointer. My assumptions that *//* triangles are four-byte-aligned and that the `unsigned long' type is *//* long enough to hold a pointer are two of the few kludges in this program.*//* *//* Subsegments are manipulated similarly. A pointer to a subsegment *//* carries both an address and an orientation in the range 0 to 1. *//* *//* The other primitives take an oriented triangle or oriented subsegment, *//* and return an oriented triangle or oriented subsegment or vertex; or *//* they change the connections in the data structure. *//* *//* Below, triangles and subsegments are denoted by their vertices. The *//* triangle abc has origin (org) a, destination (dest) b, and apex (apex) *//* c. These vertices occur in counterclockwise order about the triangle. *//* The handle abc may simultaneously denote vertex a, edge ab, and triangle *//* abc. *//* *//* Similarly, the subsegment ab has origin (sorg) a and destination (sdest) *//* b. If ab is thought to be directed upward (with b directly above a), *//* then the handle ab is thought to grasp the right side of ab, and may *//* simultaneously denote vertex a and edge ab. *//* *//* An asterisk (*) denotes a vertex whose identity is unknown. *//* *//* Given this notation, a partial list of mesh manipulation primitives *//* follows. *//* *//* *//* For triangles: *//* *//* sym: Find the abutting triangle; same edge. *//* sym(abc) -> ba* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -