Skip to content

Commit

Permalink
merge with main; bump to v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Nov 26, 2024
2 parents d29aabf + 95cc552 commit af7203a
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 126 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.19.2
uses: pypa/cibuildwheel@v2.22.0

- uses: actions/upload-artifact@v4
with:
Expand All @@ -39,7 +39,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.13'

- name: Build sdist
run: pipx run build --sdist
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
- name: List artifacts
run: ls -R

- uses: pypa/gh-action-pypi-publish@v1.9.0
- uses: pypa/gh-action-pypi-publish@v1.12.2
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
compile_commands.json
compile_commands.json
.cache/
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
rev: v0.8.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -32,14 +32,14 @@ repos:
files: ^src/stl_reader/.*\.py

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies: [numpy>=2.0, npt-promote==0.1]
Expand All @@ -54,12 +54,12 @@ repos:
args: [--autofix, --indent, '2']

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
rev: v19.1.4
hooks:
- id: clang-format

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.0
rev: 0.29.4
hooks:
- id: check-github-workflows

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extensions.
If using emacs and helm, generate the project configuration files using `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`. Here's a sample configuration for C++11 on Linux:

```
pip install nanobind
pip install nanobind -U
export NANOBIND_INCLUDE=$(python -c "import nanobind, os; print(os.path.join(os.path.dirname(nanobind.__file__), 'cmake'))")
cmake -Dnanobind_DIR=$NANOBIND_INCLUDE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES="/usr/include/c++/11;/usr/include/x86_64-linux-gnu/c++/11/;/usr/lib/gcc/x86_64-linux-gnu/11/include/"
```
Expand Down
42 changes: 39 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
.. |MIT| image:: https://img.shields.io/badge/License-MIT-yellow.svg
:target: https://opensource.org/licenses/MIT

``stl-reader`` is a Python library for raipidly reading binary STL
files. It wraps a Cython interface to the fast STL library provided by
`libstl <https://github.com/aki5/libstl>`_. Thanks @aki5!
``stl-reader`` is a Python library for rapidly reading binary and ASCII
STL files. It wraps a `nanobind
<https://nanobind.readthedocs.io/en/latest/>`_ interface to the fast STL
library provided by `libstl <https://github.com/aki5/libstl>`_. Thanks
@aki5!

The main advantage of ``stl-reader`` over other STL reading libraries is
its performance. It is particularly well-suited for large files, mainly
Expand Down Expand Up @@ -167,6 +169,40 @@ Here's an additional benchmark comparing VTK with ``stl-reader``:

.. image:: https://github.com/pyvista/stl-reader/raw/main/bench1.png

Read in ASCII Meshes
====================

The `stl-reader` also supports ASCII files and is around 2.4 times
faster than VTK at reading ASCII files.

.. code:: python
import time
import stl_reader
import pyvista as pv
import numpy as np
# create and save a ASCII file
n = 1000
mesh = pv.Plane(i_resolution=n, j_resolution=n).triangulate()
mesh.save("/tmp/tmp-ascii.stl", binary=False)
# stl reader
tstart = time.time()
mesh = stl_reader.read_as_mesh("/tmp/tmp-ascii.stl")
print("stl-reader ", time.time() - tstart)
tstart = time.time()
pv_mesh = pv.read("/tmp/tmp-ascii.stl")
print("pyvista reader", time.time() - tstart)
# verify meshes are identical
assert np.allclose(mesh.points, pv_mesh.points)
# approximate time to read in the 1M point file:
# stl-reader 0.80303955078125
# pyvista reader 1.916085958480835
*****************************
License and Acknowledgments
*****************************
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ classifiers = [
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13"
]
dependencies = [
"numpy"
]
description = "Read in STL files"
name = "stl-reader"
readme = "README.rst"
requires-python = ">=3.8"
version = "0.2.1"
requires-python = ">=3.9"
version = "0.2.2"

[tool.cibuildwheel]
archs = ["auto64"] # 64-bit only
skip = "cp36-* cp37-* pp* *musllinux*" # disable PyPy and musl-based wheels
skip = "cp37-* pp* *musllinux*" # disable PyPy and musl-based wheels
test-command = "pytest {project}/tests"
test-requires = "pytest pyvista"

Expand Down
92 changes: 0 additions & 92 deletions src/stl_reader/_stlfile_wrapper.pyx

This file was deleted.

9 changes: 0 additions & 9 deletions src/stl_reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
from pyvista.core.pointset import PolyData


def _check_stl_ascii(filename: str) -> bool:
"""Check if a STL is ASCII."""
with open(filename, "rb") as fid:
return fid.read(5) == b"solid"


def _polydata_from_faces(points: npt.NDArray[float], faces: npt.NDArray[int]) -> "PolyData":
"""Generate a polydata from a faces array containing no padding and all triangles.
Expand Down Expand Up @@ -99,9 +93,6 @@ def read(filename: str) -> Tuple[npt.NDArray[np.float32], npt.NDArray[np.uint32]
[9005998, 9005999, 9005995]], dtype=uint32)
"""
if _check_stl_ascii(filename):
raise RuntimeError("stl-reader only supports binary STL files")

return _stlfile_wrapper.get_stl_data(filename)


Expand Down
Loading

0 comments on commit af7203a

Please sign in to comment.