<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<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>
<meta name="qrichtext" content="1">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<style type="text/css">
p, li { white-space: pre-wrap; }
</style>
<meta name="qrichtext" content="1">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;"><!--StartFragment-->input
= self.GetPolyDataInput();</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">output =
self.GetPolyDataOutput();</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">colors =
vtk.vtkUnsignedCharArray();</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">colors.SetNumberOfComponents(3);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">colors.SetName("Colors");</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">numPoints
= input.GetNumberOfPoints()</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">for i in
xrange(0, numPoints):</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">
colors.InsertNextTuple3(0,255,0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">output.GetPointData().AddArray(colors)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;">del colors<!--EndFragment--></p>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<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
cite="mid:F02E4EC9F4B4BA4189BBDC8BF3B2AD820ECE78BD@umechp9h.easf.csd.disa.mil"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<style id="owaParaStyle" type="text/css">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"></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>