From 084dfd08b714faefaea77cb7dc04d2e93dc04b1d Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Fri, 16 Sep 2011 14:27:46 -0400 Subject: File reorganization to move toward standard python package layout --- stl.py | 91 ------------------------------------------------------------------ 1 file changed, 91 deletions(-) delete mode 100644 stl.py (limited to 'stl.py') diff --git a/stl.py b/stl.py deleted file mode 100644 index abf0cc9..0000000 --- a/stl.py +++ /dev/null @@ -1,91 +0,0 @@ -import numpy as np -import string -import struct -from chroma.geometry import Mesh -import bz2 - -def mesh_from_stl(filename): - "Returns a `chroma.geometry.Mesh` from an STL file." - if filename.endswith('.bz2'): - f = bz2.BZ2File(filename) - else: - f = open(filename) - buf = f.read(200) - f.close() - - for char in buf: - if char not in string.printable: - return mesh_from_binary_stl(filename) - - return mesh_from_ascii_stl(filename) - -def mesh_from_ascii_stl(filename): - "Return a mesh from an ascii stl file." - if filename.endswith('.bz2'): - f = bz2.BZ2File(filename) - else: - f = open(filename) - - vertices = [] - triangles = [] - vertex_map = {} - - while True: - line = f.readline() - - if line == '': - break - - if not line.strip().startswith('vertex'): - continue - - triangle = [None]*3 - for i in range(3): - vertex = tuple([float(s) for s in line.strip().split()[1:]]) - - if vertex not in vertex_map: - vertices.append(vertex) - vertex_map[vertex] = len(vertices) - 1 - - triangle[i] = vertex_map[vertex] - - if i < 3: - line = f.readline() - - triangles.append(triangle) - - f.close() - - return Mesh(np.array(vertices), np.array(triangles, dtype=np.uint32)) - -def mesh_from_binary_stl(filename): - "Return a mesh from a binary stl file." - f = open(filename) - - vertices = [] - triangles = [] - vertex_map = {} - - f.read(80) - ntriangles = struct.unpack('