<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
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.<br>
<br>
<div class="moz-cite-prefix">On 05/16/2014 02:07 PM, Burlen Loring
wrote:<br>
</div>
<blockquote cite="mid:53767E2C.5020903@lbl.gov" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
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.
<br>
<br>
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....<br>
<br>
<div class="moz-cite-prefix">On 05/16/2014 01:43 PM, Su, Simon M
CTR USARMY ARL (US) wrote:<br>
</div>
<blockquote
cite="mid:F02E4EC9F4B4BA4189BBDC8BF3B2AD820ECE7D41@umechp9h.easf.csd.disa.mil"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<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
face="Tahoma" size="2" color="#000000"><b>From:</b>
Burlen Loring [<a moz-do-not-send="true"
class="moz-txt-link-abbreviated"
href="mailto:bloring@lbl.gov">bloring@lbl.gov</a>]<br>
<b>Sent:</b> Friday, May 16, 2014 4:23 PM<br>
<b>To:</b> Su, Simon M CTR USARMY ARL (US); <a
moz-do-not-send="true"
class="moz-txt-link-abbreviated"
href="mailto:paraview@paraview.org">paraview@paraview.org</a><br>
<b>Subject:</b> Re: [Paraview] Accessing a specific
variable in Python Programmable Filter<br>
</font><br>
</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 moz-do-not-send="true"
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 moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.kitware.com" target="_blank">www.kitware.com</a>
Visit other Kitware open-source projects at <a moz-do-not-send="true" 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 moz-do-not-send="true" 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 moz-do-not-send="true" 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>
</blockquote>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">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">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">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">http://www.paraview.org/mailman/listinfo/paraview</a>
</pre>
</blockquote>
<br>
</body>
</html>