Python plyfile vs pymesh
Asked Answered
A

4

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.

Akiko answered 28/4, 2016 at 16:35 Comment(0)
A
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

Arabist answered 28/4, 2016 at 18:34 Comment(4)
Yours is 3 times faster in reading (let alone that you're putting the data straight into a pandas' DataFrame, which is so convenient)Chantel
Thanks for sharing! Glanced at your code; it's worth noting you don't support writing color.Ribal
@AndrewWagner it actually support writing color, normals and other scalar fields. There is even a test for that: github.com/daavoo/pyntcloud/blob/master/tests/integration/io/…Arabist
@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 dataframesExcreta
C
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:

Calhoun answered 28/1, 2020 at 14:59 Comment(4)
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.Akiko
Update lines 5 and 7 as: o3d.io.read_point_cloud(input_file) and o3d.visualization.draw_geometries([pcd])Tallou
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.Szombathely
Open3D does not have the version for Python3.10 yet.Avidin
A
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

Arabist answered 28/4, 2016 at 18:34 Comment(4)
Yours is 3 times faster in reading (let alone that you're putting the data straight into a pandas' DataFrame, which is so convenient)Chantel
Thanks for sharing! Glanced at your code; it's worth noting you don't support writing color.Ribal
@AndrewWagner it actually support writing color, normals and other scalar fields. There is even a test for that: github.com/daavoo/pyntcloud/blob/master/tests/integration/io/…Arabist
@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 dataframesExcreta
G
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, ...
Goose answered 19/10, 2019 at 12:13 Comment(1)
There is no doc. It is really hard to use this package.Inexpensive
R
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.

Ribal answered 25/10, 2019 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.