[Paraview] AttributeError when transforming vector field

Eric E. Monson emonson at cs.duke.edu
Wed Aug 4 12:04:18 EDT 2010


Hey Camilla,

Is there a reason you're specifying Unstructured Grid on the input and PolyData on the output? Are you trying to use the Programmable Filter to change the data type? I'm wondering if this might be the problem with pdo coming out as None? (Are you setting the Output Data Set Type to PolyData?)

If you're okay with preserving the original data type, you could do something a little simpler which works for me when I test it with a Wavelet Source on which I've run the Gradient filter to get some vector data (and then I tried using a Threshold to change the data type to Unstructured grid in 3d, or slice to try a 2d PolyData before the Programmable Filter, and these worked out fine, too). I think I got the matrix multiplication right, but you'd better check... :)

# ----------------
from paraview import numpy_support as NS
import numpy as N

pdi = self.GetInputDataObject(0,0)
pdo = self.GetOutputDataObject(0)
pdo.ShallowCopy(pdi)

import math

tX = math.radians(5.67)
tY = math.radians(-107.761)
tZ = math.radians(-49.432)

r11 = math.cos(tY)*math.cos(tZ) + math.sin(tX)*math.sin(tY)*math.sin(tZ)
r12 = math.sin(tZ)*math.cos(tX)
r13 = -math.sin(tY)*math.cos(tZ) + math.sin(tX)*math.sin(tZ)*math.cos(tY)
r21 = -math.sin(tZ)*math.cos(tY) - math.cos(tZ)*math.sin(tX)*math.sin(tY)
r22 = math.cos(tX)*math.cos(tZ)
r23 = math.sin(tY)*math.sin(tZ) + math.cos(tZ)*math.cos(tY)*math.sin(tX)
r31 = math.cos(tX)*math.sin(tY)
r32 = -math.sin(tX)
r33 = math.cos(tY)*math.cos(tX)

rr = N.mat([[r11, r12, r13], [r21, r22, r23], [r31, r32, r33]])

vel0 = pdi.GetPointData().GetArray('RTDataGradient')
vel0mat = N.mat(NS.vtk_to_numpy(vel0))
velTrans = vel0mat*rr.T

velNew = NS.numpy_to_vtk(velTrans)
velNew.SetName('TransfVelocity')
pdo.GetPointData().AddArray(velNew)
# ----------------

Talk to you later,
-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


On Aug 3, 2010, at 6:02 PM, ccattani at caltech.edu wrote:

> Hi,
> 
> I am new to Paraview, and I need to write a programmable filter to
> transform a vector field. My filter (below) works when applied to a 2D
> slice extracted from the data, but when I change the input to the original
> 3D dataset, I get the error:
> 
> AttributeError: 'NoneType' object has no attribute 'SetPoints'.
> 
> Any idea of why this happens, and how to fix it?
> Thank you in advance for your help!
> 
> Camilla
> 
> ---------------here's my script:------------------------------------
> 
> import math
> tX=math.radians(5.67)
> tY=math.radians(-107.761)
> tZ=math.radians(-49.432)
> 
> r11=math.cos(tY)*math.cos(tZ)+math.sin(tX)*math.sin(tY)*math.sin(tZ)
> r12=math.sin(tZ)*math.cos(tX)
> r13=-math.sin(tY)*math.cos(tZ)+math.sin(tX)*math.sin(tZ)*math.cos(tY)
> r21=-math.sin(tZ)*math.cos(tY)-math.cos(tZ)*math.sin(tX)*math.sin(tY)
> r22=math.cos(tX)*math.cos(tZ)
> r23=math.sin(tY)*math.sin(tZ)+math.cos(tZ)*math.cos(tY)*math.sin(tX)
> r31=math.cos(tX)*math.sin(tY)
> r32=-math.sin(tX)
> r33=math.cos(tY)*math.cos(tX)
> 
> pdi = self.GetUnstructuredGridInput()
> pdo =  self.GetPolyDataOutput()
> newPoints = vtk.vtkPoints()
> numPoints = pdi.GetNumberOfPoints()
> vel0=pdi.GetPointData().GetArray('velocity')
> vel=vtk.vtkFloatArray()
> vel.SetNumberOfComponents(3)
> vel.SetName('TransfVelocity')
> vel.SetNumberOfTuples(numPoints)
> 
> for i in range(0, numPoints):
>     coord = pdi.GetPoint(i)
>     x,y,z=coord[:3]
>     newPoints.InsertPoint(i, x, y, z)
>     vx=vel0.GetValue(i*3)
>     vy=vel0.GetValue(i*3+1)
>     vz=vel0.GetValue(i*3+2)
>     vxt= r11*vx + r12*vy + r13*vz
>     vyt= r21*vx + r22*vy + r23*vz
>     vzt= r31*vx + r32*vy + r33*vz
>     vel.SetTuple3(i,vxt,vyt,vzt)
> 
> pdo.SetPoints(newPoints)
> pdo.GetPointData().AddArray(vel)
> 
> 
> _______________________________________________
> Powered by 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 ParaView Wiki at: http://paraview.org/Wiki/ParaView
> 
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview



More information about the ParaView mailing list