15

I need to read, manipulate and write PLY files in Python. PLY is a format for storing 3D objects. Through a simple search I've found two relevant libraries, PyMesh and plyfile. Has anyone had any experience with either of them, and does anyone have any recommendations? plyfile seems to have been dormant for a year now, judging by Github.

I know this question instigates opinion-based answers but I don't really know where else to ask this question.

Ray
  • 7,833
  • 13
  • 57
  • 91

4 Answers4

13

As of (2020 January).

None, use open3d. It's the easiest and reads .ply files directly into numpy.

import numpy as np
import open3d as o3d

# Read .ply file
input_file = "input.ply"
pcd = o3d.io.read_point_cloud(input_file) # Read the point cloud

# Visualize the point cloud within open3d
o3d.visualization.draw_geometries([pcd]) 

# Convert open3d format to numpy array
# Here, you have the point cloud in numpy format. 
point_cloud_in_numpy = np.asarray(pcd.points) 

References:

legel
  • 2,507
  • 3
  • 23
  • 22
Chee Loong Soon
  • 3,601
  • 3
  • 17
  • 21
  • I've now used both `plyfile` and Open3D. The nice thing about `plyfile` is that it's extremely lightweight. I don't think Open3D is suitable as and answer to what I've asked, because it's very heavy-weight and does much more than just reading and writing PLY files. I've also used Open3D for a bunch of other things, and I would thoroughly recommend anyone *against* it. Its documentation isn't very good and it's just generally awkward to use. – Ray Jan 29 '20 at 16:30
  • 1
    Update lines 5 and 7 as: `o3d.io.read_point_cloud(input_file)` and `o3d.visualization.draw_geometries([pcd])` – Nirmal Feb 24 '21 at 11:31
  • This should be the correct the answer. The reason is because plyfile is... extremely slow when it comes to very large PLY files. I had a file with 24 million 3D points, and plyfile was taking minutes, while it took Open3D just a few seconds. – legel Jul 29 '21 at 04:06
  • Open3D does not have the version for Python3.10 yet. – Wisarut Bholsithi Sep 16 '22 at 09:17
10

I have succesfully used plyfile while working with pointclouds.

It's true that the poject had not presented any activity from a long time, but It meets its purpose.

And is not like the fact of parsing a ply file were something that allows you to recreate yourself by adding new features.

On the other hand PyMesh offers you many other features besides parsing ply files.

So maybe the question is:

Do you want to just 'read, manipulate and write PLY files' or are you looking for a library that provides more extra features?

What made me choose plyfile was that I'm able to incorporate it to my project by just copying 1 source file. Also I wasn't interested in any of the other features that PyMesh offers.


Update

I ended writing my own functions to read/write ply files (supporting ascii and binary) because I found the plyfile source code a little messy.

If anyone is interested, here is a link to the file: ply reader/writer

Community
  • 1
  • 1
David de la Iglesia
  • 2,436
  • 14
  • 29
  • 1
    Yours is 3 times faster in reading (let alone that you're putting the data straight into a pandas' DataFrame, which is so convenient) – Alaa M. Aug 10 '19 at 08:06
  • Thanks for sharing! Glanced at your code; it's worth noting you don't support writing color. – Andrew Wagner Oct 25 '19 at 14:48
  • @AndrewWagner it actually support writing color, normals and other scalar fields. There is even a test for that: https://github.com/daavoo/pyntcloud/blob/master/tests/integration/io/test_to_file.py#L15 – David de la Iglesia Oct 27 '19 at 16:19
  • @DaviddelaIglesia your code is great, but one small documentation hickup; in the docstring of your write_ply function you mention points & mesh should be ndarray objects while you actually expect dataframes – ThaNoob Apr 01 '21 at 09:04
5

I've just updated meshio to support PLY as well, next to about 20 other formats. Install with

pip install meshio

and use either on the command line

meshio convert in.ply out.vtk

or from within Python like

import meshio

mesh = meshio.read("in.ply")
# mesh.points, mesh.cells, ...
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
0

I rolled my own ascii ply writer (because it's so simple, I didn't want to take a dependency). Later, I was lazy and took a dependency on plyfile for loading binary .ply files coming from other places. Nothing has caught on fire yet.

A thing to mention, for better or worse, the .ply format is extensible. We shoehorned custom data into it, and that was easy since we also wrote our own writer.

Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100