[vtkusers] confused with vtkProbeFilter
Martin Genet
martin.genet at polytechnique.edu
Mon May 16 16:07:27 EDT 2016
Works like a charm…thanks! Martin
On 16/05/2016 19:55, Sujin Philip wrote:
> Hi Martin,
>
> Attached is the modified script that I ran. This is the output of the
> script:
> pointdata 1 9
> (0.0,) (0.0,) (0.0,) (0.0,) (2.0,) (0.0,) (0.0,) (0.0,) (0.0,)
> celldata 1 9
> (0.0,) (0.0,) (0.0,) (0.0,) (2.0,) (0.0,) (0.0,) (0.0,) (0.0,)
> vtkValidPointMask 1 9
> (0.0,) (0.0,) (0.0,) (0.0,) (1.0,) (0.0,) (0.0,) (0.0,) (0.0,)
>
> The results look correct. Is this not the behaviour you are getting?
> Let me know if you still have issues.
>
> Thanks
> Sujin
>
>
> On Fri, May 13, 2016 at 7:45 PM, Martin Genet
> <martin.genet at polytechnique.edu
> <mailto:martin.genet at polytechnique.edu>> wrote:
>
> Thanks for your help, Sujin.
>
> What do you mean exactly by "your code works for me"? I sat the
> arrays names but am still getting the same behavior: the code runs
> fine, but I can't find the interpolated data. Do you know where it
> is? Thanks again.
>
> Martin
>
>
> On 13/05/2016 18:53, Sujin Philip wrote:
>> Hi Martin,
>>
>> You need to set names for the point and cell data arrays.
>> farray.SetName("pointdata") and farray.SetName("celldata")
>>
>> after doing that your code works for me.
>>
>> -Sujin
>>
>>
>> On Fri, May 13, 2016 at 12:16 PM, Martin Genet
>> <martin.genet at polytechnique.edu
>> <mailto:martin.genet at polytechnique.edu>> wrote:
>>
>> 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
>>
>> _______________________________________________
>> Powered by www.kitware.com <http://www.kitware.com>
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at:
>> http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160516/f1d8d4de/attachment.html>
More information about the vtkusers
mailing list