#ifndef Tridimensional_H #define Tridimensional_H /* Last edited on 2009-02-10 09:24:25 by stolfi */ /* Procedures that Write/Read a tridimensional state (.st3) and compute some 3D geometric operations. */ #define Tridimensional_H_copyright \ "Copyright © 2000 Universidade Estadual de Campinas (UNICAMP)" #include #include #include #include #include #define _GNU_SOURCE #include typedef r3_vec_t Coords3D_t; typedef struct TetraData_t { uint p0, p1, p2, p3; r3x3_t A; double density, alpha, beta; } TetraData_t; vec_typedef(TetraData_vec_t,TetraData_vec,TetraData_t); /* A vector of {TetraData_t} */ r3_t Barycenter3D(ElemTableRec_t *too, Coords3D_t *c3); /* Returns the barycenter of all existing nodes. */ void Displace3D(ElemTableRec_t *top, r3_t *d, Coords3D_t *c3); /* Displaces all existing nodes by {d}. */ void Scale3D(ElemTableRec_t *top, double s, Coords3D_t *c3); /* Scales the coordinates of all existing nodes by {s}. */ double MeanNodeDistance3D(ElemTableRec_t *top, Coords3D_t *c3); /* The average distance of existing nodes from the origin, in the root-mean-square sense; that is, {sqrt(sum(norm(c3[v])^2, v IN VExist)) /|VExist|)}. */ void NormalizeNodeDistance3D(ElemTableRec_t *top, Coords3D_t *c3); /* Shifts and scales all existing nodes so that they have barycenter (0,0,0) and unit mean square distance from the origin. */ double TetraDet3D(uint u, uint v, uint w, uint x, Coords3D_t *c3); /* Signed determinant of the points {c3[u],c3[v],c3[w],c3[x]}, padded at the right with a column of {1}s. The absolute value of {TetraDet3D} is is six times the volume of the tetrahedron {u,v,w,x}, and the sign gives the handedness of the screw {u->v->w->x}.*/ bool_t WallIsSilhouette(Place_t p, Coords3D_t *c3); /* Return TRUE iff the projected wall associated to the {p} is a silhouette wall. */ int EdgeWindingNumber(Place_t p, Coords3D_t *c3); /* Returns the winding number of the tetrahedra incident to the edge. In a proper embedding, the number should be +1 or -1. */ r4_t ChoosePlaneThroughPoints(r3_t *u, r3_t *v); /* Chooses a plane through the points {u} and {v}. Returns the plane coefficients, the last one being the independent term. */ void FWriteState3D(FILE *wr, ElemTableRec_t *top, Coords3D_t *c3, char *cmt /* DF " " */); /* Writes the 3D geometric coordinates {c3->e[0..c3->nel-1]} to the previously opened file {wr}, in a format that can be read back by {FReadState3D}. The file {wr} will be flushed but will be left open. */ void WriteState3D(char *name, char *tag, ElemTableRec_t *top, Coords3D_t *c3, char *cmt /* DF { } */); /* Similar to {FWriteState3D}, but writes the data to a file "{name}{tag}.st3". */ Coords3D_t FReadState3D(FILE *rd); /* Reads from the previously opened file {rd} a vector of 3D geometric coordinates, in the format written by {WriteState3D}, and returns it. The file is left open. */ Coords3D_t ReadState3D(char *name, char *tag); /* Similar to {FReadState3D}, but the data is read from a disk file called "{name}{tag}.st3". */ void FWriteTetrahedra(FILE *wr, ElemTableRec_t *top, TetraData_vec_t *cell, char *cmt /* DF " " */); /* Writes the tetrahedron data {cell->e[0..dell->nel-1]} to the previously opened file {wr}, in a format that can be read back by {FReadTetrahedra}. The file {wr} will be flushed but will be left open. */ void WriteTetrahedra(char *name, char *tag, ElemTableRec_t *top, TetraData_vec_t *cell, char *cmt /* DF " " */); /* Similar to {}, but writes to a new disk file called "{name}{flage}.te". */ void WriteTetrahedron(FILE *wr, TetraData_t *t, uint nbase); /* Writes the data record of a single tetrahedron to {wr}. */ void ReadTetrahedron(FILE *rd, TetraData_t *t); /* Reads the data record single tetrahedron, produced by {WriteTetrahedron}. */ void FReadVectors(FILE *rd, uint n, Coords3D_t *pos); /* Reads a list of coordinates into {*pos}. */ #define Tridimensional_H_author \ "Created by L.A.P.Lozada ca. 1999.\n" \ "Some procedures are based on R. L. W. Liesenfeld's tools \n" \ "/Animação dinâmica de corpos elásticos/, ca. ????.\n" \ "Modified by L. A. P. lozada on 2000-02-19." #endif