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

📄 triangle.shar

📁 用c语言编写的约束Delauney网格剖分程序源代码
💻 SHAR
📖 第 1 页 / 共 5 页
字号:
/*   following constants determine how many of each structure is allocated   *//*   at once.                                                                */#define TRIPERBLOCK 4092           /* Number of triangles allocated at once. */#define SHELLEPERBLOCK 508       /* Number of shell edges allocated at once. */#define POINTPERBLOCK 4092            /* Number of points allocated at once. */#define VIRUSPERBLOCK 1020   /* Number of virus triangles allocated at once. *//* Number of encroached segments allocated at once. */#define BADSEGMENTPERBLOCK 252/* Number of skinny triangles allocated at once. */#define BADTRIPERBLOCK 4092/* Number of splay tree nodes allocated at once. */#define SPLAYNODEPERBLOCK 508/* The point marker DEADPOINT is an arbitrary number chosen large enough to  *//*   (hopefully) not conflict with user boundary markers.  Make sure that it *//*   is small enough to fit into your machine's integer size.                */#define DEADPOINT -1073741824/* 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 <string.h>#include <math.h>#ifndef NO_TIMER#include <sys/time.h>#endif /* NO_TIMER */#ifdef TRILIBRARY#include "triangle.h"#endif /* TRILIBRARY *//* The following obscenity seems to be necessary to ensure that this program *//* will port to Dec Alphas running OSF/1, because their stdio.h file commits *//* the unpardonable sin of including stdlib.h.  Hence, malloc(), free(), and *//* exit() may or may not already be defined at this point.  I declare these  *//* functions explicitly because some non-ANSI C compilers lack stdlib.h.     */#ifndef _STDLIB_H_extern void *malloc();extern void free();extern void exit();extern double strtod();extern long strtol();#endif /* _STDLIB_H_ *//* A few forward declarations.                                               */void poolrestart();#ifndef TRILIBRARYchar *readline();char *findfield();#endif /* not TRILIBRARY *//* Labels that signify whether a record consists primarily of pointers or of *//*   floating-point words.  Used to make decisions about data alignment.     */enum wordtype {POINTER, FLOATINGPOINT};/* 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 site insertion.  The result indicates   *//*   that the point was inserted with complete success, was inserted but     *//*   encroaches on a segment, was not inserted because it lies on a segment, *//*   or was not inserted because another point occupies the same location.   */enum insertsiteresult {SUCCESSFULPOINT, ENCROACHINGPOINT, VIOLATINGPOINT,                       DUPLICATEPOINT};/* 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};/* Labels that signify the result of the circumcenter computation routine.   *//*   The return value indicates which edge of the triangle is shortest.      */enum circumcenterresult {OPPOSITEORG, OPPOSITEDEST, OPPOSITEAPEX};/*****************************************************************************//*                                                                           *//*  The basic mesh data structures                                           *//*                                                                           *//*  There are three:  points, triangles, and shell edges (abbreviated        *//*  `shelle').  These three data structures, linked by pointers, comprise    *//*  the mesh.  A point simply represents a point in space and its properties.*//*  A triangle is a triangle.  A shell edge is a special data structure used *//*  to represent impenetrable segments in the mesh (including the outer      *//*  boundary, boundaries of holes, and internal boundaries separating two    *//*  triangulated regions).  Shell edges 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 shell edges (when shell   *//*  edges are used), 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 shell edges are present.  Such absent         *//*  triangles and shell edges are never represented by NULL pointers; they   *//*  are represented by two special records:  `dummytri', the triangle that   *//*  fills "outer space", and `dummysh', the omnipresent shell edge.          *//*  `dummytri' and `dummysh' are used for several reasons; for instance,     *//*  they can be dereferenced and their contents examined without causing the *//*  memory protection exception that would occur if NULL were dereferenced.  *//*                                                                           *//*  However, it is important to understand that a triangle includes other    *//*  information as well.  The pointers to adjoining vertices, triangles, and *//*  shell edges 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  *//*  shell edge indicates which side of that shell edge is contacted, and how *//*  the shell edge is oriented relative to the triangle.                     *//*                                                                           *//*  Shell edges are found abutting edges of triangles; either sandwiched     *//*  between two triangles, or resting against one triangle on an exterior    *//*  boundary or hole boundary.                                               *//*                                                                           *//*  A shell edge consists of a list of two vertices, a list of two           *//*  adjoining shell edges, and a list of two adjoining triangles.  One of    *//*  the two adjoining triangles may not be present (though there should      *//*  always be one), and neighboring shell edges might not be present.        *//*  Shell edges also store a user-defined integer "boundary marker".         *//*  Typically, this integer is used to indicate what sort of boundary        *//*  conditions are to be applied at that location in a finite element        *//*  simulation.                                                              *//*                                                                           *//*  Like triangles, shell edges maintain information about the relative      *//*  orientation of neighboring objects.                                      *//*                                                                           *//*  Points are relatively simple.  A point is a list of floating point       *//*  numbers, starting with the x, and y coordinates, followed by an          *//*  arbitrary number of optional user-defined floating-point attributes,     *//*  followed by an integer boundary marker.  During the segment insertion    *//*  phase, there is also a pointer from each point to a triangle that may    *//*  contain it.  Each pointer is not always correct, but when one is, it     *//*  speeds up segment insertion.  These pointers are assigned values once    *//*  at the beginning of the segment insertion phase, and are not used or     *//*  updated at any other time.  Edge swapping during segment insertion will  *//*  render some of them incorrect.  Hence, don't rely upon them for          *//*  anything.  For the most part, points do not have any information about   *//*  what triangles or shell edges they are linked to.                        *//*                                                                           *//*****************************************************************************//*****************************************************************************//*                                                                           *//*  Handles                                                                  *//*                                                                           *//*  The oriented triangle (`triedge') and oriented shell edge (`edge') data  *//*  structures defined below do not themselves store any part of the mesh.   *//*  The mesh itself is made of `triangle's, `shelle's, and `point's.         *//*                                                                           *//*  Oriented triangles and oriented shell edges will usually be referred to  *//*  as "handles".  A handle is essentially a pointer into the mesh; it       *//*  allows you to "hold" one particular part of the mesh.  Handles are used  *//*  to specify the regions in which one is traversing and modifying the mesh.*//*  A single `triangle' may be held by many handles, or none at all.  (The   *//*  latter case is not a memory leak, because the triangle is still          *//*  connected to other triangles in the mesh.)                               *//*                                                                           *//*  A `triedge' is a handle that holds a triangle.  It holds a specific side *//*  of the triangle.  An `edge' is a handle that holds a shell edge.  It     *//*  holds either the left or right side of the edge.                         *//*                                                                           *//*  Navigation about the mesh is accomplished through a set of mesh          *//*  manipulation primitives, further below.  Many of these primitives take   *//*  a handle and produce a new handle that holds the mesh near the first     *//*  handle.  Other primitives take two handles and glue the corresponding    *//*  parts of the mesh together.  The exact position of the handles is        *//*  important.  For instance, when two triangles are glued together by the   *//*  bond() primitive, they are glued by the sides on which the handles lie.  *//*                                                                           *//*  Because points have no information about which triangles they are        *//*  attached to, I commonly represent a point by use of a handle whose       *//*  origin is the point.  A single handle can simultaneously represent a     *//*  triangle, an edge, and a point.                                          *//*                                                                           *//*****************************************************************************//* The triangle data structure.  Each triangle contains three pointers to    *//*   adjoining triangles, plus three pointers to vertex points, plus three   *//*   pointers to shell edges (defined below; these pointers are usually      *//*   `dummysh').  It may or may not also contain user-defined attributes     *//*   and/or a floating-point "area constraint".  It may also contain extra   *//*   pointers for nodes, when the user asks for high-order elements.         *//*   Because the size and structure of a `triangle' is not decided until     *//*   runtime, I haven't simply defined the type `triangle' to be a struct.   */typedef REAL **triangle;            /* Really:  typedef triangle *triangle   *//* An oriented triangle:  includes a pointer to a triangle and orientation.  *//*   The orientation denotes an edge of the triangle.  Hence, there are      *//*   three possible orientations.  By convention, each edge is always        */

⌨️ 快捷键说明

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