You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just wanted to use meshio to write me nice vtk files for some meshes, and therefore I need to merge multiple meshes together.
I did not found a direct way to do that, thus I wrote this (very simplified and not generally usable) function:
import meshio
def merge_meshes(a: meshio.Mesh = None, b: meshio.Mesh = None) -> meshio.Mesh:
if a is None:
return b
if b is None:
return a
n_vert = a.points.shape[0]
vertices = np.vstack((a.points, b.points))
all_cell_types = a.cells_dict.keys() & b.cells_dict.keys()
cells = dict()
for cell_type in all_cell_types:
if cell_type in a.cells_dict and cell_type in b.cells_dict:
cells[cell_type] = np.vstack((a.cells_dict[cell_type], b.cells_dict[cell_type] + n_vert))
elif cell_type in a.cells_dict:
cells[cell_type] = a.cells_dict[cell_type]
elif cell_type in b.cells_dict:
cells[cell_type] = b.cells_dict[cell_type] + n_vert
return meshio.Mesh(vertices, cells)
It simply concatenates the point vectors and adjusts the numbering in the second mesh.
Because that could be useful for other things as well, I wondered, if I overlooked something and there is more generic way already implemented?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I just wanted to use meshio to write me nice vtk files for some meshes, and therefore I need to merge multiple meshes together.
I did not found a direct way to do that, thus I wrote this (very simplified and not generally usable) function:
It simply concatenates the point vectors and adjusts the numbering in the second mesh.
Because that could be useful for other things as well, I wondered, if I overlooked something and there is more generic way already implemented?
Beta Was this translation helpful? Give feedback.
All reactions