[Paraview] Centering data

Eric E. Monson emonson at cs.duke.edu
Sat Aug 7 20:03:39 EDT 2010


Hey David,

Here's another alternative using numpy. There may be a slightly more straightforward way to do it (so anyone please feel free to edit it, or pass along refinements/advice and I can edit it), but it works for me.

http://www.paraview.org/Wiki/Python_Programmable_Filter#Center_Data_using_numpy

from paraview.vtk import dataset_adapter as DA

pdi = self.GetInputDataObject(0,0)
pdo = self.GetOutputDataObject(0)
pdo.CopyAttributes(pdi)

old_pts = inputs[0].Points
new_pts = old_pts - mean(old_pts, axis=0)
arr = DA.numpyTovtkDataArray(new_pts, 'newpts')
pdo.GetPoints().SetData(arr)

Talk to you later,
-Eric


On Aug 6, 2010, at 12:27 PM, David Doria wrote:

> On Fri, Aug 6, 2010 at 12:21 PM, Moreland, Kenneth <kmorel at sandia.gov> wrote:
>> For the record, Andy’s method is attempting to find the center of mass
>> (assuming uniform density).  If you just need the center of the bounds, you
>> can go to the information panel, average the bounds in each dimension, and
>> then do a translate transform to move that point to the origin.
>> 
>> -Ken
> 
> Here is a programmable filter that does the trick:
> http://www.paraview.org/Wiki/Python_Programmable_Filter#Center_Data
> 
> Thanks all,
> 
> David
> _______________________________________________
> 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



More information about the ParaView mailing list