[Paraview] Programmable filter works on Slice but not on original data set
Ganesh Vijayakumar
ganesh.iitm at gmail.com
Thu Aug 28 16:24:07 EDT 2014
Hello,
I figured out that the input data set is of type vtkImage while the Slice
is type Polygonal. Hence my script seems to work on the Polygonal data set.
This is how you get add a vector array to a Cell based vtkImage dataset.
import numpy as np
from paraview.vtk.dataset_adapter import numpyTovtkDataArray
output = self.GetImageDataOutput()
u = inputs[0].CellData["U"]
d = inputs[0].GetDimensions()
dz = 2048/256.0
uPrime = np.empty([d[2],d[1],d[0],3])
print d
for i in range(d[0]):
for j in range(d[1]):
for k in range(d[2]):
uPrime[k,j,i] = np.array([0,0,k*dz + 4.0])
uPrime = uPrime.reshape((d[0]*d[1]*d[2],3))
uPrimeVTK = numpyTovtkDataArray(uPrime)
uPrimeVTK.SetName('uPrime')
output.GetCellData().AddArray(uPrimeVTK)
On Thu, Aug 28, 2014 at 11:53 AM, Ganesh Vijayakumar <ganesh.iitm at gmail.com>
wrote:
> Hello,
>
>
> My original dataset is an xdmf file that points to some hdf5 files. I
> have this piece of code in a programmable filter. It seems to work on a
> Slice of the original dataset, but won't work on the dataset as a whole.
> The original dataset is cell centered and I then pass it through a
> "CellDataToPointData" filter. Could anyone tell me why? I'm running
> Paraview 4.1 - 64 bit on a server-client mode with the server using 16
> cores. I thought it might be related to the dataset being multiblock or
> something (I don't understand this very well). So I tried the piece of code
> here
>
>
> http://www.paraview.org/Wiki/Python_Programmable_Filter#Dealing_with_Composite_Datasets
>
> This also works on the slice.. but not on the whole dataset.
>
>
> #Programmable filter code below
>
> import numpy as np
> from paraview import vtk
> from paraview.vtk.dataset_adapter import numpyTovtkDataArray
> from scipy.interpolate import interp1d
>
> initrLoc = array([0, 2.8667, 5.6, 8.3333, 11.75, 15.85, 19.95, 24.05,
> 28.15, 32.25, 36.35, 40.45, 44.55, 48.65, 52.75, 56.1667, 58.9, \
> 61.633, 62.9, 300.0])
> initaeroTwist = array([13.308, 13.308, 13.308, 13.308, 13.308, 11.48,
> 10.162, 9.011, 7.795, 6.544, 5.361, 4.188, 3.125, 2.319, 1.526, \
> 0.863, 0.37, 0.106, 0, 0.0])
> pitch = 8.7
> aeroTwistInterp = interp1d(initrLoc, initaeroTwist+pitch)
>
>
> uxym = np.loadtxt('uxym')
> umeanInterp = interp1d(uxym[:,2], uxym[:,0]*cos(21.6*np.pi/180.
> 0) + uxym[:,1]*sin(21.6*np.pi/180.0))
> vmeanInterp = interp1d(uxym[:,2], -uxym[:,0]*sin(21.6*np.pi/180.0) +
> uxym[:,1]*cos(21.6*np.pi/180.0))
>
> input = self.GetInput()
> output = self.GetOutput()
> output.ShallowCopy(input)
> points = inputs[0].Points[:,:]
> nPoints = np.size(points,0)
> vel = inputs[0].PointData['U']
> uPrime = np.empty(np.shape(vel))
> AoACyl = np.empty(np.size(vel,0))
> omega = (12.0 * 2 * np.pi / 60.0) * array([1,0,0])
> for i in range(nPoints):
> uPrime[i] = array([umeanInterp(points[i,2]),vmeanInterp(points[i,2]),
> 0.0])
> r = array([0, 15, 0])
> localTwist = aeroTwistInterp(15)
> newVel = vel[i] - np.cross(omega, r)
> AoACyl[i] = arctan2(newVel[0,1],-newVel[0,2])*180/np.pi - localTwist
>
> uPrimeVTK = numpyTovtkDataArray(uPrime)
> uPrimeVTK.SetName('uPrime')
> output.GetPointData().AddArray(uPrimeVTK)
>
> AoACylVTK = numpyTovtkDataArray(AoACyl)
> AoACylVTK.SetName('AoACyl')
> output.GetPointData().AddArray(AoACylVTK)
>
>
> --
> ganesh
>
--
ganesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20140828/7a312b2b/attachment-0001.html>
More information about the ParaView
mailing list