forked from DCBIA-OrthoLab/ShapeAXI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstl_to_vtk.py
More file actions
29 lines (23 loc) · 968 Bytes
/
stl_to_vtk.py
File metadata and controls
29 lines (23 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import vtk
import argparse
def convert_stl_to_vtk(stl_filename, vtk_filename):
# Create a reader for the STL file
reader = vtk.vtkSTLReader()
reader.SetFileName(stl_filename)
# Create a writer for the VTK file
writer = vtk.vtkPolyDataWriter()
writer.SetFileName(vtk_filename)
# Connect the output of the reader directly to the input of the writer
writer.SetInputConnection(reader.GetOutputPort())
# Write the VTK file
writer.Write()
def get_argparse():
# Function to parse the arguments
parser = argparse.ArgumentParser(description='Converts a STL file to a VTK file')
parser.add_argument('--surf', type=str, help='Surface stl file', required=True)
parser.add_argument('--out', type=str, help='Output', default="out.vtk")
return parser
if __name__ == '__main__':
parser = get_argparse()
args = parser.parse_args()
convert_stl_to_vtk(args.surf, args.out)