Accessing points associated to a cell from the Programmable Filter or Python Shell

Hello, I am new to using ParaView. I already browsed ParaView Discourse, User Guide, and python scripting reference but I could not find what I am looking for. I hope you can help me:

My objective:
I am trying to colour faces of a regular orthogonal shape (cube/star) by the face ID. For example, I want to colour a cube’s 6 faces with 6 different colours. Let us suppose that the cube is made from a mesh of triangles.

Chosen method:
In order to assign face colours, I want to first access the cell information—viz., the points of every triangle on each face. I notice from the “SpreadsheetView” that the Cell Data and Points are two different tables, but I am unable to understand how ParaView knows to link a cell with 3 points (vertices of the triangles).

Once I have the vertices of each cellID, I am hoping that I can sort the cells and assign a faceID property to each cell.

Challenge faced:
I am using the paraview vtk.numpy_interface from python. From the following few lines in the ProgrammableFilter:

from paraview.vtk.numpy_interface import dataset_adapter as dsa
from paraview.vtk.numpy_interface import algorithms as algs

data = inputs[0]

I can see some attributes, but nothing that specifically can link the triangles/cells to the points.

Solution requested:

  1. Is there some documentation already on how to achieve what I am trying to do?
  2. Is there an easier solution? I know I can take the stl/vtk file into python (outside of Paraview) and do what I want to do, but I would like to be able to see the face colours directly in ParaView.

Many thanks for your help in advance!


Hi, it’s pretty simple

  • ExtractSurface, Apply
  • GenerateIds, Apply
  • Color by Id (Here I use categorical colors, but that depends what you want)

Hello Mathieu,

Thanks for your prompt response! This method looks cool and I will remember it for future usage, but I am unfortunately unable to use to achieve my end goal.

A simplified description of the problem:
What I am trying to do is assign a “faceID” property to each cell. I want to elaborate with an example:

  1. If I had a spherical surface made of 600 triangles, I want all the 600 triangles to have faceID=1
  2. If I had a square surface with 600 triangles, I there be 6 faceIDs. And each faceID corresponds to 100 triangles. In other words, when I coloured the square, each side of the surface should show up in a distinct colour.

The reason why I am trying to approach this solution through a programmable filter or through python shell is so that I can write a code snippet to sort the various cells and assign a “faceID”.

Desired method:
In the python interface, I think I need a table of cellIDs (or triangle ID) and corresponding points (vertices of the triangles) to sort them. And then, I need to add a faceID column/attribute to the output data structure from which I can “Color by ID” from ParaView.

I can see from ParaView GUI with “Select cells” that it is possible to know which cells are associated with which points. I am just unable to find this data in a tabulated manner.

Would greatly appreciate your help and advice!


Definitely not trivial, you need to be able to descriminate betwee each faces.

Indeed, you can select cells and then extract, but that would be a manual process.

You might be able to do this with the Connectivity filter. (Answering these questions is always easier when you post some example data.) If the triangles of your mesh are sharing points with each other, they will be considered connected, and the Connectivity filter will assign them all the same id. If they are not all connected, you can run the Clean filter to connect them.

Now, it turns out that for polygonal surfaces (like triangular meshes) it is often desirable to “split” the surface along edges with a large bend so that normal shading can represent folds in the surface (like the adjoining faces of your cube). This is so that the triangles on each side of this bend can be different to represent the different angles of light. If your mesh has this feature, it also has by happy accident a split in the mesh that the Connectivity filter will identify as separate parts of the mesh.

If your mesh is not split at the edges, then the Generate Surface Normals filter will do it for you. It has a Splitting feature that when on (the default), it will identify edges with a bend over a certain angle and divide the mesh at those points. This will separate faces of a cube mesh but will keep together the surface of a sphere.

Below is an example where I synthesized a triangular mesh of a cube and then used the sequence of Clean, Generate Surface Normals, and Connectivity to create a RegionId field that identifies each face.

1 Like

Thanks @Kenneth_Moreland and @mwestphal!

I somehow lost your messages in my mailbox, and I only discovered your messages today.

You’re right, I should have shared an.stl file, although I only simply created a star geometry from source for testing/learning purposes. I’ll keep this tip in mind for next time.

The Connectivity filter did the trick indeed, thanks! I was struggling with the Generate Surface Normals + Programmable Filter as I was trying to do what Connectivity probably does, but from python.

This issue is solved! I will raise a new question regarding the ProgrammableFilter and the python interface if the need for it comes up again.

Thanks and regards,