wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
605 stars 103 forks source link

How to product closed mesh after splitting using Numpy-stl? #174

Closed rasunag27 closed 3 years ago

rasunag27 commented 3 years ago

Dear All,

I have an stl file with large amount of traingles present. I wanted to split the stl file using vertex threshold.

  1. I used numpy-stl to split the stl file into two separate solids. The splitting is perfectly done.
  2. But, I needed a closed mesh as original stl mesh. How can I obtain a closed mesh after splitting. Below is the code snippet of splitting the mesh.
  3. I have also attached the original mesh and the splitted mesh.

Loading original stl mesh

`mesh = mesh.Mesh.from_file('mesh.stl') facet_normals = pd.DataFrame(mesh.units) vertex1 = pd.DataFrame(mesh.v0) vertex2 = pd.DataFrame(mesh.v1) vertex3 = pd.DataFrame(mesh.v2)

Mesh splitting starts from here

coord_matrix = np.zeros((len(facet_normals), 12)) coord_matrix = pd.DataFrame(coord_matrix)

All the vertex and facet normals are arranged in matrix

coord_matrix[coord_matrix.columns[0:3]] = vertex1[vertex1.columns[0:3]] coord_matrix[coord_matrix.columns[3:6]] = vertex2[vertex2.columns[0:3]] coord_matrix[coord_matrix.columns[6:9]] = vertex3[vertex3.columns[0:3]] coord_matrix[coord_matrix.columns[9:12]] = facet_normals[facet_normals.columns[0:3]]

Splitting into two based on vertex threshold

c = coord_matrix[(coord_matrix[2] <=0.1) & (coord_matrix[5] <=0.1) & (coord_matrix[8] <=0.1)] g = coord_matrix[(coord_matrix[2] >=0.1) & (coord_matrix[5] >=0.1) & (coord_matrix[8] >=0.1)]

assigning it to a new splitted mesh named "chestwall"

chestwall = mesh.Mesh(np.zeros(c.shape[0], dtype=mesh.Mesh.dtype)) chestwall_facet_normals = np.array(c[c.columns[9:12]]) chestwall.units = chestwall_facet_normals chestwall.v0 = np.array(c[c.columns[0:3]]) chestwall.v1 = np.array(c[c.columns[3:6]]) chestwall.v2 = np.array(c[c.columns[6:9]])

assigning it to a new splitted mesh named "gland"

gland = mesh.Mesh(np.zeros(g.shape[0], dtype=mesh.Mesh.dtype)) gland_facet_normals = np.array(g[g.columns[9:12]]) gland.units = gland_facet_normals gland.v0 = np.array(g[g.columns[0:3]]) gland.v1 = np.array(g[g.columns[3:6]]) gland.v2 = np.array(g[g.columns[6:9]])

Saving the new splitted mesh

chestwall.save('chestwall.stl') gland.save('gland.stl')`

Image

Original stl mesh: Original stl

Splitted stl mesh: Splitted mesh

As can be seen in image, the splitted mesh has no connectivity between the two meshes.

How to obtain closed mesh after splitting the mesh..? Any leads will be appreciated.

Regards, Sunag R A.