Forked from thewtex/vtk-unstructuredgrid-to-stl.py
Created
February 26, 2018 11:57
-
-
Save pmav99/add9c9b6597255bd1aaefb91ab34d600 to your computer and use it in GitHub Desktop.
Convert a .vtk UnstructuredGrid file to .stl file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Convert UnstructuredGrid in .vtk files to STL files.""" | |
import sys | |
import vtk | |
if len(sys.argv) < 2 or sys.argv[1] == '-h' or sys.argv[1] == '--help': | |
print('Usage: vtk-unstructuredgrid-to-stl.py <input.vtk> <output.stl>') | |
sys.exit(1) | |
reader = vtk.vtkUnstructuredGridReader() | |
reader.SetFileName(sys.argv[1]) | |
surface_filter = vtk.vtkDataSetSurfaceFilter() | |
surface_filter.SetInputConnection(reader.GetOutputPort()) | |
triangle_filter = vtk.vtkTriangleFilter() | |
triangle_filter.SetInputConnection(surface_filter.GetOutputPort()) | |
writer = vtk.vtkSTLWriter() | |
writer.SetFileName(sys.argv[2]) | |
writer.SetInputConnection(triangle_filter.GetOutputPort()) | |
writer.Write() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment