Add custom property to vtkXMLUnstructuredGrid using python

277 views Asked by At

I have a .vtu file representing a mesh which I read through vtkXMLUnstructuredGridReader. Then I create a numpy array (nbOfPoints x 3) in which I store the mesh vertex coordinates, which I'll call meshArray. I also have a column array (nOfPoints x 1), which I'll call brightnessArray, which represents a certain property I want to assign to the vertexes of the meshArray; so to each vertex corresponds a scalar value. For example: to the element meshArray[0] will correspond brightnessArray[0] and so on. How can I do this?

It is then possible to interpolate the value at the vertexes of the mesh to obtain a smooth variation of the property I had set in order to visualize it in paraview?

Thank you. Simon

1

There are 1 answers

0
Mathieu Westphal On

Here is what you need to do :

  1. Write a Python Programmable Source to read your numpy data as a vtkUnstructuredGrid. Here are a few examples of programmable sources : https://www.paraview.org/Wiki/ParaView/Simple_ParaView_3_Python_Filters https://www.paraview.org/Wiki/Python_Programmable_Filter

  2. Read your .vtu dataset

  3. Use a "Ressample with Dataset" filter on your python programmable source output and select your dataset as "source"

And you're done.

The hardest part is writing the programmble source script.