Skip to content

Commit

Permalink
implement nanobind wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Jul 16, 2024
1 parent 594c970 commit 8b94594
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 225 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
compile_commands.json
compile_commands.json

# cache
.cache
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/miniply"]
path = src/miniply
url = https://github.com/vilya/miniply
47 changes: 22 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,30 @@ in comparison to competing C and C++ libraries at `ply_io_benchmark
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:
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.046 |
| pyminiply | 0.027 |
+-------------+-----------------+
| open3d | 0.149 |
| open3d | 0.102 |
+-------------+-----------------+
| PyVista | 0.409 |
| PyVista | 0.214 |
| (VTK) | |
+-------------+-----------------+
| meshio | 0.512 |
| meshio | 0.249 |
+-------------+-----------------+
| plyfile | 8.939 |
| plyfile | 4.039 |
+-------------+-----------------+

**Benchmark source:**

.. code:: python
import time
from timeit import timeit
import numpy as np
import pyvista as pv
Expand All @@ -158,34 +160,29 @@ Here are the timings from reading in a 1,000,000 point binary PLY file:
import meshio
import open3d
filename = 'tmp.ply'
number = 10
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}')
telap = timeit(lambda: pyminiply.read(filename), number=number)
print(f"pyminiply: {telap/number:.3f}")
# open3d
tstart = time.time()
open3d.io.read_point_cloud(filename)
tend = time.time() - tstart; print(f'open3d: {tend:.3f}')
telap = timeit(lambda: open3d.io.read_point_cloud(filename), number=number)
print(f"open3d: {telap/number:.3f}")
# VTK/PyVista
tstart = time.time()
pv.read(filename)
tend = time.time() - tstart; print(f'VTK/PyVista: {tend:.3f}')
telap = timeit(lambda: pv.read(filename), number=number)
print(f"VTK/PyVista: {telap/number:.3f}")
tstart = time.time()
meshio.read(filename)
tend = time.time() - tstart; print(f'meshio: {tend:.3f}')
telap = timeit(lambda: meshio.read(filename), number=number)
print(f"meshio: {telap/number:.3f}")
# plyfile
tstart = time.time()
plyfile.PlyData.read(filename)
tend = time.time() - tstart; print(f'plyfile: {tend:.3f}')
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
===============================
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ extend-select = ["I"]
# Setuptools-style build caching in a local directory
build-dir = "build/{wheel_tag}"
minimum-version = "0.4"
sdist.exclude = [".github", "*.png", "tests", ".mypy_cache", ".pre-commit-config.yaml", "*_cache", "CONTRIBUTING.md", ".gitignore"]
sdist.exclude = [".github", "*.png", "tests", ".mypy_cache", ".pre-commit-config.yaml", "*_cache", "CONTRIBUTING.md", ".gitignore", "src/miniply/extra/", "src/G*", "src/miniply/TODO.md", "src/miniply/NOTES.md", "src/miniply/README.md", "src/miniply/CMakeLists.txt", "src/miniply/.git", ".gitmodules"]
114 changes: 0 additions & 114 deletions src/_wrapper.pyx

This file was deleted.

1 change: 1 addition & 0 deletions src/miniply
Submodule miniply added at 1a235c
4 changes: 2 additions & 2 deletions src/pyminiply/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from pyminiply._wrapper import load_mesh_from_ply
from pyminiply._wrapper import load_ply


def _polydata_from_faces(points, faces):
Expand Down Expand Up @@ -144,7 +144,7 @@ def read(filename, read_normals=True, read_uv=True, read_color=True):
"""
if not os.path.isfile(filename):
raise FileNotFoundError(f'Invalid file or unable to locate "{filename}"')
return load_mesh_from_ply(filename, read_normals, read_uv, read_color)
return load_ply(filename, read_normals, read_uv, read_color)


def read_as_mesh(filename, read_normals=True, read_uv=True, read_color=True):
Expand Down
Loading

0 comments on commit 8b94594

Please sign in to comment.