def test_empty_areas(): data = numpy.zeros(3, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]]) data['vectors'][1] = numpy.array([[1, 0, 0], [0, 1, 0], [1, 0, 0]]) data['vectors'][2] = numpy.array([[1, 0, 0], [0, 1, 0], [1, 0, 0]]) mesh = Mesh(data, calculate_normals=False, remove_empty_areas=False) assert mesh.data.size == 3 # Test the normals recalculation which also calculates the areas by default mesh.areas[1] = 1 mesh.areas[2] = 2 assert numpy.allclose(mesh.areas, [[0.5], [1.0], [2.0]]) mesh.update_normals(update_areas=False) assert numpy.allclose(mesh.areas, [[0.5], [1.0], [2.0]]) mesh.update_normals(update_areas=True) assert numpy.allclose(mesh.areas, [[0.5], [0.0], [0.0]]) mesh = Mesh(data, remove_empty_areas=True) assert mesh.data.size == 1
def test_remove_all_duplicate_polygons(): data = numpy.zeros(5, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][1] = numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][2] = numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][3] = numpy.array([[3, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][4] = numpy.array([[3, 0, 0], [0, 0, 0], [0, 0, 0]]) mesh = Mesh(data, remove_duplicate_polygons=False) assert mesh.data.size == 5 Mesh.remove_duplicate_polygons(mesh.data, RemoveDuplicates.NONE) mesh = Mesh(data, remove_duplicate_polygons=RemoveDuplicates.ALL) assert mesh.data.size == 3 assert (mesh.vectors[0] == numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[1] == numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[2] == numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]])).all()
def test_empty_areas(): data = numpy.zeros(3, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]]) data['vectors'][1] = numpy.array([[1, 0, 0], [0, 1, 0], [1, 0, 0]]) data['vectors'][2] = numpy.array([[1, 0, 0], [0, 1, 0], [1, 0, 0]]) mesh = Mesh(data, remove_empty_areas=False) assert mesh.data.size == 3 mesh = Mesh(data, remove_empty_areas=True) assert mesh.data.size == 1
def test_remove_all_duplicate_polygons(): mesh = Mesh(your_mesh, remove_duplicate_polygons=False) assert mesh.data.size == 9 Mesh.remove_duplicate_polygons(mesh.data, RemoveDuplicates.NONE) mesh = Mesh(your_mesh, remove_duplicate_polygons=RemoveDuplicates.ALL) assert mesh.data.size == 9 assert (your_mesh.points[0][0:3] == your_mesh.v0[0]).all() assert (your_mesh.points[0][3:6] == your_mesh.v1[0]).all() assert (your_mesh.points[0][6:9] == your_mesh.v2[0]).all()
def gen_stl(self): vertices = [] faces = [] for l in self.lines: for v in l: vertices.append(v) faces = [] for n, l in enumerate(self.lines[:-1]): for i, p in enumerate(l[:-1]): p0 = self.index(n, i) p1 = self.index(n, i + 1) p2 = self.index(n + 1, i) faces.append([p1, p0, p2]) p0 = self.index(n + 1, i) p1 = self.index(n + 1, i + 1) p2 = self.index(n, i + 1) faces.append([p0, p1, p2]) vertices = np.array(vertices) faces = np.array(faces) cube = Mesh( np.zeros(faces.shape[0], dtype=Mesh.dtype), remove_duplicate_polygons=RemoveDuplicates.NONE, ) for i, f in enumerate(faces): for j in range(3): cube.vectors[i][j] = vertices[f[j], :] return cube
def test_units_1d(): data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) mesh = Mesh(data, remove_empty_areas=False) mesh.update_units() assert mesh.areas == 0 assert (mesh.normals == [0, 0, 0]).all() assert (mesh.units == [0, 0, 0]).all()
def build_stl(name, points): ''' Given a set point points, make a STL file of the convex hull. ''' points = np.array(points) points -= np.min(points, axis=0) # Move bound to origin hull = ConvexHull(points) shape = Mesh(np.zeros(len(hull.vertices), dtype=Mesh.dtype)) for i, vertex in enumerate(hull.vertices): shape.vectors[i] = hull.points[vertex][::-1] # Turn it inside out size = np.max(hull.points, axis=0) return shape, size
def gen_stl(self, fname): vertices = [] faces = [] cube = Mesh( np.concatenate([b.gen_stl().data.copy() for b in self.blocks]), remove_duplicate_polygons=RemoveDuplicates.NONE, ) cube.save(fname)
def test_units_1d(): data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) mesh = Mesh(data, remove_empty_areas=False) mesh.update_units() assert mesh.areas == 0 utils.array_equals(mesh.normals, [0, 0, 0]) utils.array_equals(mesh.units, [0, 0, 0]) utils.array_equals(mesh.get_unit_normals(), [0, 0, 0])
def test_units_2d(): data = numpy.zeros(2, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]]) data['vectors'][1] = numpy.array([[1, 0, 0], [0, 1, 0], [1, 1, 0]]) mesh = Mesh(data, remove_empty_areas=False) mesh.update_units() assert numpy.allclose(mesh.areas, [.5, .5]) assert numpy.allclose(mesh.normals, [[0, 0, 1.], [0, 0, -1.]]) assert numpy.allclose(mesh.units, [[0, 0, 1], [0, 0, -1]])
def test_units_3d(): data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [1, 0, 0], [0, 1, 1.]]) mesh = Mesh(data, remove_empty_areas=False) mesh.update_units() assert (mesh.areas - 2 ** .5) < 0.0001 assert numpy.allclose(mesh.normals, [0.0, -0.70710677, 0.70710677]) assert numpy.allclose(mesh.units[0], [0.0, -0.5, 0.5])
def test_no_translation(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 1, 1], [1, 0, 1], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) assert (mesh.vectors == numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])).all() # Translate mesh with a zero vector mesh.translate([0.0, 0.0, 0.0]) assert (mesh.vectors == numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])).all()
def test_translation(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 1, 1], [1, 0, 1], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) assert numpy.allclose(mesh.vectors, numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])) # Translate mesh with vector [1, 2, 3] mesh.translate([1.0, 2.0, 3.0]) assert numpy.allclose(mesh.vectors, numpy.array([[[1, 3, 4], [2, 2, 4], [1, 2, 4]]]))
def test_duplicate_polygons(): data = numpy.zeros(6, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][1] = numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][2] = numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][3] = numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][4] = numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][5] = numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) mesh = Mesh(data, remove_duplicate_polygons=False) assert mesh.data.size == 6 mesh = Mesh(data, remove_duplicate_polygons=True) assert mesh.data.size == 3 print 'vectors' print mesh.vectors assert (mesh.vectors[0] == numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[1] == numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[2] == numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])).all()
def test_rotation(): # Create 6 faces of a cube data = numpy.zeros(6, dtype=Mesh.dtype) # Top of the cube data['vectors'][0] = numpy.array([[0, 1, 1], [1, 0, 1], [0, 0, 1]]) data['vectors'][1] = numpy.array([[1, 0, 1], [0, 1, 1], [1, 1, 1]]) # Right face data['vectors'][2] = numpy.array([[1, 0, 0], [1, 0, 1], [1, 1, 0]]) data['vectors'][3] = numpy.array([[1, 1, 1], [1, 0, 1], [1, 1, 0]]) # Left face data['vectors'][4] = numpy.array([[0, 0, 0], [1, 0, 0], [1, 0, 1]]) data['vectors'][5] = numpy.array([[0, 0, 0], [0, 0, 1], [1, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) # Since the cube faces are from 0 to 1 we can move it to the middle by # substracting .5 data['vectors'] -= .5 # Rotate 90 degrees over the X axis followed by the Y axis followed by the # X axis mesh.rotate([0.5, 0.0, 0.0], math.radians(90)) mesh.rotate([0.0, 0.5, 0.0], math.radians(90)) mesh.rotate([0.5, 0.0, 0.0], math.radians(90)) # Since the cube faces are from 0 to 1 we can move it to the middle by # substracting .5 data['vectors'] += .5 assert (mesh.vectors == numpy.array([ [[1, 0, 0], [0, 1, 0], [0, 0, 0]], [[0, 1, 0], [1, 0, 0], [1, 1, 0]], [[0, 1, 1], [0, 1, 0], [1, 1, 1]], [[1, 1, 0], [0, 1, 0], [1, 1, 1]], [[0, 0, 1], [0, 1, 1], [0, 1, 0]], [[0, 0, 1], [0, 0, 0], [0, 1, 0]], ])).all()
def test_no_transformation(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 1, 1], [1, 0, 1], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) assert (mesh.vectors == numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])).all() # Transform mesh with identity matrix mesh.transform(numpy.eye(4)) assert (mesh.vectors == numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])).all() assert numpy.all(mesh.areas == 0.5)
def test_rotation_over_point(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) mesh.rotate([1, 0, 0], math.radians(180), point=[1, 2, 3]) assert (mesh.vectors == numpy.array([[1, -4, -6], [0, -5, -6], [0, -4, -7]])).all()
def test_duplicate_polygons(): data = numpy.zeros(6, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][1] = numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][2] = numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][3] = numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][4] = numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]]) data['vectors'][5] = numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) mesh = Mesh(data) assert mesh.data.size == 6 mesh = Mesh(data, remove_duplicate_polygons=0) assert mesh.data.size == 6 mesh = Mesh(data, remove_duplicate_polygons=False) assert mesh.data.size == 6 mesh = Mesh(data, remove_duplicate_polygons=None) assert mesh.data.size == 6 mesh = Mesh(data, remove_duplicate_polygons=RemoveDuplicates.NONE) assert mesh.data.size == 6 mesh = Mesh(data, remove_duplicate_polygons=RemoveDuplicates.SINGLE) assert mesh.data.size == 3 mesh = Mesh(data, remove_duplicate_polygons=True) assert mesh.data.size == 3 assert (mesh.vectors[0] == numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[1] == numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[2] == numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])).all() mesh = Mesh(data, remove_duplicate_polygons=RemoveDuplicates.ALL) assert mesh.data.size == 3 assert (mesh.vectors[0] == numpy.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[1] == numpy.array([[2, 0, 0], [0, 0, 0], [0, 0, 0]])).all() assert (mesh.vectors[2] == numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])).all()
def test_units_3d(): data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 0, 0], [1, 0, 0], [0, 1, 1.]]) mesh = Mesh(data, remove_empty_areas=False) mesh.update_units() assert (mesh.areas - 2**.5) < 0.0001 assert (mesh.normals == [0, -1, 1]).all() units = mesh.units[0] assert units[0] == 0 # Due to floating point errors assert (units[1] + .5 * 2**.5) < 0.0001 assert (units[2] - .5 * 2**.5) < 0.0001
def test_double_rotation(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) rotation_matrix = mesh.rotation_matrix([1, 0, 0], math.radians(180)) combined_rotation_matrix = numpy.dot(rotation_matrix, rotation_matrix) mesh.rotate_using_matrix(combined_rotation_matrix) utils.array_equals( mesh.vectors, numpy.array([[[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]]))
def toSTL(self): """ Exports the current laminate as an STL file """ from stl.mesh import Mesh #Requires numpy-stl layerdef = self.layerdef laminate_verts = [] for layer in layerdef.layers: shapes = self.geoms[layer] #TODO Add it in for other shapes zvalue = layerdef.z_values[layer] thickness = layer.thickness if (len(shapes) == 0): #In case there are no shapes. print("No shapes skipping") continue for s in shapes: shape_verts = s.extrudeVertices(thickness, z0=zvalue) laminate_verts.extend(shape_verts) laminate_verts = [ point / popupcad.SI_length_scaling for point in laminate_verts ] # Or creating a new mesh (make sure not to overwrite the `mesh` import by # naming it `mesh`): VERTICE_COUNT = len(laminate_verts) // 3 #Number of verticies data = numpy.zeros( VERTICE_COUNT, dtype=Mesh.dtype ) #We create an array full of zeroes. Will edit it later. #Creates a mesh from the specified set of points for dtype, points in zip(data, numpy.array(laminate_verts).reshape(-1, 9)): points = points.reshape(-1, 3) #Splits each triangle into points numpy.copyto(dtype[1], points) #Copies the list of points into verticies index data = Mesh.remove_duplicate_polygons(data) #This constructs the mesh objects, generates the normals and all your_mesh = Mesh(data, remove_empty_areas=True) filename = str(self.id) + '.stl' old_path = os.getcwd() #Save old directory new_path = popupcad.exportdir + os.path.sep #Load export directory os.chdir(new_path) #Change to export directory print("Saving in " + str(new_path)) your_mesh.save(filename) #Apparently save does not like absolute paths print(filename + " has been saved") os.chdir(old_path) #Change back to old directory
def test_no_rotation(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 1, 1], [1, 0, 1], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) # Rotate by 0 degrees mesh.rotate([0.5, 0.0, 0.0], math.radians(0)) assert (mesh.vectors == numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])).all() # Use a zero rotation matrix mesh.rotate([0.0, 0.0, 0.0], math.radians(90)) assert (mesh.vectors == numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])).all()
def test_transformation(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[0, 1, 1], [1, 0, 1], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) assert (mesh.vectors == numpy.array([[[0, 1, 1], [1, 0, 1], [0, 0, 1]]])).all() # Transform mesh with identity matrix tr = numpy.zeros((4, 4)) tr[0:3, 0:3] = Mesh.rotation_matrix([0, 0, 1], 0.5 * numpy.pi) tr[0:3, 3] = [1, 2, 3] mesh.transform(tr) assert (mesh.vectors == numpy.array([[[0, 2, 4], [1, 3, 4], [1, 2, 4]]])).all() assert numpy.all(mesh.areas == 0.5)
def test_rotation(): # Create 6 faces of a cube data = numpy.zeros(6, dtype=Mesh.dtype) # Top of the cube data['vectors'][0] = numpy.array([[0, 1, 1], [1, 0, 1], [0, 0, 1]]) data['vectors'][1] = numpy.array([[1, 0, 1], [0, 1, 1], [1, 1, 1]]) # Right face data['vectors'][2] = numpy.array([[1, 0, 0], [1, 0, 1], [1, 1, 0]]) data['vectors'][3] = numpy.array([[1, 1, 1], [1, 0, 1], [1, 1, 0]]) # Left face data['vectors'][4] = numpy.array([[0, 0, 0], [1, 0, 0], [1, 0, 1]]) data['vectors'][5] = numpy.array([[0, 0, 0], [0, 0, 1], [1, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) # Since the cube faces are from 0 to 1 we can move it to the middle by # substracting .5 data['vectors'] -= .5 # Rotate 90 degrees over the X axis followed by the Y axis followed by the # X axis mesh.rotate([0.5, 0.0, 0.0], math.radians(90)) mesh.rotate([0.0, 0.5, 0.0], math.radians(90)) mesh.rotate([0.5, 0.0, 0.0], math.radians(90)) # Since the cube faces are from 0 to 1 we can move it to the middle by # substracting .5 data['vectors'] += .5 # We use a slightly higher absolute tolerance here, for ppc64le # https://github.com/WoLpH/numpy-stl/issues/78 assert numpy.allclose(mesh.vectors, numpy.array([ [[1, 0, 0], [0, 1, 0], [0, 0, 0]], [[0, 1, 0], [1, 0, 0], [1, 1, 0]], [[0, 1, 1], [0, 1, 0], [1, 1, 1]], [[1, 1, 0], [0, 1, 0], [1, 1, 1]], [[0, 0, 1], [0, 1, 1], [0, 1, 0]], [[0, 0, 1], [0, 0, 0], [0, 1, 0]], ]), atol=1e-07)
def _add_normalizing_vector_point(mesh, minpt, maxpt): """ This function allows you to visualize all meshes in their size relative to each other It is a quick simple hack: by adding 2 vector points at the same x coordinates at the extreme left and extreme right of the largest .stl mesh, all the meshes are displayed with the same scale. input: [mesh], minpoint coordinates, maxpoint coordinates output: [mesh] with 2 added coordinate points """ newmesh = Mesh(np.zeros(mesh.vectors.shape[0] + 2, dtype=Mesh.dtype)) # newmesh.vectors = np.vstack([mesh.vectors, # np.array([ [[0,maxpt,0], [0,maxpt,0], [0,maxpt,0]], # [[0,minpt,0], [0,minpt,0], [0,minpt,0]] ], float) ]) newmesh.vectors = np.vstack([ mesh.vectors, np.array([[[0, 0, maxpt], [0, 0, maxpt], [0, 0, maxpt]], [[0, 0, minpt], [0, 0, minpt], [0, 0, minpt]]], float) ]) return newmesh
def test_rotation_over_point(): # Create a single face data = numpy.zeros(1, dtype=Mesh.dtype) data['vectors'][0] = numpy.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) mesh = Mesh(data, remove_empty_areas=False) mesh.rotate([1, 0, 0], math.radians(180), point=[1, 2, 3]) utils.array_equals( mesh.vectors, numpy.array([[[1., 4., 6.], [0., 3., 6.], [0., 4., 5.]]])) mesh.rotate([1, 0, 0], math.radians(-180), point=[1, 2, 3]) utils.array_equals(mesh.vectors, numpy.array([[[1, 0, 0], [0, 1, 0], [0, 0, 1]]])) mesh.rotate([1, 0, 0], math.radians(180), point=0.0) utils.array_equals( mesh.vectors, numpy.array([[[1., 0., -0.], [0., -1., -0.], [0., 0., -1.]]])) with pytest.raises(TypeError): mesh.rotate([1, 0, 0], math.radians(180), point='x')
import stl import numpy as np import sys from stl.mesh import Mesh print((sys.argv)) stl_mesh = Mesh.from_file(sys.argv[1]) data = np.zeros(stl_mesh.data.size, dtype=Mesh.dtype) new_mesh = Mesh(data) new_mesh.normals[:] = stl_mesh.normals new_mesh.vectors[:] = stl_mesh.vectors target = open(sys.argv[2], "w") for i in range(0, new_mesh.normals.shape[0]): x1 = new_mesh.vectors[i, 0, 0] x2 = new_mesh.vectors[i, 1, 0] x3 = new_mesh.vectors[i, 2, 0] y1 = new_mesh.vectors[i, 0, 1] y2 = new_mesh.vectors[i, 1, 1] y3 = new_mesh.vectors[i, 2, 1] z1 = new_mesh.vectors[i, 0, 2] z2 = new_mesh.vectors[i, 1, 2] z3 = new_mesh.vectors[i, 2, 2] xc = 1.0 / 3.0 * (x1 + x2 + x3) yc = 1.0 / 3.0 * (y1 + y2 + y3) zc = 1.0 / 3.0 * (z1 + z2 + z3) nx = new_mesh.normals[i, 0] ny = new_mesh.normals[i, 1] nz = new_mesh.normals[i, 2] normalmag = np.sqrt(pow(nx, 2) + pow(ny, 2) + pow(nz, 2)) + 1e-15 target.write("%f %f %f %f %f %f\n" % (xc, yc, zc, nx / normalmag, ny / normalmag, nz / normalmag)) target.close()
# fh.write(tmp_file) # fh.seek(0) # mesh.Mesh.from_file(str(tmp_file), fh=fh, speedups=speedups) # #test_valid_ascii(cwd, 'speedups') # #def zero_runs(a): # from link # iszero = np.concatenate(([0][0], np.equal(a, 0).view(np.int8), [0])) # absdiff = np.abs(np.diff(iszero)) # ranges = np.where(absdiff == 1)[0].reshape(-1, 2) # return ranges # Using an existing stl file: your_mesh = mesh.Mesh.from_file("pistons.stl") Mesh.remove_duplicate_polygons(mesh.data, RemoveDuplicates.NONE) mesh = Mesh(your_mesh, remove_duplicate_polygons=RemoveDuplicates.ALL) # ============================================================================= # To Plot the object using mathplotlib # ============================================================================= # Create a new plot #figure = pyplot.figure() #axes = mplot3d.Axes3D(figure) # ## Load the STL files and add the vectors to the plot ##axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors[0:3500][:][:])) #axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors[0:2000][:][:],edgecolor='k')) # ## Auto scale to the mesh size #scale = your_mesh.points.flatten(-1) #axes.auto_scale_xyz(scale, scale, scale)
def get_mesh(self): the_mesh = Mesh(self.data, remove_empty_areas=False) the_mesh.update_units() return the_mesh