PLY face element

I’m using vtk in Python to view and make screenshots of some .ply files. I’m completely new to vtk, but i have managed to load and view vertices. How do I load the face element of .ply file and view them in render window?

This is my .ply header:

format ascii 1.0
comment VCGLIB generated
element vertex 178241
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
property uchar alpha
element face 356502
property list uchar int vertex_indices
property int flags

Thank you.

Are you trying to read the PLY file yourself? You don’t need to do that. VTK has a vtkPLYReader class that can load the file for you.

Here’s a python example show its use:

I’m using the vtkPLYReader. I have pretty much what the example is showing. I just don’t know where the face elements are loaded, and how to use them.

That example reads the PLY file and give it to a vtkActor object. That actor object has all the ply file data in a vtkPolyData object. So that includes the vertices and the faces. The actor is then given to the renderer for display.

If you just want to load a PLY file and than display it, that example does exactly that.

If you are completely new to VTK and using Python, I would highly recommend trying a wrapper around VTK like PyVista: - VTK can be a bit tough to get started and PyVista (or vtkplotter) will streamline a lot of the nuanced routines you have to set up

Loading and plotting a PLY file with PyVista is as simple as:

import pyvista as pv
mesh ="my_file.ply")
1 Like

Ok, thank you. I think I understand my problem now. I think my problem is with the face flags. It is used in MeshLab, and I thought it was universally used. What i need is to change the color of faces according to this flag. Is there an easy way to do this? From documentation it seems the vtkPLYReader will not read this flag.