Skip to content

Instantly share code, notes, and snippets.

@ihnorton
Last active March 14, 2018 19:53
Show Gist options
  • Save ihnorton/6d0788e6c53a908663e726e909f7223d to your computer and use it in GitHub Desktop.
Save ihnorton/6d0788e6c53a908663e726e909f7223d to your computer and use it in GitHub Desktop.
export a set of vtk polylines as tubes
import vtk, os
from glob import glob
def exp_tubes(fname):
rdr = vtk.vtkPolyDataReader()
rdr.SetFileName(fname)
pd = rdr.GetOutputPort()
tf = vtk.vtkTubeFilter()
tf.SetInputConnection(pd)
tf.SetNumberOfSides(6)
tf.SetRadius(0.5)
wr = vtk.vtkPolyDataWriter()
outputfn = os.path.join("tubes/", os.path.splitext(fname)[0]+"-tube.vtk")
wr.SetInputConnection(tf.GetOutputPort())
wr.SetFileName(outputfn)
wr.SetFileTypeToBinary()
wr.Update()
for f in glob("*.vtk"):
print "exp: "+f
exp_tubes(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment