From 2bfc68c72d7547a77167917388bb39c533641e8c Mon Sep 17 00:00:00 2001 From: dboe <dboe@ipp.mpg.de> Date: Mon, 6 Dec 2021 16:30:51 +0100 Subject: [PATCH] speedup of stl save --- tfields/mesh_3d.py | 8 +------- tfields/triangles_3d.py | 6 +++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tfields/mesh_3d.py b/tfields/mesh_3d.py index 4aad957..a37cd51 100644 --- a/tfields/mesh_3d.py +++ b/tfields/mesh_3d.py @@ -374,13 +374,7 @@ class Mesh3D(tfields.TensorMaps): """ Saves the mesh in stl format """ - import stl - - shape = stl.Mesh(np.zeros(self.faces.shape[0], dtype=stl.Mesh.dtype)) - for i, f in enumerate(self.faces): - for j in range(3): - shape.vectors[i][j] = self[f[j], :] - shape.save(path, **kwargs) + self.triangles()._save_stl(path, **kwargs) @classmethod def _load_stl(cls, path): diff --git a/tfields/triangles_3d.py b/tfields/triangles_3d.py index f1f28d1..1b7e7f6 100644 --- a/tfields/triangles_3d.py +++ b/tfields/triangles_3d.py @@ -123,7 +123,11 @@ class Triangles3D(tfields.TensorFields): """ Save the object to a stl file """ - self.mesh().save_stl(path, **kwargs) + import stl + + shape = stl.Mesh(np.zeros(self.ntriangles(), dtype=stl.Mesh.dtype)) + shape.vectors = self.bulk.reshape((self.ntriangles(), 3, 3)) + shape.save(path, **kwargs) @classmethod def _load_stl(cls, path): -- GitLab