/* See {CubeLAPL.h} */ #include /* Last edited on 2007-02-04 19:07:13 by stolfi */ #define CubeLAPL_C_COPYRIGHT \ "Copyright © 2000,2007 Universidade Estadual de Campinas (UNICAMP)" #include #include #include #include #include #include #include #include #include #include void SetCubeInteriorCell(Place_t p, Cell_t n); /* Set to {n} the cell slot of the 24 places of the cube's interior. */ EightNodes_t CubeNegNodes(Place_t p) { Node_t n0 = OrgV(p); Node_t n1 = OrgV(PrevE(p)); Node_t n2 = OrgV(PrevE(PrevE(p))); Node_t n3 = OrgV(PrevE(PrevF(PrevE(p)))); assert((n0 != n1)); assert((n0 != n2) && (n1 != n2)); assert((n0 != n3) && (n1 != n3) && (n2 != n3)); Place_t b = Clock(NextF(PrevE(PrevE(PrevF(p))))); assert(PnegP(p) == PposP(b)); Node_t m0 = OrgV(b); Node_t m1 = OrgV(PrevE(b)); Node_t m2 = OrgV(PrevE(PrevE(b))); Node_t m3 = OrgV(PrevE(PrevF(PrevE(b)))); assert((m0 != m1)); assert((m0 != m2) && (m1 != m2)); assert((m0 != m3) && (m1 != m3) && (m2 != m3)); return (EightNodes_t){{n0,n1,n2,n3,m0,m1,m2,m3}}; } r4_t CubeBarycenter(Place_t a, Coords_t *c) { r4_t sum = (r4_t){{0,0,0,0}}; EightNodes_t v = CubeNegNodes(a); int i; for (i = 0; i < 8; i++) { r4_t *pi = &(c->e[v.v[i]->num]); r4_add(pi, &sum, &sum); } r4_scale(1.0/8.0, &sum, &sum); return sum; } SixPlaces_t CubeLAPLMake(void) { auto Place_t CEE(Place_t p); /* Short for {Clock(NextE(NextE(p)))}. */ Place_t CEE(Place_t p) { return Clock(NextE(NextE(p))); } SixPlaces_t co; int i; for (i = 0; i < 6; i++){ co.p[i] = MakeSquare(); } /* Glue Walls */ SetNextF(co.p[1], CEE(co.p[2])); /* 1-2 */ SetEdgeInfo(co.p[1], PEdge(CEE(co.p[2]))); SetOrgAll(co.p[1], OrgV(co.p[1])); SetOrgAll(Clock(co.p[1]), OrgV(Clock(co.p[1]))); SetNextF(co.p[2], CEE(co.p[3])); /* 2-3 */ SetEdgeInfo(co.p[2], PEdge(CEE(co.p[3]))); SetOrgAll(co.p[2], OrgV(co.p[2])); SetOrgAll(Clock(co.p[2]), OrgV(Clock(co.p[2]))); SetNextF(co.p[3], CEE(co.p[4])); /* 3-4 */ SetEdgeInfo(co.p[3], PEdge(CEE(co.p[4]))); SetOrgAll(co.p[3], OrgV(co.p[3])); SetOrgAll(Clock(co.p[3]), OrgV(Clock(co.p[3]))); SetNextF(co.p[4], CEE(co.p[1])); /* 4-1 */ SetEdgeInfo(co.p[4], PEdge(CEE(co.p[1]))); SetOrgAll(co.p[4], OrgV(co.p[4])); SetOrgAll(Clock(co.p[4]), OrgV(Clock(co.p[4]))); SetNextF(PrevE(co.p[1]), Clock(NextE(co.p[0]))); /* 1-0 */ SetEdgeInfo(PrevE(co.p[1]), PEdge(Clock(NextE(co.p[0])))); SetOrgAll(PrevE(co.p[1]), OrgV(PrevE(co.p[1]))); SetOrgAll(Clock(PrevE(co.p[1])), OrgV(Clock(PrevE(co.p[1])))); SetNextF(PrevE(co.p[5]), Clock(NextE(co.p[1]))); /* 5-1 */ SetEdgeInfo(PrevE(co.p[5]), PEdge(Clock(NextE(co.p[1])))); SetOrgAll(PrevE(co.p[5]), OrgV(PrevE(co.p[5]))); SetOrgAll(Clock(PrevE(co.p[5])), OrgV(Clock(PrevE(co.p[5])))); SetNextF(co.p[5], Clock(NextE(co.p[2]))); /* 5-2 */ SetEdgeInfo(co.p[5], PEdge(Clock(NextE(co.p[2])))); SetOrgAll(co.p[5], OrgV(co.p[5])); SetOrgAll(Clock(co.p[5]), OrgV(Clock(co.p[5]))); SetNextF(NextE(co.p[5]), Clock(NextE(co.p[3]))); /* 5-3 */ SetEdgeInfo(NextE(co.p[5]), PEdge(Clock(NextE(co.p[3])))); SetOrgAll(NextE(co.p[5]), OrgV(NextE(co.p[5]))); SetOrgAll(Clock(NextE(co.p[5])), OrgV(Clock(NextE(co.p[5])))); SetNextF(NextE(NextE(co.p[5])), Clock(NextE(co.p[4]))); /* 5-4 */ SetEdgeInfo(NextE(NextE(co.p[5])), PEdge(Clock(NextE(co.p[4])))); SetOrgAll(NextE(NextE(co.p[5])), OrgV(NextE(NextE(co.p[5])))); SetOrgAll(Clock(NextE(NextE(co.p[5]))), OrgV(Clock(NextE(NextE(co.p[5]))))); SetNextF(co.p[0], Clock(PrevE(co.p[2]))); /* 0-2 */ SetEdgeInfo(co.p[0], PEdge(Clock(PrevE(co.p[2])))); SetOrgAll(co.p[0], OrgV(co.p[0])); SetOrgAll(Clock(co.p[0]), OrgV(Clock(co.p[0]))); SetNextF(PrevE(co.p[0]), Clock(PrevE(co.p[3]))); /* 0-3 */ SetEdgeInfo(PrevE(co.p[0]), PEdge(Clock(PrevE(co.p[3])))); SetOrgAll(PrevE(co.p[0]), OrgV(PrevE(co.p[0]))); SetOrgAll(Clock(PrevE(co.p[0])), OrgV(Clock(PrevE(co.p[0])))); SetNextF(NextE(NextE(co.p[0])), Clock(PrevE(co.p[4]))); /* 0-4 */ SetEdgeInfo(NextE(NextE(co.p[0])), PEdge(Clock(PrevE(co.p[4])))); SetOrgAll(NextE(NextE(co.p[0])), OrgV(NextE(NextE(co.p[0])))); SetOrgAll(Clock(NextE(NextE(co.p[0]))), OrgV(Clock(NextE(NextE(co.p[0]))))); Cell_t q = MakeCell(0); SetCubeInteriorCell(co.p[0], q); return co; } Place_t GlueCube(Place_t a, Place_t b) /* Make the glueing of two simples cubes around of one squared wall common. The place {a} and theirs adjacents with the same wall component is killed. */ { Meld(a,b); /* Update the edge slots: */ SetRingEdgeInfo(b, PEdge(b)); SetRingEdgeInfo(NextE(b), PEdge(NextE(b))); SetRingEdgeInfo(NextE(NextE(b)), PEdge(NextE(NextE(b)))); SetRingEdgeInfo(NextE(NextE(NextE(b))), PEdge(NextE(NextE(NextE(b))))); /* Update the node slots: */ SetOrgAll(b, OrgV(b)); SetOrgAll(NextE(b), OrgV(NextE(b))); SetOrgAll(NextE(NextE(b)), OrgV(NextE(NextE(b)))); SetOrgAll(NextE(NextE(NextE(b))), OrgV(NextE(NextE(NextE(b))))); SetOrgAll(Clock(b), OrgV(Clock(b))); SetOrgAll(Clock(NextE(b)), OrgV(Clock(NextE(b)))); SetOrgAll(Clock(NextE(NextE(b))), OrgV(Clock(NextE(NextE(b))))); SetOrgAll(Clock(NextE(NextE(NextE(b)))), OrgV(Clock(NextE(NextE(NextE(b)))))); /* Update the cell slots: */ SetPneg(b, PnegP(a)); SetPneg(PrevE(b), PnegP(PrevE(a))); SetPneg(PrevE(PrevE(b)), PnegP(PrevE(PrevE(a)))); SetPneg(PrevE(PrevE(PrevE(b))), PnegP(PrevE(PrevE(PrevE(a))))); return b; } void SetCubeInteriorCell(Place_t p, Cell_t n) { Place_t t = p; SetPnegOfNearbyWalls(t, n); do { SetPnegOfNearbyWalls(Clock(PrevF(t)),n); t = PrevE(t); } while (t != p); t = PrevF(PrevE(PrevE(PrevF(p)))); SetPnegOfNearbyWalls(t,n); } void FixCoordsCube(SixPlaces_t *ca, ElemTableRec_t *top, Coords_t *c) { r4_t o1 = (r4_t){{ 1.0, 1.0, 1.0,1.0}}; /* the node ( 1, 1, 1,1) */ r4_t o2 = (r4_t){{ 1.0, 1.0,-1.0,1.0}}; /* the node ( 1, 1,-1,1) */ r4_t o3 = (r4_t){{ 1.0,-1.0, 1.0,1.0}}; /* the node ( 1,-1, 1,1) */ r4_t o4 = (r4_t){{ 1.0,-1.0,-1.0,1.0}}; /* the node ( 1,-1,-1,1) */ r4_t o5 = (r4_t){{-1.0, 1.0, 1.0,1.0}}; /* the node (-1, 1, 1,1) */ r4_t o6 = (r4_t){{-1.0, 1.0,-1.0,1.0}}; /* the node (-1, 1,-1,1) */ r4_t o7 = (r4_t){{-1.0,-1.0, 1.0,1.0}}; /* the node (-1,-1, 1,1) */ r4_t o8 = (r4_t){{-1.0,-1.0,-1.0,1.0}}; /* the node (-1,-1,-1,1) */ auto void SetCornerCoords(Place_t e, r4_t *cv); void SetCornerCoords(Place_t e, r4_t *cv) { c->e[OrgV(e)->num] = (*cv); } /* Set the corners */ SetCornerCoords(ca->p[5], &o1); SetCornerCoords(ca->p[1], &o2); SetCornerCoords(Clock(ca->p[4]),&o3); SetCornerCoords(ca->p[4], &o4); SetCornerCoords(Clock(ca->p[5]),&o5); SetCornerCoords(ca->p[2], &o6); SetCornerCoords(Clock(ca->p[3]),&o7); SetCornerCoords(ca->p[3], &o8); } #define CubeLAPL_C_author \ "Created by L. A. P. Lozada, 2000.\n" \ "Modification history:\n" \ " 27-10-2000 : Modified {SetCubeProperties} procedure.\n" \ " 04-11-2000 : Added the {CubeNegNodes} and {CubeBarycenter} procedures.\n" \ " 26-01-2007 : Converted to C by J. Stolfi; got {FixCoordsCube}\n" \ " from {MakeBigCubeFixed.c}."