Skip to main content

Rapidly read in PLY files using a wrapper over miniply

Project description

pypi MIT

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

Optionally with PyVista:

pip install pyminipl[pyvista]

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()
https://github.com/pyvista/pyminiply/raw/main/demo.png

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 on an Intel i9-14900KF:

Library

Time (seconds)

pyminiply

0.027

open3d

0.102

PyVista (VTK)

0.214

meshio

0.249

plyfile

4.039

Benchmark source:

import time
from timeit import timeit

import numpy as np
import pyvista as pv
import pyminiply
import plyfile
import meshio
import open3d

number = 10

filename = "tmp.ply"
mesh = pv.Plane(i_resolution=999, j_resolution=999).triangulate()
mesh.clear_data()
mesh.save(filename)

telap = timeit(lambda: pyminiply.read(filename), number=number)
print(f"pyminiply:   {telap/number:.3f}")

telap = timeit(lambda: open3d.io.read_point_cloud(filename), number=number)
print(f"open3d:      {telap/number:.3f}")

telap = timeit(lambda: pv.read(filename), number=number)
print(f"VTK/PyVista: {telap/number:.3f}")

telap = timeit(lambda: meshio.read(filename), number=number)
print(f"meshio:      {telap/number:.3f}")

# plyfile
number = 3  # less because it takes a while
telap = timeit(lambda: plyfile.PlyData.read(filename), number=number)
print(f"plyfile:     {telap/number:.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()
https://github.com/pyvista/pyminiply/raw/main/bench0.png https://github.com/pyvista/pyminiply/raw/main/bench1.png

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyminiply-0.2.0.tar.gz (26.1 kB view details)

Uploaded Source

Built Distributions

pyminiply-0.2.0-cp312-cp312-win_amd64.whl (57.3 kB view details)

Uploaded CPython 3.12 Windows x86-64

pyminiply-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (79.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pyminiply-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (52.4 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pyminiply-0.2.0-cp312-cp312-macosx_10_14_x86_64.whl (58.2 kB view details)

Uploaded CPython 3.12 macOS 10.14+ x86-64

pyminiply-0.2.0-cp311-cp311-win_amd64.whl (59.2 kB view details)

Uploaded CPython 3.11 Windows x86-64

pyminiply-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyminiply-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (54.6 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pyminiply-0.2.0-cp311-cp311-macosx_10_14_x86_64.whl (60.6 kB view details)

Uploaded CPython 3.11 macOS 10.14+ x86-64

pyminiply-0.2.0-cp310-cp310-win_amd64.whl (59.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

pyminiply-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyminiply-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (54.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pyminiply-0.2.0-cp310-cp310-macosx_10_14_x86_64.whl (60.7 kB view details)

Uploaded CPython 3.10 macOS 10.14+ x86-64

pyminiply-0.2.0-cp39-cp39-win_amd64.whl (59.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

pyminiply-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyminiply-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (54.8 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pyminiply-0.2.0-cp39-cp39-macosx_10_14_x86_64.whl (60.8 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

pyminiply-0.2.0-cp38-cp38-win_amd64.whl (59.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyminiply-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyminiply-0.2.0-cp38-cp38-macosx_11_0_arm64.whl (54.8 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pyminiply-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl (60.8 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

File details

Details for the file pyminiply-0.2.0.tar.gz.

File metadata

  • Download URL: pyminiply-0.2.0.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pyminiply-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7ca7970cc3065031126c604b44a7beb997f4c9a4912f502ffd09df2709edb8d4
MD5 e6a3259d8b2f2dcf204b8f665593717f
BLAKE2b-256 ffa9e56d7bb796e91322ceca7e7802cb33c6189cd39f6c55e2d4d98a285475b9

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fea963bd163ab8a3f6034fde6028ece1d22b0a3877e11402e47336cc66ee676d
MD5 6c3993d5b029424df3eb8c95f333e014
BLAKE2b-256 6f44af04888a6ad79fcfbda8ce8aa711d3532d99a7b0a53e6665ba9c3b2df502

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d38d55577e7d54fcd0163d8d427f7c91190b2c3207b69f876e4e57d02800966
MD5 62da2ba2ae2ae9fd4ed77f253d7d2318
BLAKE2b-256 63065b0cfff0f7a62aa2f7beadce21702264d3bd88f901d86a7de5d020b960bc

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f12abe6e0780f34b0c42cf1bd2c63965d57d2cb2658ea0a8668909e7fa2e540
MD5 f38fd098603615379811d5327f46416f
BLAKE2b-256 3013d90c8730694983d80b6b075363655e6722d6fb263f110f70439e7f420d43

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp312-cp312-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp312-cp312-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 499e22a70beee34056ac79556b736e176c20235ede8115f3f3b95d0f71c83589
MD5 9c743639c528a636f2229441161da876
BLAKE2b-256 9b7efbc285e1096d2c39b1eb87eee8adbdec3cf1301c03d898cfbebb53577be7

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8735578671144f77a4c062bd1673e8bc45632ca8311f92bda3dbbe56b0f525e4
MD5 c565a19f6210110f83aa55ec93112728
BLAKE2b-256 32d8438bf0c19242d2ea932558dd96bfb74bc3c47e32e271e93a19f4a47ec192

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c299eecfdfe92cfce325388c39f3bec677a88787c848daafa9a934b1910e35cd
MD5 636c5f4b272140abfa501d083d915285
BLAKE2b-256 c48459ef92c071993d54e32ac53a1bc0ad21f42ca011e36f2fb85c6f3d710bf8

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 999be627874fe3227027cdc194f58fe3a7885c0c7beb4bb1931cdbd8978fac51
MD5 2e5e5e98346f8c3ee758cd323daacb86
BLAKE2b-256 00f1781e20a4175f228d73f5db2584954ae0aed4c6bbc81778ac6bac41568668

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 341c56b8da4b8d5d7221959fc84e58e8241638a2e06f68589d39dcb32b74aa1c
MD5 ba1ca1d704ef7967b73ac0dabb7d59e2
BLAKE2b-256 3db36e60ddbf418e9104715228a1ac0b3d65f0e03e1cbcae8fd63c70d65061e2

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1fb91bc362660919439c2dbae52b80b74273e2a8f1e10e84549ca9d1c2076b26
MD5 0caa93effc92df56938e941e5ded6aeb
BLAKE2b-256 87159b2639e0a508947f4e648428a77b57d830baee099fd1652644472c631d92

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30e66378239e1970762cd17dddf52b118b09c5c6d8106e580d0499a466648ed2
MD5 713aa9a9370496a5109f823f78848e99
BLAKE2b-256 26806c07c590fcf90cc1aec076bf6ec5e629d9dbc67bb25a92675d40f288c9d7

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be4eaf2aa15d13ea76877016362c17264ea21852d24398c88193ecf70452d470
MD5 3db1e27e341bccadf211d793cfe4e6fe
BLAKE2b-256 b9bef1f56b07f7bdfa8c686cd3db2cee27e3996aac511505dab2de9c9579a9ba

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0207bd10f895d4bf29f7aa64fe8868ad9af9dc23ab6484bda49612c30e2ba7e9
MD5 1d2749a45b90576ff503bf635cb8a6aa
BLAKE2b-256 32f76e9c3748b91ea3db3cbbe384d447c7c9ddb302c08ba037b41509d39e8a98

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pyminiply-0.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 59.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pyminiply-0.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f5571d15396a7e665ab69cd27877f6e0997d247f594228ebdce2c480738fba2a
MD5 dd65b890ea9f049e73bd7879dfd2d961
BLAKE2b-256 e054214cbe236a84ea11897cba8749b7a420fb1f7dfff223637e58f8ca9513a6

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b07c54f4887750ba14c042dc9b763f9150b46f4051a02626d5d6b97621d0b459
MD5 a10a2426e1e4b14612489c0cf3daffe0
BLAKE2b-256 21360d4c4dc1662b946716d693feb32c47eaa86403f0e7ebdef67db4080ba740

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b9deee78fc3ad11819994fdc085d8aa3ccaa2e13168d3d328a67c18f8849a90
MD5 1d6642559a89b3a8766960e383b30de6
BLAKE2b-256 15349e0596baf8c01104df72b2ef4e17c90dd5ab530da4ef77109b86fb2befd7

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 30be00263fa9eb1ee59ff909c1a5fc6a9a013203271a8afaec703ab13be74bb8
MD5 63919c96e9b8fe44749e58ff7e299766
BLAKE2b-256 555c8d39824cae462da93896172b70d41af8b579ee96302f57ecf139c110fdf9

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyminiply-0.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 59.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pyminiply-0.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 de4510ce0412db4b1e1f62657f6a62f5d5a9e7b07454cf0dc66e5b42faf6fec0
MD5 a46ed0fbe0fdc6bbfcaf322f47d4b246
BLAKE2b-256 43b4f5c2a1d17f58e5e75089c416f5205b70b6199c4c2e25390c3d48b4d2f2a1

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 39dc2c0c8ce5fb1a802db1850c6e0a555c7ad30bf3e5682df943b85e33e6879c
MD5 69274212a076f02b70f7825fda0c1049
BLAKE2b-256 25961a441d910fbfa41affcb15ea953a189ac19e4958bad33bb009b15a7cd8d1

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a9b361a8b0346b6f4b1330f80ab9adb8283a2b29f160543985a4e709bf3c99e7
MD5 87d82be7b9553341be551780958ea3e7
BLAKE2b-256 47813a300623d6b020fa8b58b5fe1c462550bb849c047748cb8f3b923ed77f6a

See more details on using hashes here.

File details

Details for the file pyminiply-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for pyminiply-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 731d0b9997bae7793b2d5a1a4494561cdd6aff7aa54e9878be2fe7a817496925
MD5 d8f735d007a5976e2f6fcd9d69453dd7
BLAKE2b-256 c8039a65e7bfa023d522a77a2153c1a8a028dc7cd69d3812ff64fef978d299cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page