Read in PLY files using a wrapper over miniply
Project description
pyminiply is a Python library for rapidly reading PLY files. It is a Python wrapper around the fast C++ PLY reading library provided by miniply. Thanks @vilya!
The main advantage of pyminiply over other PLY reading libraries is its performance. See the benchmarks below for more details.
Installation
The recommended way to install pyminiply is via PyPI:
pip install pyminiply
You can also clone the repository and install it from source:
git clone https://github.com/pyvista/pyminiply.git
cd pyminiply
git submodule update --init --recursive
pip install .
Usage
Load in the vertices, indices, normals, UV, and color information from a PLY file:
>>> import pyminiply
>>> vertices, indices, normals, uv, color = pyminiply.read("example.ply")
>>> vertices
array([[ 5.0000000e-01, -5.0000000e-01, -5.5511151e-17],
[ 4.0000001e-01, -5.0000000e-01, -4.4408922e-17],
[ 3.0000001e-01, -5.0000000e-01, -3.3306692e-17],
...,
[-4.2500001e-01, 5.0000000e-01, 4.7184480e-17],
[-4.7499999e-01, 4.4999999e-01, 5.2735593e-17],
[-5.0000000e-01, 4.2500001e-01, 5.5511151e-17]], dtype=float32)
>>> indices
array([[ 0, 442, 441],
[ 442, 122, 443],
[ 443, 121, 441],
...,
[1677, 438, 1679],
[1679, 439, 1676],
[1677, 1679, 1676]], dtype=int32)
>>> normals
array([[-1.110223e-16, 0.000000e+00, -1.000000e+00],
[-1.110223e-16, 0.000000e+00, -1.000000e+00],
[-1.110223e-16, 0.000000e+00, -1.000000e+00],
...,
[-1.110223e-16, 0.000000e+00, -1.000000e+00],
[-1.110223e-16, 0.000000e+00, -1.000000e+00],
[-1.110223e-16, 0.000000e+00, -1.000000e+00]], dtype=float32)
>>> uv
array([[0. , 0. ],
[0.1 , 0. ],
[0.2 , 0. ],
...,
[0.92499995, 1. ],
[0.975 , 0.95 ],
[1. , 0.92499995]], dtype=float32)
>>> color
array([[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[254, 254, 254],
[254, 254, 254],
[255, 255, 255]], dtype=uint8)
You can also read in the PLY file as a PyVista PolyData and immediately plot it.
>>> import pyminiply
>>> mesh = pyminiply.read_as_mesh("example.ply")
>>> mesh
PolyData (0x7f0653579c00)
N Cells: 200
N Points: 121
N Strips: 0
X Bounds: -5.000e-01, 5.000e-01
Y Bounds: -5.000e-01, 5.000e-01
Z Bounds: -5.551e-17, 5.551e-17
N Arrays: 2
>>> mesh.plot()
Benchmark
The main reason behind writing yet another PLY file reader for Python is to leverage the highly performant miniply library.
There is already an benchmark demonstrating how miniply outperforms in comparison to competing C and C++ libraries at ply_io_benchmark when reading PLY files. The benchmark here shows how pyminiply performs relative to other Python PLY file readers.
Here are the timings from reading in a 1,000,000 point binary PLY file:
Library |
Time (seconds) |
---|---|
pyminiply |
0.046 |
open3d |
0.149 |
PyVista (VTK) |
0.409 |
meshio |
0.512 |
plyfile |
8.939 |
Benchmark source:
import time
import numpy as np
import pyvista as pv
import pyminiply
import plyfile
import meshio
import open3d
filename = 'tmp.ply'
mesh = pv.Plane(i_resolution=999, j_resolution=999).triangulate()
mesh.clear_data()
mesh.save(filename)
# pyminiply
tstart = time.time()
pyminiply.read(filename)
tend = time.time() - tstart; print(f'pyminiply: {tend:.3f}')
# open3d
tstart = time.time()
open3d.io.read_point_cloud(filename)
tend = time.time() - tstart; print(f'open3d: {tend:.3f}')
# VTK/PyVista
tstart = time.time()
pv.read(filename)
tend = time.time() - tstart; print(f'VTK/PyVista: {tend:.3f}')
tstart = time.time()
meshio.read(filename)
tend = time.time() - tstart; print(f'meshio: {tend:.3f}')
# plyfile
tstart = time.time()
plyfile.PlyData.read(filename)
tend = time.time() - tstart; print(f'plyfile: {tend:.3f}')
Comparison with VTK and PyVista
Here’s an additional benchmark comparing VTK/PyVista with pyminiply:
import numpy as np
import time
import pyvista as pv
import matplotlib.pyplot as plt
import pyminiply
times = []
filename = 'tmp.ply'
for res in range(50, 800, 50):
mesh = pv.Plane(i_resolution=res, j_resolution=res).triangulate().subdivide(2)
mesh.clear_data()
mesh.save(filename)
tstart = time.time()
pv_mesh = pv.read(filename)
vtk_time = time.time() - tstart
tstart = time.time()
ply_mesh = pyminiply.read_as_mesh(filename)
ply_reader_time = time.time() - tstart
assert np.allclose(pv_mesh['Normals'], ply_mesh['Normals'])
assert np.allclose(pv_mesh.points, ply_mesh.points)
assert np.allclose(pv_mesh._connectivity_array, ply_mesh._connectivity_array)
times.append([mesh.n_points, vtk_time, ply_reader_time])
print(times[-1])
times = np.array(times)
plt.figure(1)
plt.title('PLY load time')
plt.plot(times[:, 0], times[:, 1], label='VTK')
plt.plot(times[:, 0], times[:, 2], label='pyminiply')
plt.xlabel('Number of Points')
plt.ylabel('Time to Load (seconds)')
plt.legend()
plt.figure(2)
plt.title('PLY load time (Log-Log)')
plt.loglog(times[:, 0], times[:, 1], label='VTK')
plt.loglog(times[:, 0], times[:, 2], label='pyminiply')
plt.xlabel('Number of Points')
plt.ylabel('Time to Load (seconds)')
plt.legend()
plt.show()
License and Acknowledgments
This project relies on miniply and credit goes to the original author for the excellent C++ library. That work is licensed under the MIT License.
The work in this repository is also licensed under the MIT License.
Support
If you are having issues, please feel free to raise an Issue.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pyminiply-0.1.0.tar.gz
.
File metadata
- Download URL: pyminiply-0.1.0.tar.gz
- Upload date:
- Size: 28.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 428772f74ef9953adf7be51ee10b6cc2c9f4ae69879c1cc18a412a2a353454d3 |
|
MD5 | f55d2d6cb291e07d34464bb1a7b302ac |
|
BLAKE2b-256 | bb44a6ac2137f6165aa2aa40e5baaf8b5c0dbb877d81c9319b5d5284607a1194 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 53.2 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06066a790693a587954d80f8c81da50361978eebfe6c34dc2f5c8fb48495a184 |
|
MD5 | 6d6eec55e47a64995c29ed56220b5c37 |
|
BLAKE2b-256 | 9efdae68a219b050ecb44277842f06d4efa2d4d09948bd837daf1d68b571842e |
Provenance
File details
Details for the file pyminiply-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 478.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 733d775456b59f9126c4ec2ddcc5c0dffce579b355b05abc09eff87f9b3c8c5d |
|
MD5 | d8db2c9eac75597be87219e8fe493610 |
|
BLAKE2b-256 | e70aeae646fd51a3255f3e7ef14bc30b6031b2d12862da354a72685661986717 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 67.9 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25702671aad2112b63ac2ef7177016a68baa91e3050cdc3b36a54c0498c776f0 |
|
MD5 | 86988769ba9455466729675e75cb85e4 |
|
BLAKE2b-256 | 7515d7e4c5915906b7b3807242679215d27c5540d151c52d57a4d68cc37fff18 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp311-cp311-macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 125.1 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f36576cbbc621c3d7a8114b61a2bae5bfef0c5ef73ef84c7e95106c30288230 |
|
MD5 | 384478873e0a188e57330ad513418cab |
|
BLAKE2b-256 | 7602206dc640a6360de7d1cb990d806b27cb37d167b6e8365d7c64859466a10a |
Provenance
File details
Details for the file pyminiply-0.1.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 52.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ebb77cb713e65246a41b43fa02b7edf4f54c5122a7bb716827643c0e3415926 |
|
MD5 | 5c795b0509042369da937d05ccf8b170 |
|
BLAKE2b-256 | d0e8bf177e69039607796ca2d6970a3641c532a98501db58e92f993c04885276 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 462.9 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1becd34a922ffde0ed590f61e4087f177fb46ba4206a8548e5718741befe62c8 |
|
MD5 | ac996c5cbe544db23cbb765677a85d48 |
|
BLAKE2b-256 | 87464381135a4b0ac972a972ff861c775c31553728402945cec8a6b092f9a2a0 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 67.2 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af29eb27aa20da6c74c0889754daf9a021cd102f8f009be373fa1a94fabc9bd5 |
|
MD5 | 626f375b303ba2fa985b8520a6419bfe |
|
BLAKE2b-256 | f37628048731bc3013fd111ff69209b37ed8ba62e64f56fb30af4d720fbed94e |
Provenance
File details
Details for the file pyminiply-0.1.0-cp310-cp310-macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 123.9 kB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f47024cc3b80b5b90e240407ffc137b03532d7167f7e895975a1084589255738 |
|
MD5 | 4516f9ee978e34762ebc62f00f2a65d4 |
|
BLAKE2b-256 | 7ef44b7a27094fb7ff6d279d65fa326bcb3a0e276914c660cc3aa41d667eb272 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 53.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f99c404c13f26e38edac57f6d61ca9a16c63ed3ae22d23b4d04a43048f6be76 |
|
MD5 | 430503a20b8b447abde362383d6dde21 |
|
BLAKE2b-256 | f4d2ef343c49edab89294ed212fbf6844c5f36c1cfa9dc83e7303ac06289df75 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 464.7 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de85a68e3526820c9e0dea7df2c6e976bf2e0c6c9ecf441eab7f4af054284b6a |
|
MD5 | 041396a0dbd8e2c67266459cf78bce3a |
|
BLAKE2b-256 | 2540bebe5799664220449be623eb34db1edac6302654582c84050a0324bbc9dc |
Provenance
File details
Details for the file pyminiply-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 67.7 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca053d4203bd703dcc10bcb5ababecead848bf7dbe6d3a9e097bd86b0e1189c |
|
MD5 | 148c4a5a2d35b5a08d29e76523cd7919 |
|
BLAKE2b-256 | 213f038a58918988784578a117e23103539a72c7181570eebb0f9d2bf85c4893 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp39-cp39-macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp39-cp39-macosx_10_9_universal2.whl
- Upload date:
- Size: 124.7 kB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 789739ac3f48e0453d8e7e3c4aaed455f2dd3145bd0ee964b09a5de42c7e634b |
|
MD5 | 30e7a58c9a7264c1215152b760a45258 |
|
BLAKE2b-256 | 15346c1cc95f4d58c093569879becdaadba3326528f38f2044f424358fb76e22 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 53.4 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4adf8ed0c579a08c94b7fcce0cb56e5723f9f52c3ae14a7d2fba99c2b8a0bccf |
|
MD5 | c344adde565594f76165d29122270363 |
|
BLAKE2b-256 | a36ee69cf6a325861cae8211809b98ac6c387ea63b140f1152e62604eaea5272 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 466.4 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a024fb197be2eed74d71d8dbb781ea7a641247330c4c4ecb51ea67646dba185 |
|
MD5 | c188a5e045a73b925138ae603881dc96 |
|
BLAKE2b-256 | 714543b6e82ad064bdc027bfe502b1e8ba24d2c4eadfced8d650bf29e9a98c5d |
Provenance
File details
Details for the file pyminiply-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 67.7 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff5b375b098cf11fa81546f2520a02694be13cc1e379258cdaa19fa1192f60c0 |
|
MD5 | 97265009693390bc45f25d022b364c00 |
|
BLAKE2b-256 | 3b33687632f1cf319d246c543e24028e7d00f2aab91618797646d097a4048df3 |
Provenance
File details
Details for the file pyminiply-0.1.0-cp38-cp38-macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyminiply-0.1.0-cp38-cp38-macosx_10_9_universal2.whl
- Upload date:
- Size: 124.9 kB
- Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec294cb0bd442ead3f547201f7debcadcccee082080339f413e47b3ace240061 |
|
MD5 | 05684008d0fafc030688a83d0ab9cb14 |
|
BLAKE2b-256 | b639e90294b7d9984513667f75c1d78f495dbac209ca62dfdbd42956da515556 |