VTK vs ITK metadata (size, origin, spacing, direction)

Hi all,

I’m trying to convert a polydata and place it in the same space as image X using the code below:

def polydata_to_imagedata(polydata, direction, dimensions, origin, spacing):
    dx, dy, dz = dimensions
    ox,oy,oz = origin
    sx, sy, sz = spacing

    image = vtk.vtkImageData()
    image.SetDirectionMatrix(direction)
    image.SetSpacing((sx, sy, sz))
    image.SetDimensions((dx, dy, dz))
    image.SetExtent(0, dx - 1, 0, dy - 1, 0, dz - 1)
    image.SetOrigin((ox, oy, oz))
    image.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
    inval = 255
    outval = 0

    for i in range(image.GetNumberOfPoints()):
        image.GetPointData().GetScalars().SetTuple1(i, inval)

    pol2stenc = vtk.vtkPolyDataToImageStencil()
    pol2stenc.SetInputData(polydata)
    pol2stenc.SetOutputOrigin((ox, oy, oz))
    pol2stenc.SetOutputSpacing((sx, sy, sz))
    pol2stenc.Update()

    imgstenc = vtk.vtkImageStencil()
    imgstenc.SetInputData(image)
    imgstenc.SetStencilConnection(pol2stenc.GetOutputPort())
    imgstenc.ReverseStencilOff()
    imgstenc.SetBackgroundValue(outval)
    imgstenc.Update()

    return imgstenc.GetOutput()

However, when I do the same thing in ITK,

    filter= itk.TriangleMeshToBinaryImageFilter[MeshType, ImageType].New()
    filter.SetInput(mesh)
    filter.SetSize(size)
    filter.SetOrigin(origin)
    filter.SetSpacing(spacing)
    filter.SetDirection(direction)
    filter.Update()
    image= filter.GetOutput()

the outputs are different in that they both have the same size,origin,spacing,direction but are in different locations in space as (exported and) viewed in 3DSlicer. The correct mesh-image goes to ITK since when I put up the original image X, it is situated in the correct location. What am I missing in VTK?

Many filters in VTK (including vtkPolyDataToImageStencil) do not support “Direction”. It is not implemented yet.

Thanks David,

That makes sense. Even the origins stop making sense due to the direction being absent. Will support be implemented anytime soon?