⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triangle.c

📁 一个用于三角剖分的类.实用性非常好。对于需要从多边形
💻 C
📖 第 1 页 / 共 5 页
字号:
#define REAL double#endif /* not SINGLE *//* If yours is not a Unix system, define the NO_TIMER compiler switch to     *//*   remove the Unix-specific timing code.                                   *//* #define NO_TIMER *//* To insert lots of self-checks for internal errors, define the SELF_CHECK  *//*   symbol.  This will slow down the program significantly.  It is best to  *//*   define the symbol using the -DSELF_CHECK compiler switch, but you could *//*   write "#define SELF_CHECK" below.  If you are modifying this code, I    *//*   recommend you turn self-checks on until your work is debugged.          *//* #define SELF_CHECK *//* To compile Triangle as a callable object library (triangle.o), define the *//*   TRILIBRARY symbol.  Read the file triangle.h for details on how to call *//*   the procedure triangulate() that results.                               *//* #define TRILIBRARY *//* It is possible to generate a smaller version of Triangle using one or     *//*   both of the following symbols.  Define the REDUCED symbol to eliminate  *//*   all features that are primarily of research interest; specifically, the *//*   -i, -F, -s, and -C switches.  Define the CDT_ONLY symbol to eliminate   *//*   all meshing algorithms above and beyond constrained Delaunay            *//*   triangulation; specifically, the -r, -q, -a, -u, -D, -S, and -s         *//*   switches.  These reductions are most likely to be useful when           *//*   generating an object library (triangle.o) by defining the TRILIBRARY    *//*   symbol.                                                                 *//* #define REDUCED *//* #define CDT_ONLY *//* On some machines, my exact arithmetic routines might be defeated by the   *//*   use of internal extended precision floating-point registers.  The best  *//*   way to solve this problem is to set the floating-point registers to use *//*   single or double precision internally.  On 80x86 processors, this may   *//*   be accomplished by setting the CPU86 symbol for the Microsoft C         *//*   compiler, or the LINUX symbol for the gcc compiler running on Linux.    *//*                                                                           *//* An inferior solution is to declare certain values as `volatile', thus     *//*   forcing them to be stored to memory and rounded off.  Unfortunately,    *//*   this solution might slow Triangle down quite a bit.  To use volatile    *//*   values, write "#define INEXACT volatile" below.  Normally, however,     *//*   INEXACT should be defined to be nothing.  ("#define INEXACT".)          *//*                                                                           *//* For more discussion, see http://www.cs.cmu.edu/~quake/robust.pc.html .    *//*   For yet more discussion, see Section 5 of my paper, "Adaptive Precision *//*   Floating-Point Arithmetic and Fast Robust Geometric Predicates" (also   *//*   available as Section 6.6 of my dissertation).                           *//* #define CPU86 *//* #define LINUX */#define INEXACT /* Nothing *//* #define INEXACT volatile *//* Maximum number of characters in a file name (including the null).         */#define FILENAMESIZE 2048/* Maximum number of characters in a line read from a file (including the    *//*   null).                                                                  */#define INPUTLINESIZE 1024/* For efficiency, a variety of data structures are allocated in bulk.  The  *//*   following constants determine how many of each structure is allocated   *//*   at once.                                                                */#define TRIPERBLOCK 4092           /* Number of triangles allocated at once. */#define SUBSEGPERBLOCK 508       /* Number of subsegments allocated at once. */#define VERTEXPERBLOCK 4092         /* Number of vertices allocated at once. */#define VIRUSPERBLOCK 1020   /* Number of virus triangles allocated at once. *//* Number of encroached subsegments allocated at once. */#define BADSUBSEGPERBLOCK 252/* Number of skinny triangles allocated at once. */#define BADTRIPERBLOCK 4092/* Number of flipped triangles allocated at once. */#define FLIPSTACKERPERBLOCK 252/* Number of splay tree nodes allocated at once. */#define SPLAYNODEPERBLOCK 508/* The vertex types.   A DEADVERTEX has been deleted entirely.  An           *//*   UNDEADVERTEX is not part of the mesh, but is written to the output      *//*   .node file and affects the node indexing in the other output files.     */#define INPUTVERTEX 0#define SEGMENTVERTEX 1#define FREEVERTEX 2#define DEADVERTEX -32768#define UNDEADVERTEX -32767/* The next line is used to outsmart some very stupid compilers.  If your    *//*   compiler is smarter, feel free to replace the "int" with "void".        *//*   Not that it matters.                                                    */#define VOID int/* Two constants for algorithms based on random sampling.  Both constants    *//*   have been chosen empirically to optimize their respective algorithms.   *//* Used for the point location scheme of Mucke, Saias, and Zhu, to decide    *//*   how large a random sample of triangles to inspect.                      */#define SAMPLEFACTOR 11/* Used in Fortune's sweepline Delaunay algorithm to determine what fraction *//*   of boundary edges should be maintained in the splay tree for point      *//*   location on the front.                                                  */#define SAMPLERATE 10/* A number that speaks for itself, every kissable digit.                    */#define PI 3.141592653589793238462643383279502884197169399375105820974944592308/* Another fave.                                                             */#define SQUAREROOTTWO 1.4142135623730950488016887242096980785696718753769480732/* And here's one for those of you who are intimidated by math.              */#define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#ifndef NO_TIMER#include <sys/time.h>#endif /* not NO_TIMER */#ifdef CPU86#include <float.h>#endif /* CPU86 */#ifdef LINUX#include <fpu_control.h>#endif /* LINUX */#ifdef TRILIBRARY#include "triangle.h"#endif /* TRILIBRARY *//* A few forward declarations.                                               */#ifndef TRILIBRARYchar *readline();char *findfield();#endif /* not TRILIBRARY *//* Labels that signify the result of point location.  The result of a        *//*   search indicates that the point falls in the interior of a triangle, on *//*   an edge, on a vertex, or outside the mesh.                              */enum locateresult {INTRIANGLE, ONEDGE, ONVERTEX, OUTSIDE};/* Labels that signify the result of vertex insertion.  The result indicates *//*   that the vertex was inserted with complete success, was inserted but    *//*   encroaches upon a subsegment, was not inserted because it lies on a     *//*   segment, or was not inserted because another vertex occupies the same   *//*   location.                                                               */enum insertvertexresult {SUCCESSFULVERTEX, ENCROACHINGVERTEX, VIOLATINGVERTEX,                         DUPLICATEVERTEX};/* Labels that signify the result of direction finding.  The result          *//*   indicates that a segment connecting the two query points falls within   *//*   the direction triangle, along the left edge of the direction triangle,  *//*   or along the right edge of the direction triangle.                      */enum finddirectionresult {WITHIN, LEFTCOLLINEAR, RIGHTCOLLINEAR};/*****************************************************************************//*                                                                           *//*  The basic mesh data structures                                           *//*                                                                           *//*  There are three:  vertices, triangles, and subsegments (abbreviated      *//*  `subseg').  These three data structures, linked by pointers, comprise    *//*  the mesh.  A vertex simply represents a mesh vertex and its properties.  *//*  A triangle is a triangle.  A subsegment is a special data structure used *//*  to represent an impenetrable edge of the mesh (perhaps on the outer      *//*  boundary, on the boundary of a hole, or part of an internal boundary     *//*  separating two triangulated regions).  Subsegments represent boundaries, *//*  defined by the user, that triangles may not lie across.                  *//*                                                                           *//*  A triangle consists of a list of three vertices, a list of three         *//*  adjoining triangles, a list of three adjoining subsegments (when         *//*  segments exist), an arbitrary number of optional user-defined            *//*  floating-point attributes, and an optional area constraint.  The latter  *//*  is an upper bound on the permissible area of each triangle in a region,  *//*  used for mesh refinement.                                                *//*                                                                           *//*  For a triangle on a boundary of the mesh, some or all of the neighboring *//*  triangles may not be present.  For a triangle in the interior of the     *//*  mesh, often no neighboring subsegments are present.  Such absent         *//*  triangles and subsegments are never represented by NULL pointers; they   *//*  are represented by two special records:  `dummytri', the triangle that   *//*  fills "outer space", and `dummysub', the omnipresent subsegment.         *//*  `dummytri' and `dummysub' are used for several reasons; for instance,    *//*  they can be dereferenced and their contents examined without violating   *//*  protected memory.                                                        *//*                                                                           *//*  However, it is important to understand that a triangle includes other    *//*  information as well.  The pointers to adjoining vertices, triangles, and *//*  subsegments are ordered in a way that indicates their geometric relation *//*  to each other.  Furthermore, each of these pointers contains orientation *//*  information.  Each pointer to an adjoining triangle indicates which face *//*  of that triangle is contacted.  Similarly, each pointer to an adjoining  *//*  subsegment indicates which side of that subsegment is contacted, and how *//*  the subsegment is oriented relative to the triangle.                     *//*                                                                           *//*  The data structure representing a subsegment may be thought to be        *//*  abutting the edge of one or two triangle data structures:  either        *//*  sandwiched between two triangles, or resting against one triangle on an  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -