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:
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.
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.
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
I can see some attributes, but nothing that specifically can link the triangles/cells to the points.
Is there some documentation already on how to achieve what I am trying to do?
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.
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:
If I had a spherical surface made of 600 triangles, I want all the 600 triangles to have faceID=1
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”.
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.
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.