#Reads a volume image in .vtk format, extracts a polygonal isosurface ,and exports this surface to a .ply file.
#Filip Malmberg 2006

import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Read the volume images
reader = vtk.vtkStructuredPointsReader()reader.SetFileName("my_image.vtk")
# Extracting a triangulated isosurface from the volume
isoSurface = vtk.vtkContourFilter()
isoSurface.SetInput(reader.GetOutput())
isoSurface.SetValue(0, 127)

#Write isosurface mesh to PLY format
writer = vtk.vtkPLYWriter()
writer.SetInput(isoSurface.GetOutput())
writer.SetFileTypeToASCII()
writer.SetFileName('isosurface.ply')
writer.Write()



