[vtkusers] confused with vtkProbeFilter
Martin Genet
martin.genet at polytechnique.edu
Fri May 13 12:16:36 EDT 2016
Dear everyone:
Sorry for the triviality, but I'm getting confused with vtkProbeFilter:
trying to probe an image with a mesh (not the opposite: I need the mesh
data interpolated onto the image points), but can't get it to work.
Consider the following code:
> import numpy
> import vtk
>
> image = vtk.vtkImageData()
> image.SetDimensions([3, 3, 1])
> image.SetSpacing(1./numpy.array(image.GetDimensions()))
> image.SetOrigin(numpy.array(image.GetSpacing())/2)
>
> points = vtk.vtkPoints()
> points.InsertNextPoint([1./4, 1./4, 2./4])
> points.InsertNextPoint([3./4, 1./4, 2./4])
> points.InsertNextPoint([3./4, 3./4, 2./4])
> points.InsertNextPoint([1./4, 3./4, 2./4])
>
> cell = vtk.vtkQuad()
> cell.GetPointIds().SetId(0, 0)
> cell.GetPointIds().SetId(1, 1)
> cell.GetPointIds().SetId(2, 2)
> cell.GetPointIds().SetId(3, 3)
>
> cell_array = vtk.vtkCellArray()
> cell_array.InsertNextCell(cell)
>
> ugrid = vtk.vtkUnstructuredGrid()
> ugrid.SetPoints(points)
> ugrid.SetCells(vtk.VTK_QUAD, cell_array)
>
> farray = vtk.vtkFloatArray()
> farray.SetNumberOfComponents(1)
> farray.SetNumberOfTuples(1)
> farray.SetTuple1(0, 2.)
> ugrid.GetCellData().AddArray(farray)
>
> farray = vtk.vtkFloatArray()
> farray.SetNumberOfComponents(1)
> farray.SetNumberOfTuples(4)
> farray.SetTuple1(0, 2.)
> farray.SetTuple1(2, 2.)
> farray.SetTuple1(3, 2.)
> farray.SetTuple1(4, 2.)
> ugrid.GetPointData().AddArray(farray)
>
> probe = vtk.vtkProbeFilter()
> if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
> probe.SetInputData(image)
> probe.SetSourceData(ugrid)
> else:
> probe.SetInput(image)
> probe.SetSource(ugrid)
> probe.Update()
> probed_image = probe.GetOutput()
Problem is: probed_image contains only one array, called
vtkValidPointMask, but no interpolated data.
If I do:
> probed_scalars = probed_image.GetPointData().GetArray("vtkValidPointMask")
> for k_voxels in xrange(probed_scalars.GetNumberOfTuples()): print
> probed_scalars.GetTuple1(k_voxels)
I'm getting:
> 0.0
> 0.0
> 0.0
> 0.0
> 1.0
> 0.0
> 0.0
> 0.0
> 0.0
So I'm guessing the filter is able to figure out which image point lies
within the mesh and which does not, but I can't find the interpolated
data? Any help would be super appreciated. Thanks!
Martin
More information about the vtkusers
mailing list