// Verifies consistency of DCEL for lab 2, Spring 2005 // 3/3/05 BPW // 3/5/05 Added detection of adjacent "flat" faces BPW /* Define vertex indices. */ #define X 0 #define Y 1 #define Z 2 typedef enum { FALSE, TRUE } bool; int V,F,E; typedef struct tVertexStructure tsVertex; typedef tsVertex *tVertex; typedef struct tFaceStructure tsFace; typedef tsFace *tFace; typedef struct tEdgeStructure tsEdge; typedef tsEdge *tEdge; struct tVertexStructure { int coord[3]; int Enum; // Incident half-edge number }; struct tFaceStructure { int Enum; // First half-edge }; struct tEdgeStructure { int tail; // Vertex number for tail int twin; // Number of reverse half-edge int face; // Face number int nextEnum, // For doubly-linked list around face prevEnum; }; // Three tables - loaded from file tVertex vertex; tFace face; tEdge edge; typedef int tPointi[3]; /* Type integer point */ int VolumeSign( tPointi a, tPointi b, tPointi c, tPointi d ) { double vol; double ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz; double bxdx, bydy, bzdz, cxdx, cydy, czdz; ax = a[X]; ay = a[Y]; az = a[Z]; bx = b[X]; by = b[Y]; bz = b[Z]; cx = c[X]; cy = c[Y]; cz = c[Z]; dx = d[X]; dy = d[Y]; dz = d[Z]; bxdx=bx-dx; bydy=by-dy; bzdz=bz-dz; cxdx=cx-dx; cydy=cy-dy; czdz=cz-dz; vol = (az-dz) * (bxdx*cydy - bydy*cxdx) + (ay-dy) * (bzdz*cxdx - bxdx*czdz) + (ax-dx) * (bydy*czdz - bzdz*cydy); /* The volume should be an integer. */ if ( vol > 0.5 ) return 1; else if ( vol < -0.5 ) return -1; else return 0; } void readVertices() { int i; // Read vertices and do range check for (i=0;i=E) { printf("Fatal at %d\n",__LINE__); exit(0); } } } void readFaces() { int i; // Read faces and do range check for (i=0;i=E) { printf("Fatal at %d\n",__LINE__); exit(0); } } } void readEdges() { int i; // Read edges and range checks for (i=0;i=V) { printf("Fatal at %d\n",__LINE__); exit(0); } if (edge[i].twin<0 || edge[i].twin>=E) { printf("Fatal at %d\n",__LINE__); exit(0); } if (edge[i].face<0 || edge[i].face>=F) { printf("Fatal at %d\n",__LINE__); exit(0); } if (edge[i].nextEnum<0 || edge[i].nextEnum>=E) { printf("Fatal at %d\n",__LINE__); exit(0); } if (edge[i].prevEnum<0 || edge[i].prevEnum>=E) { printf("Fatal at %d\n",__LINE__); exit(0); } } } bool checkConsistency() { int i,j,edgesTouched; int a,b,c,d; bool clean=TRUE; // Consistency between tables for (i=0;i