We start by importing vtk
and SimpleITK
:
import vtk
import SimpleITK
We then create two dictionaries containing the matching built-in types:
dctITKtoVTK = {SimpleITK.sitkInt8: vtk.VTK_TYPE_INT8,
SimpleITK.sitkInt16: vtk.VTK_TYPE_INT16,
SimpleITK.sitkInt32: vtk.VTK_TYPE_INT32,
SimpleITK.sitkInt64: vtk.VTK_TYPE_INT64,
SimpleITK.sitkUInt8: vtk.VTK_TYPE_UINT8,
SimpleITK.sitkUInt16: vtk.VTK_TYPE_UINT16,
SimpleITK.sitkUInt32: vtk.VTK_TYPE_UINT32,
SimpleITK.sitkUInt64: vtk.VTK_TYPE_UINT64,
SimpleITK.sitkFloat32: vtk.VTK_TYPE_FLOAT32,
SimpleITK.sitkFloat64: vtk.VTK_TYPE_FLOAT64}
dctVTKtoITK = dict(zip(dctITKtoVTK.values(),
dctITKtoVTK.keys()))
These two next functions can then use the above dictionaries to easily convert between matching types:
def convertTypeITKtoVTK(typeITK):
if typeITK in dctITKtoVTK:
return dctITKtoVTK[typeITK]
else:
raise ValueError("Type not supported")
def convertTypeVTKtoITK(typeVTK):
if typeVTK in dctVTKtoITK:
return dctVTKtoITK[typeVTK]
else:
raise ValueError("Type not supported")
The entirety of the code can be seen in the accompanying .py file