[Paraview] Sum values of scalar vector

Christian Richter christian.richter at ovgu.de
Sat Nov 3 04:53:19 EDT 2012


Hi,

in a programmable Filter do something like this:

  import math
  input = self.GetInputDataObject(0, 0)
  output = self.GetOutputDataObject(0)
  COUNT=input.GetNumberOfPoints()
  pd=input.GetPointData()
  m=0
  v=0
  for i in xrange(COUNT):
   r=pd.GetArray('radius').GetValue(i)
   v=v+((4.0/3.0)*math.pi*r*r*r)
   m=m+pd.GetArray('Mass').GetValue(i)
  outputarray = vtk.vtkStringArray()
  outputarray.SetName("Text")
  outputarray.SetNumberOfTuples(1)
  outputarray.SetValue(0,"N=%d\nV=%1.6f m³\nm=%1.6f kg" % (COUNT,v,m))
  output.GetRowData().AddArray(outputarray)

Attention: if you save this to a state-file change the ³ to 3 because it 
will not be escaped and you can not load the state anymore.

best wishes,
Christian

Am 02.11.2012 21:49, schrieb Scott Ripplinger:
> I need to sum all the values in a vector of a scalar property.  I've 
> struggled understanding the documentation for the python calculator 
> and programmable filter, mainly in how to access the point data that I 
> want to use.  Any tips will be appreciated.
>
>
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20121103/f31ce402/attachment.htm>


More information about the ParaView mailing list