pysdic.Mesh.from_vtk#
- classmethod Mesh.from_vtk(filename, element_type=None, load_properties=True)[source]#
Create a Mesh instance from a VTK file (Only for 3D embedding dimension meshes \(E=3\)).
This method uses meshio to read the VTK file and then converts it to a
Meshinstance.See also
Mesh.to_vtk()for the reverse operation.Mesh.from_meshio()for more information on the conversion process.meshio documentation for more information.
Meshfor more information on the Mesh class and element types.
Warning
This method is only compatible with meshes having an embedding dimension of 3.
- Parameters:
- Returns:
A
Meshinstance created from the VTK file.- Return type:
- Raises:
FileNotFoundError – If the file does not exist.
ValueError – If the file format is not supported or the mesh structure is invalid.
Examples
Create a simple
meshio.Meshobject.1import numpy as np 2import meshio 3from pysdic import Mesh 4 5points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]) 6cells = [("triangle", np.array([[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]]))] 7 8mesh = meshio.Mesh(points=points, cells=cells)
Save the meshio Mesh object to a VTK file.
1mesh.write("simple_mesh.vtk", file_format="vtk")
Create a
Meshinstance from the VTK file.1mesh3d = Mesh.from_vtk("simple_mesh.vtk") 2print(mesh3d.vertices) 3# Output: PointCloud with 4 points [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]