[vtkusers] Compute vorticity from imagedata

Stephen Hamilton stephenshamilton at gmail.com
Wed Jun 10 18:15:36 EDT 2015


Hi,

I'm fairly new to VTK, but I've been stuck for over a day on trying to
figure out a fairly simple task.

I have a numpy array that I'm trying to convert to image data (structured
grid), compute the vorticity, and use the cellderivatives to create an
array of vorticity magnitude.  I can do this easily in Paraview, but in
python the cell derivatives never seem to compute.

Here is what I have so far:
vtkdata = numpy_support.numpy_to_vtk(h5file[i][:,:,:,:].ravel(), deep=True,
array_type=vtk.VTK_FLOAT)
vtkdata.SetNumberOfComponents(3)
image = vtk.vtkImageData()
image.SetDimensions(xl, yl, zl)   #This is set above and matches the numpy
array
image.GetPointData().AddArray(vtkdata)

At this point, if I write the vti file using vtkXMLImageDataWriter(), I get
what I expect in Paraview when I load it.

Here is where I have problems:

vorticity = vtk.vtkCellDerivatives()
vorticity.SetVectorModeToComputeVorticity()
vorticity.SetInputData(image)
vorticity.Update()
vwriter = vtk.vtkXMLImageDataWriter()
vwriter.SetInputData(vorticity.GetOutput())
vwriter.SetFileName("vorticity.vti")

When I check the vorticity file, it is basically the same as if I never
applied the cell derivative filter.  I've tried using the imagestreamer,
and basically still get the same results.  I can't seem to find a good vtk6
example on the web that is close enough to what I'm trying.  I also tried
the threshold function, and got the same thing, so I think I'm applying the
filter incorrectly (not at all in the case).

Any help would be much appreciated!

Thanks.
Stephen
PhD Student, Johns Hopkins University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150610/69e1ff40/attachment.html>


More information about the vtkusers mailing list