📄 tetgen.h
字号:
// //// The Metric tensor data structure //// //// A metric is a function that specifies the "distance" between two points //// in a metric space E. Recall if d(p, q) is a metric of E, then we have: //// (1) d(p, q) = d(q, p). (d is symmetric) //// (2) d(p, q) = 0 if and only if p = q. //// (3) d(p, x) + d(x, q) >= d(p, q). (d satisfies triangle inequality) //// //// In d dimensions, the metric tensor of a point p is a (dxd) symmetric //// positive definie (non-degenerate) matrix M(p). Very roughly, it tells how //// to compute the distance of p and other points in the metric space of p. //// d_M(p, q) = \sqrt{(p - q)' M (p -q)}. //// If for any point p, a metric tensor M(p) is given, the field of tensors //// thus defines a Riemannian space. For example, if M(q) is a metric tensor //// defined on q. Then the distance d(p, q) can be calculated by: //// d(p, q) = \int_{0}{1} \sqrt((p - q)' M(t) (p - q)) dt. //// where M(t) is the interpolation of metric tensors between p and q, M(0) = //// M(p) and M(1) = M(q). //// //// A metric tensor in three dimension, for example, is a matrix: //// | a b c | //// M = | b d e | //// | c e f | //// such that a > 0, d > 0, f > 0, det(M) = adf + 2bce -ccd - eea - bbf > 0. //// //// It is defined as an array mat[6] = {a, b, c, d, e, f}. Operation on //// tensors are defined as well. //// ///////////////////////////////////////////////////////////////////////////////// class metric { public: REAL mat[6]; // Initialization. void init() {for (int i = 0; i < 6; i++) mat[i] = 0.0;} void set(REAL a, REAL b, REAL c, REAL d, REAL e, REAL f) { mat[0] = a; mat[1] = b; mat[2] = c; mat[3] = d; mat[4] = e; mat[5] = f; } void set(REAL a, REAL d, REAL f) { mat[0] = a; mat[1] = 0.0; mat[2] = 0.0; mat[3] = d; mat[4] = 0.0; mat[5] = f; } // Constructors. metric() {init();} };///////////////////////////////////////////////////////////////////////////////// //// The list, link and queue data structures //// //// These data types are used to manipulate a set of (same-typed) data items. //// For a given set S = {a, b, c, ...}, a list stores the elements of S in a //// piece of continuous memory. It allows quickly accessing each element of S,//// thus is suitable for storing a fix-sized set. While a link stores its //// elements incontinuously. It allows quickly inserting or deleting an item, //// thus is suitable for storing a size-variable set. A queue is basically a //// special case of a link where one data element joins the link at the end //// and leaves in an ordered fashion at the other end. //// ///////////////////////////////////////////////////////////////////////////////// // The compfunc data type. "compfunc" is a pointer to a linear-order // function, which takes two 'void*' arguments and returning an 'int'. // // A function: int cmp(const T &, const T &), is said to realize a // linear order on the type T if there is a linear order <= on T such // that for all x and y in T satisfy the following relation: // -1 if x < y. // comp(x, y) = 0 if x is equivalent to y. // +1 if x > y. typedef int (*compfunc) (const void *, const void *); // The predefined compare functions for primitive data types. They // take two pointers of the corresponding date type, perform the // comparation, and return -1, 0 or 1 indicating the default linear // order of them. // Compare two 'integers'. static int compare_2_ints(const void* x, const void* y); // Compare two 'longs'. static int compare_2_longs(const void* x, const void* y); // Compare two 'unsigned longs'. static int compare_2_unsignedlongs(const void* x, const void* y); // The function used to determine the size of primitive data types and // set the corresponding predefined linear order functions for them. static void set_compfunc(const char* str, int* itembytes, compfunc* pcomp);///////////////////////////////////////////////////////////////////////////////// //// List data structure. //// //// A 'list' is an array of items with automatically reallocation of memory. //// It behaves like an array. //// //// 'base' is the starting address of the array; The memory unit in list is //// byte, i.e., sizeof(char). 'itembytes' is the size of each item in byte, //// so that the next item in list will be found at the next 'itembytes' //// counted from the current position. //// //// 'items' is the number of items stored in list. 'maxitems' indicates how //// many items can be stored in this list. 'expandsize' is the increasing //// size (items) when the list is full. //// //// 'comp' is a pointer pointing to a linear order function for the list. //// default it is set to 'NULL'. //// //// The index of list always starts from zero, i.e., for a list L contains //// n elements, the first element is L[0], and the last element is L[n-1]. //// This feature lets lists like C/C++ arrays. //// ///////////////////////////////////////////////////////////////////////////////// class list { public: char *base; int itembytes; int items, maxitems, expandsize; compfunc comp; public: list(int itbytes, compfunc pcomp, int mitems = 256, int exsize = 128) { listinit(itbytes, pcomp, mitems, exsize); } list(const char* str, int mitems = 256, int exsize = 128) { set_compfunc(str, &itembytes, &comp); listinit(itembytes, comp, mitems, exsize); } ~list() { free(base); } void *operator[](int i) { return (void *) (base + i * itembytes); } void listinit(int itbytes, compfunc pcomp, int mitems, int exsize); void setcomp(compfunc compf) { comp = compf; } void clear() { items = 0; } int len() { return items; } void *append(void* appitem); void *insert(int pos, void* insitem); void del(int pos, int order); int hasitem(void* checkitem); void sort(); }; ///////////////////////////////////////////////////////////////////////////////// //// Memorypool data structure. //// //// A type used to allocate memory. (It is incorporated from Shewchuk's //// Triangle program) //// //// firstblock is the first block of items. nowblock is the block from which //// items are currently being allocated. nextitem points to the next slab //// of free memory for an item. deaditemstack is the head of a linked list //// (stack) of deallocated items that can be recycled. unallocateditems is //// the number of items that remain to be allocated from nowblock. //// //// Traversal is the process of walking through the entire list of items, and //// is separate from allocation. Note that a traversal will visit items on //// the "deaditemstack" stack as well as live items. pathblock points to //// the block currently being traversed. pathitem points to the next item //// to be traversed. pathitemsleft is the number of items that remain to //// be traversed in pathblock. //// //// itemwordtype is set to POINTER or FLOATINGPOINT, and is used to suggest //// what sort of word the record is primarily made up of. alignbytes //// determines how new records should be aligned in memory. itembytes and //// itemwords are the length of a record in bytes (after rounding up) and //// words. itemsperblock is the number of items allocated at once in a //// single block. items is the number of currently allocated items. //// maxitems is the maximum number of items that have been allocated at //// once; it is the current number of items plus the number of records kept //// on deaditemstack. //// ///////////////////////////////////////////////////////////////////////////////// class memorypool { public: void **firstblock, **nowblock; void *nextitem; void *deaditemstack; void **pathblock; void *pathitem; wordtype itemwordtype; int alignbytes; int itembytes, itemwords; int itemsperblock; long items, maxitems; int unallocateditems; int pathitemsleft; public: memorypool(); memorypool(int, int, enum wordtype, int); ~memorypool(); void poolinit(int, int, enum wordtype, int); void restart(); void *alloc(); void dealloc(void*); void traversalinit(); void *traverse(); }; ///////////////////////////////////////////////////////////////////////////////// //// Link data structure. //// //// A 'link' is a double linked nodes. It uses the memorypool data structure //// for memory management. Following is an image of a link. //// //// head-> ____0____ ____1____ ____2____ _________<-tail //// |__next___|--> |__next___|--> |__next___|--> |__NULL___| //// |__NULL___|<-- |__prev___|<-- |__prev___|<-- |__prev___| //// | | |_ _| |_ _| | | ///
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -