Reputation: 11
I am trying to label vtkPolyData
points with a scalar taken from my 3d volume vtkImageData
of scalars. I have already done this, by using the GetPoint()
function on the vtkPolyData
point, calculating the id of the nearest point in the vtkImageData
object, then getting the value from its scalar array. However, I would like to be able to do this by interpolating the scalar value, because currently the output is quite blocky / noisy as my 3d vtkImageData
is formed from putting 2d slices on top of one another. I am struggling to find a way I can either interpolate the vtkImageData
values, or get an interpolated value for my vtkPolyData
. I have seen mentions of the InterpolatePoint()
function and the vtkProbeFilter
, but I am not sure about either of those as I couldn't get them to work and there isn't a lot of example code to go off.
Upvotes: 1
Views: 661
Reputation: 4725
I have just tried out the vtkProbeFilter
and it seems to do the job.
import vtk
namedColors = vtk.vtkNamedColors()
# Mesh coordinates are within the 3D image. It could be an iso surface
filename = 'mesh.vtp'
reader0 = vtk.vtkXMLPolyDataReader()
reader0.SetFileName(filename)
reader0.Update()
# 3D image data
fileName = 'image.mhd'
reader1 = vtk.vtkMetaImageReader()
reader1.SetFileName(fileName)
reader1.Update()
rng = reader1.GetOutput().GetScalarRange()
# You can narrow this down to the range around your value used for extracting
# the iso surface
fMin = rng[0]
fMax = rng[1]
probe = vtk.vtkProbeFilter()
probe.SetInputConnection(reader0.GetOutputPort())
probe.SetSourceData(reader1.GetOutput())
probe.Update()
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(probe.GetOutputPort())
lut = vtk.vtkLookupTable()
lut.SetTableRange(fMin, fMax)
# We want same saturation for all values in the LUT
lut.SetSaturationRange(1.0, 1.0)
lut.Build()
mapper = vtk.vtkPolyDataMapper()
mapper.ScalarVisibilityOn()
mapper.SetLookupTable(lut)
mapper.SetInputConnection(normals.GetOutputPort())
mapper.SetScalarRange(fMin, fMax)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderWindow = vtk.vtkRenderWindow()
renderWindow.SetSize(600, 600)
renderWindow.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
renderWindow.Render()
interactor.Start()
Here the code is used for coloring the surface of the hepatic veins in the Liver using values extracted from a CT image.
Upvotes: 1