<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body ocsi="0" fpstyle="1" bgcolor="#FFFFFF">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Thanks Burlen<br>
-simon<br>
<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF695062"><font color="#000000" face="Tahoma" size="2"><b>From:</b> Burlen Loring [bloring@lbl.gov]<br>
<b>Sent:</b> Friday, May 16, 2014 4:23 PM<br>
<b>To:</b> Su, Simon M CTR USARMY ARL (US); paraview@paraview.org<br>
<b>Subject:</b> Re: [Paraview] Accessing a specific variable in Python Programmable Filter<br>
</font><br>
</div>
<div></div>
<div>
<blockquote type="cite">=============================<br>
<div dir="ltr" class="mw-geshi" style="text-align:left">
<div class="python source-python">
<pre class="de1"><span class="kw2">input</span> = <span class="kw2">self</span>.<span class="me1">GetPolyDataInput</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span>
output = <span class="kw2">self</span>.<span class="me1">GetPolyDataOutput</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span>
colors = vtk.<span class="me1">vtkUnsignedCharArray</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span>
colors.<span class="me1">SetNumberOfComponents</span><span class="br0">(</span><span class="nu0">3</span><span class="br0">)</span><span class="sy0">;</span>
colors.<span class="me1">SetName</span><span class="br0">(</span><span class="st0">"Colors"</span><span class="br0">)</span><span class="sy0">;</span>
numPoints = <span class="kw2">input</span>.<span class="me1">GetNumberOfPoints</span><span class="br0">(</span><span class="br0">)</span>
<span class="kw1">for</span> i <span class="kw1">in</span> <span class="kw2">range</span><span class="br0">(</span><span class="nu0">0</span>, numPoints<span class="br0">)</span>:
colors.<span class="me1">InsertNextTuple3</span><span class="br0">(</span><span class="nu0">255</span>,<span class="nu0">0</span>,<span class="nu0">0</span><span class="br0">)</span><span class="sy0">;</span>
output=<span class="kw2">input</span>
output.<span class="me1">GetPointData</span><span class="br0">(</span><span class="br0">)</span>.<span class="me1">AddArray</span><span class="br0">(</span>colors<span class="br0">)</span></pre>
</div>
</div>
===============================</blockquote>
Not sure how this got on the wiki but this is an example of what *not* to do!!<br>
<br>
In a VTK filter one's never supposed to modify the input. <br>
<blockquote type="cite">
<pre class="de1">output=<span class="kw2">input</span>
output.<span class="me1">GetPointData</span><span class="br0">(</span><span class="br0">)</span>.<span class="me1">AddArray</span><span class="br0">(</span>colors<span class="br0">)</span></pre>
</blockquote>
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!<br>
<br>
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.<br>
<br>
<style type="text/css">
<!--
p, li
{white-space:pre-wrap}
-->
</style>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
input = self.GetPolyDataInput();</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
output = self.GetPolyDataOutput();</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
colors = vtk.vtkUnsignedCharArray();</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
colors.SetNumberOfComponents(3);</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
colors.SetName("Colors");</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
numPoints = input.GetNumberOfPoints()</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
for i in xrange(0, numPoints):</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
colors.InsertNextTuple3(0,255,0);</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
output.GetPointData().AddArray(colors)</p>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
del colors</p>
<style type="text/css">
<!--
p, li
{white-space:pre-wrap}
-->
</style><br>
<br>
<div class="moz-cite-prefix">On 05/16/2014 12:46 PM, Su, Simon M CTR USARMY ARL (US) wrote:<br>
</div>
<blockquote type="cite"><style id="owaParaStyle" type="text/css">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
BODY {direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;}P {margin-top:0;margin-bottom:0;}</style>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Hello,<br>
<br>
After staring at <a href="http://www.paraview.org/Wiki/Python_Programmable_Filter" target="_blank">
http://www.paraview.org/Wiki/Python_Programmable_Filter</a> 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<br>
<br>
=============================<br>
<div dir="ltr" class="mw-geshi" style="text-align:left">
<div class="python source-python">
<pre class="de1"><span class="kw2">input</span> = <span class="kw2">self</span>.<span class="me1">GetPolyDataInput</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span>
output = <span class="kw2">self</span>.<span class="me1">GetPolyDataOutput</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span>
colors = vtk.<span class="me1">vtkUnsignedCharArray</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span>
colors.<span class="me1">SetNumberOfComponents</span><span class="br0">(</span><span class="nu0">3</span><span class="br0">)</span><span class="sy0">;</span>
colors.<span class="me1">SetName</span><span class="br0">(</span><span class="st0">"Colors"</span><span class="br0">)</span><span class="sy0">;</span>
numPoints = <span class="kw2">input</span>.<span class="me1">GetNumberOfPoints</span><span class="br0">(</span><span class="br0">)</span>
<span class="kw1">for</span> i <span class="kw1">in</span> <span class="kw2">range</span><span class="br0">(</span><span class="nu0">0</span>, numPoints<span class="br0">)</span>:
colors.<span class="me1">InsertNextTuple3</span><span class="br0">(</span><span class="nu0">255</span>,<span class="nu0">0</span>,<span class="nu0">0</span><span class="br0">)</span><span class="sy0">;</span>
output=<span class="kw2">input</span>
output.<span class="me1">GetPointData</span><span class="br0">(</span><span class="br0">)</span>.<span class="me1">AddArray</span><span class="br0">(</span>colors<span class="br0">)</span></pre>
</div>
</div>
===============================<br>
<br>
How do I from the next filter, access the variable name "Colors" that I created? <br>
<br>
Any help is much appreciated. <br>
<br>
thanks<br>
-simon<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader" target="_blank"></fieldset> <br>
<pre>_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com" target="_blank">www.kitware.com</a>
Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the ParaView Wiki at: <a class="moz-txt-link-freetext" href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/ParaView</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/mailman/listinfo/paraview</a>
</pre>
</blockquote>
<br>
</div>
</div>
</div>
</body>
</html>