Parse mesh from vtk file
Full example code: examples/parser/opencarp_vtk.py
Similar to the points (.pts) and elements (.elem) file, we also find our mesh in the .vtk file. Same vertices and elements.
import numpy as np
from dgmr.parser import OpencarpReader
vtk_file = "path_to_your_vtk_file"
mesh_data = OpencarpReader.load_vtk_file(vtk_file)
# Retrieve lists from dictionary
keys = ("coords", "triangles", "tags")
coords, triangles, tags = (mesh_data[key] for key in keys)
Additionally, a list of tags is present to annotate types of elements, such as scar tissue. We can use these tags to give sections a different colour or remove them from our mesh altogether.
# Remove cutouts and scar tissue (elements annotated as scar)
SCAR_TAG = 3 # = max(tags)
triangles = triangles[np.array(tags) != SCAR_TAG] # NumPy boolean masking
print(coords[:5])
print(triangles[:5])
print(tags[:5])
Output: dictionary containing coords, tags and elements being triangles or tetraeders.