How to add a custom array to a polydata in paraview?

喜你入骨 提交于 2019-12-30 10:05:44

问题


I know that I can use the Calculator filter for operations on arrays, but I want to perform some more complicated computations. I managed to do it in Paraview python shell, but the missing step now is to go back to the viewer again (or save the new polydata to file). Here is what I have so far:

polydata = servermanager.Fetch(FindSource("mydataalreadyopeninparaview"))
region_size = paraview.vtk.vtkIntArray()
region_size.SetNumberOfComponents(0)
region_size.SetName("regionsize")
for i in range(polydata .GetNumberOfPoints()):
   region_size.InsertNextValue(somecomputedvalue)
polydata.GetPointData().AddArray(region_size)

How can I "import" in the paraview pipeline my newly created data?


回答1:


Better approach would be use the Programmable Filter to add the array to your input dataset. In ParaView 4.1, the following script can be added to the Script on Properties panel for the Programmager Filter

polydata = output
array = vtk.vtkIntArray()
array.SetNumberOfComponents(0)
array.SetName("regionsize")
for i in range(polydata .GetNumberOfPoints()):
    array.InsertNextValue(somecomputedvalue)
polydata.GetPointData().AddArray(array);



回答2:


The method which works better with the pipeline is using a programmable filter. (related: Paraview Python -- Reverse operation to servermanager.Fetch()? )

For saving the new polydata to file: (discovered thanks to http://markmail.org/message/4kp7cxl2ani25cak when importing all ctk modules)

from paraview.vtk.vtkIOLegacy import *
writer = vtkPolyDataWriter()
.....

A more "rough" method is to export the data as csv using numpy.savetxt , then reading the csv and apply the TableToPoints filter or Python scripting.

It could be possible to use TrivialProducer and GetClientSideObject when client and server share the same memory space (with the builtin server) as explained here http://public.kitware.com/pipermail/paraview/2011-February/020120.html , but I haven't tried it



来源:https://stackoverflow.com/questions/24220250/how-to-add-a-custom-array-to-a-polydata-in-paraview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!