Hi Liam,<br><br>this is how I usually add arrays to image data<br><br>        vtkDataArray *Velocity;<br>        Velocity = Velocity-&gt;CreateDataArray(VTK_DOUBLE);<br>        Velocity-&gt;SetNumberOfComponents(3);<br>        Velocity-&gt;SetNumberOfTuples(grid-&gt;GetNumberOfPoints());<br>
        Velocity-&gt;SetName(&quot;vertexVelocity&quot;);<br>        grid-&gt;GetPointData()-&gt;AddArray(Velocity);<br><br>        vtkDataArray *Density;<br>
        Density =Density -&gt;CreateDataArray(VTK_DOUBLE);<br>
        Density-&gt;SetNumberOfComponents(1);<br>
        Density -&gt;SetNumberOfTuples(grid-&gt;GetNumberOfPoints());<br>
        Density-&gt;SetName(&quot;Density&quot;);<br>
        grid-&gt;GetPointData()-&gt;AddArray(Density);<br><br>I checked my arrays, they look ok.<br>I was able to calculate avg just using for-loop,<br>but I&#39;d still like to understand/use vtk functions for<br>these tasks.<br>
<br>Thank you,<br>ula <br>
<br><br><br><div class="gmail_quote">On Fri, Apr 29, 2011 at 3:07 AM, Liam Kurmos <span dir="ltr">&lt;<a href="mailto:quantum.leaf@gmail.com">quantum.leaf@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
hi Ula,<br>
<br>
can i see the code for how you add the 2 fields to the imagedata?<br>
<br>
thanks,<br>
<br>
Liam<br>
<div><div></div><div class="h5"><br>
<br>
On Fri, Apr 29, 2011 at 7:33 AM, Ula Popov &lt;<a href="mailto:ula.popov@gmail.com">ula.popov@gmail.com</a>&gt; wrote:<br>
&gt; Hello all,<br>
&gt;<br>
&gt; I have an object of class vtkImageData.<br>
&gt; It has two arrays: density (scalar) and velocity (vector).<br>
&gt;<br>
&gt; I want to know mean and median values of the density field.<br>
&gt;<br>
&gt; I tried to use vtkImageAccumulate to achieve this goal, but<br>
&gt; my program crashes on my input (actually, I don&#39;t know how<br>
&gt; to specify on which of the arrays I want to apply. How<br>
&gt; should I do it?)<br>
&gt; When I tried to specify origin and spacing, I got similar result (seg fault)<br>
&gt;<br>
&gt;         vtkImageAccumulate *Accumulate = vtkImageAccumulate::New();<br>
&gt;<br>
&gt; Accumulate-&gt;SetInput(grid);<br>
&gt;<br>
&gt; Accumulate-&gt;Update();<br>
&gt; &lt;------- crashes here<br>
&gt;         double *mean = Accumulate-&gt;GetMean();<br>
&gt;<br>
&gt;<br>
&gt; Thank you!<br>
&gt; ula<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the VTK FAQ at:<br>
&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br>