INTERFACE Map3D; (* Tridimensional maps. The facet-edge data structure for tridimensional maps, decorated with material properties of vertices, edges, faces, and cells. Written by L. Lozada (see copyright at end of file). *) IMPORT Map3D, R3, Wr, LR4, Random; (* === ELEMENTS === *) TYPE VisitProc = Map3D.VisitProc; VFEBits = Map3D.VFEBits; FaceEdge = Map3D.FaceEdge; Handle = Map3D.Handle; VPNode = Map3D.VPNode; EFNode = Map3D.EFNode; TYPE ElemNode <: PublicElemNode; PublicElemNode = Map3D.ElemNode OBJECT exists: BOOLEAN := TRUE; (* FALSE means the element is not there. *) fixed: BOOLEAN := FALSE; (* TRUE if position is fixed in optimization. *) color: R3.T := R3.T{0.0,0.0,0.0}; (* Color for painting. *) transp: R3.T := R3.T{0.0,..}; (* Transp. coefficient for painting. *) radius: REAL := 0.020; (* Vertex/edge radius for drawing. *) label: TEXT; (* Element label, useful in bar.sub *) parent: INTEGER := -1; (* The "parent" element in the original map. *) END; (* A node with element properties. Note that some properties only make sense for nodes of certain dimensions; eg. the `radius' is useless for faces and cells, `fixed' only makes sense for vertices. Also note that a property that is useless in the primal map may be used when the same element record is accessed as part of the dual map. *) PROCEDURE Exists(e: ElemNode): BOOLEAN; (* Returns TRUE iff e # NIL and e.exists is TRUE. *) (* === ELEMENT CREATION === *) PROCEDURE MakeEdge(): Edge; (* Creates a new component edge. *) PROCEDURE MakeFace(): Face; (* Creates a new component face. *) PROCEDURE MakeVertex(): Vertex; (* Creates an unattached vertex record. *) PROCEDURE MakeCell(): Cell; (* Creates an unattached cell record. *) (* === PAIR PROPERTIES === *) PROCEDURE OrgV(a: Handle): Vertex; (* The origin of handle "a", narrowed to type "Vertex". *) PROCEDURE DesV(a: Handle): Vertex; (* The destination of handle "a", narrowed to type "Vertex". *) PROCEDURE PnegP(a : Handle): Cell; (* The negative cell of handle "a", narrowed to type "Cell". *) PROCEDURE PposP(a : Handle): Cell; (* The positive cell of handle "a", narrowed to type "Cell".*) (* === Element enumeration === *) PROCEDURE VertexNeighbors(a: Handle): REF ARRAY OF VPNode; (* Neighbor vertices of "OrgV(a)", for any topology. *) PROCEDURE FaceCorners(a: Handle): REF ARRAY OF VPNode; (* Corner vertices of the face Fce(a), for any topology. *) (* === CONSTRUCTION TOOLS === *) PROCEDURE MakeTriangle(): Handle; (* Make a map consisting of a single triangular face, three vertices, tree edges, and one cell. Leaves the cell records as NIL. *) PROCEDURE MakeSquare(): Handle; (* Make a map consisting of a single square face, four vertices, four edges, and one cell. Leaves the cell records as NIL. *) PROCEDURE MakeGon(n: CARDINAL): Handle; (* Builds a map consisting of a single one n-gon face, with n vertices, n edges, and one cell. The cell records are left NIL. *) (* ==== Topological tables ==== *) TYPE Topology = RECORD NV: INTEGER; (* Number of vertex *) NE: CARDINAL; (* Number of edges *) NF: CARDINAL; (* Number of faces *) NP: INTEGER; (* Number of cells *) NFE: INTEGER; (* Number of fes *) vref: REF ARRAY OF Handle; (* One handle for each vertex. *) fref: REF ARRAY OF Handle; (* One handle on each face. *) eref: REF ARRAY OF Handle; (* One handle on each edge. *) pref: REF ARRAY OF Handle; (* One handle on the boundary of each cell. *) feref: REF ARRAY OF Handle; (* One handle for each fe *) END; PROCEDURE MakeTopology(a: Handle): Topology; (* This procedure computes the topological structure of a map with or without boundary. It assumes that the procedures "Map3D.Numberfes", "Map3D.NumberVertices", "Map3D.NumberEdges", "Map3D.NumberFacets" have been called after the last change to the structure "a". *) (* === GEOMETRIC TOOLS === *) TYPE Coords = ARRAY OF LR4.T; PROCEDURE InitCoords(coins: Random.T; VAR c: Coords; radius: LONGREAL := 1.0d0); (* Fills c with random coordinates in a sphere of the given "radius" centered at origin. *) PROCEDURE GenCoords(coins: Random.T; NV: CARDINAL; radius: LONGREAL := 1.0d0): REF Coords; (* Allocates a vector with coordinates for NV points, and initializes it with InitCoords. *) PROCEDURE Barycenter(READONLY top: Topology; READONLY c: Coords): LR4.T; (* Returns the barycenter of all existing vertices. *) PROCEDURE Displace(READONLY top: Topology; d: LR4.T; VAR c: Coords); (* Displaces all existing vertices by "d". *) PROCEDURE Scale(READONLY top: Topology; s: LONGREAL; VAR c: Coords); (* Scales the coordinates of all existing vertices by "s". *) PROCEDURE MeanVertexDistance(READONLY top: Topology; READONLY c: Coords): LONGREAL; (* The average distance of existing vertices from the origin, in the root-mean-square sense; that is, "sqrt(sum(norm(c[v])^2, v IN VExist)) /|VExist|)". *) PROCEDURE MeanEdgeLength(READONLY top: Topology; READONLY c: Coords): LONGREAL; (* The average length of existing edges, in the root-mean-square sense; that is "sqrt(sum(dist(c[org(e)], c[dst(e)])^2, e IN EExist))/|EExist|)". *) PROCEDURE NormalizeVertexDistance(READONLY top: Topology; VAR c: Coords); (* Shifts and scales all vertices so that the existing ones have barycenter (0,0,0,0) and unit mean square distance from the origin. *) PROCEDURE NormalizeEdgeLengths(READONLY top: Topology; VAR c: Coords); (* Shifts and scales all vertices so that the existing ones have barycenter (0,0,0,0), and the mean square length of existing edges is 1.0. *) PROCEDURE EdgeBarycenter(a: Handle; READONLY c: Coords): LR4.T; (* The barycenter of the existing endpoints of the edge component of handle "a". *) PROCEDURE FaceBarycenter(a: Handle; READONLY c: Coords): LR4.T; (* The barycenter of the existing corners of the face component of handle "a". *) PROCEDURE PnegBarycenter(a: Handle; READONLY c: Coords): LR4.T; (* The barycenter of the existing vertices of the cell "Pneg(a)". *) PROCEDURE NeighborBarycenter(n: REF ARRAY OF Vertex; READONLY c: Coords): LR4.T; (* Barycenter of the existing neighbors vertices of "OrgV(a)". *) (* === INPUT/OUTPUT === *) TYPE TopCom = RECORD top: Topology; comments: TEXT END; PROCEDURE WriteTopology(name: TEXT; READONLY top: Topology; comments: TEXT := " "); (* Writes "top", and "comments" to file disk in a format that can be read back. The file will have the given "name" with ".tp" appended. *) PROCEDURE WriteState( name: TEXT; READONLY top: Topology; READONLY c: Coords; comments: TEXT := " "; ); (* Writes the coordinates geometrics to file disk in a format that can be read back. The file will have the given "name" with ".st" appended. *) PROCEDURE WriteMaterials( name: TEXT; READONLY top: Topology; comments: TEXT := " "; ro_te: BOOLEAN := FALSE; ); (* Writes the materials properties to file disk in a format that can be read back. The file will have the given "name" with ".ma" appended. *) PROCEDURE FindDegeneracies(READONLY top: Topology); (* Finds geometric degeneracies. Update the attribute "degenerate" of the elements: edge, face and cell. *) PROCEDURE WriteStDe( wr: Wr.T; READONLY c: Coords; (* Vertex coordinates *) READONLY Dc: Coords; (* Vertex coordinates derivates *) prec: CARDINAL := 4; (* Significant figures to use for "c" and "Dc" *) comments: TEXT := ""; ); (* Writes the coordinates "c" and derivatives "Dc" to file "wr" in the ".sd" format. *) PROCEDURE ReadToTaMa(name: TEXT; ro_te: BOOLEAN := FALSE): TopCom; (* Reads three disk files created by "WriteTopology", "MakeTopologyTable" and "WriteMaterials". The files must have the given "name" with ".tp", ".tb" and ".ma". *) PROCEDURE ReadState(name: TEXT): REF Coords; (* Reads a disk file created by "WriteState". The file must have the given "name" with ".st" appended. *) END Map3D. (* Last edited on 2001-05-06 09:25:15 by stolfi *)