(* Seth Porter SMFWriter3d.sml Output 3d vertices to Garland's SMF format. *) functor SMFWriter3d(structure Complex : SIMPLICIAL_COMPLEX where type Vertex.point = RealGeometry3d.Point.point) : SIMP_COMP_WRITER where Complex = Complex = struct structure Complex = Complex structure Helper = WriterHelper(structure Complex = Complex) structure Point = RealGeometry3d.Point structure Simplex = Complex.Simplex structure Vertex = Simplex.Vertex (* outputs Garland's SMF except with ~ for - Fix up with perl or tr *) fun write(filename, complex, dummy) = let fun format_vertex v = let val coords = Point.toSeq (Vertex.location v) fun toS(r, s) = s ^ " " ^ (Real.toString (RealGeometry3d.Number.toReal r)) in (Sequence.foldl toS "v" coords) ^ "\n" end fun format_face(s, get_v_num) = let val verts = Sequence.map get_v_num (Simplex.vertices s) fun toS(i, s) = s ^ " " ^ (Int.toString i) in (Sequence.foldl toS "f" verts) ^ "\n" end in Helper.write(complex, filename, (fn () => ""), format_vertex, format_face, dummy) end end