correction, Dave D. just pointed out to me that since PV 4.0 the shallow copy is no longer needed because of the VTK 6.0 pipeline improvements.

On 05/16/2014 02:07 PM, Burlen Loring wrote:
By the way, the example following that is buggy as well, when you apply an internal filter you first need to shallow copy the input.

I fixed both of these, although I think these examples(ones in Examples section) are not great ones in the first place and don't add much to the already pretty comprehensive examples preceding them, I would vote to remove them. However, I'll leave this up to the real pv developers....

On 05/16/2014 01:43 PM, Su, Simon M CTR USARMY ARL (US) wrote:
Thanks Burlen
-simon

------------------------------------------------------------------------
*From:* Burlen Loring [[email protected]]
*Sent:* Friday, May 16, 2014 4:23 PM
*To:* Su, Simon M CTR USARMY ARL (US); [email protected]
*Subject:* Re: [Paraview] Accessing a specific variable in Python Programmable Filter

=============================
input  =self.GetPolyDataInput();
output =self.GetPolyDataOutput();
colors = vtk.vtkUnsignedCharArray();
colors.SetNumberOfComponents(3);
colors.SetName("Colors");
numPoints =input.GetNumberOfPoints()
for  iin  range(0, numPoints):
     colors.InsertNextTuple3(255,0,0);
output=input
output.GetPointData().AddArray(colors)
===============================
Not sure how this got on the wiki but this is an example of what *not* to do!!

In a VTK filter one's never supposed to modify the input.
output=input
output.GetPointData().AddArray(colors)
This is exactly what's done here. Of course you're not going to find the array in the filter's output if you're adding it to the input!

This code can be fixed by removing the output=input line. With that change you should be able to see the array in downstream filters. note, in python 2 range actually generates a list with all the values in it, while xrange creates an iterator which is far more efficient. To actually use the colors you'll also have to uncheck the map scalars check box in the display properties.

input = self.GetPolyDataInput();

output = self.GetPolyDataOutput();

colors = vtk.vtkUnsignedCharArray();

colors.SetNumberOfComponents(3);

colors.SetName("Colors");

numPoints = input.GetNumberOfPoints()

for i in xrange(0, numPoints):

colors.InsertNextTuple3(0,255,0);

output.GetPointData().AddArray(colors)

del colors



On 05/16/2014 12:46 PM, Su, Simon M CTR USARMY ARL (US) wrote:
Hello,

After staring at http://www.paraview.org/Wiki/Python_Programmable_Filter for a while, the way to access the data for a specific variable name still eludes me. This is the python code from the wiki on Add the Colors variable to a PolyData

=============================
input  =self.GetPolyDataInput();
output =self.GetPolyDataOutput();
colors = vtk.vtkUnsignedCharArray();
colors.SetNumberOfComponents(3);
colors.SetName("Colors");
numPoints =input.GetNumberOfPoints()
for  iin  range(0, numPoints):
     colors.InsertNextTuple3(255,0,0);
output=input
output.GetPointData().AddArray(colors)
===============================

How do I from the next filter, access the variable name "Colors" that I created?

Any help is much appreciated.

thanks
-simon


_______________________________________________
Powered bywww.kitware.com

Visit other Kitware open-source projects 
athttp://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




_______________________________________________
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

_______________________________________________
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

Reply via email to