vtkProbeFilter speed vtkImageData vs. vtkStructuredGrid

Hi all,

Im posting because I have an analysis that performed one way (with vtkImageData) is very fast and another (vtkStructuredGrid) is insanely slow.

I have a polydata that I project a vector from (using normals at each point) to create a vtkLineSource. I then probe values along this line using vtkProbeFilter(). The problem comes if I give vtkStructuredGrid instead of vtkImageData to the vtkProbeFilter.

E.g.,

line = vtk.vtkLineSource()
line.SetResolution(line_resolution)

probe_filter = vtk.vtkProbeFilter()
probe_filter.SetSourceData(vtk_image)   # This originally was vtkImageData - now I am trying vtkStructuredGrid
probe_filter.SetInputConnection(line.GetOutputPort())

points = mesh.GetPoints()
normals = (local function gets this for me)

for idx in range(points.GetNumberOfPoints()):
    # Some code gets a normal, a length, and a starting point to yield a line start/end
    start_pt = (local code gets this)
    end_pt = (local code gets this)

    line.SetPoint1(start_pt)
    line.SetPoint2(end_pt)

    probe_filter.Update()


If probe_filter.SetSourceData(vtkImageData) then it iterates over and processes 20k points <1second. If I probe_filter.SetSourceData(vtkStructuredGrid) and print stuff on each loop to check out timing the vtkStructuredGrid results appear to pop out in chunks. E.g., 5-6 points are processed immediately then there is a 2-3 second gap before another 5-6 pop out.

You might be wondering why I am trying to use vtkStructuredGrid. The reason is that I want to rotate the image data using a transformation matrix (vtkTransformFilter()). Which you cant do for a vtkImageData… well you can, but it returns a vtkStructuredGrid. I’ve already tried (and it works) to apply the inverse transform to the polydata and then do the probing. The problem is that I have 2 sets of images and 1 polydata. The images arent aligned with one another. So, if I rotate the polydata to align with one image it isnt aligned with the other. So, I’m hoping to transform the images to match one another (I already have a transformation matrix from ITK).

It might simply be that this operation is slow. Or I could be doing something silly. Curious if anyone has any thoughts/insights that might help.

Thanks!

Anthony

Images can be rotated (not just that, but arbitrarily warped) using vtkImageReslice filter. The result is a vtkImageData.

But you can probe rotated image without resampling, too. You just need to transform the sampling points with the inverse rotation, do the sampling, then transform back.

In current VTK version you have an even simpler option: you can rotate a image by changing direction matrix in vtkImageData.

2 Likes

Thanks @lassoan!

Those all sound like great suggestions for my problem. I’ll give them a try.

For the new version of VTK you mention (applying transform to direction matrix), does this mean that vtkImageData doesn’t have to be orthogonal to the global x/y/z anymore? I thought I read somewhere that this was a limitation of the vtkImageData class.

Thanks.

Anthony.

Yes, after many years of suffering, finally vtkImageData can represent arbitrarily oriented axes.

1 Like