quickpaver 0.7.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {quickpaver-0.7.0 → quickpaver-0.8.0}/CHANGELOG.rst +35 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/Cargo.lock +1 -1
- {quickpaver-0.7.0 → quickpaver-0.8.0}/Cargo.toml +1 -1
- {quickpaver-0.7.0 → quickpaver-0.8.0}/PKG-INFO +61 -1
- {quickpaver-0.7.0 → quickpaver-0.8.0}/README.rst +60 -0
- quickpaver-0.8.0/benchmarks/bench_quality_sampling.py +81 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/__init__.py +67 -1
- quickpaver-0.8.0/python/quickpaver/_mesh.py +297 -0
- quickpaver-0.8.0/python/quickpaver/_quality.py +269 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/_quickpaver.pyi +20 -0
- quickpaver-0.8.0/python/quickpaver/_sampling.py +104 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/src/lib.rs +147 -2
- quickpaver-0.8.0/src/mesh.rs +422 -0
- quickpaver-0.8.0/src/quality.rs +222 -0
- quickpaver-0.8.0/src/sampling.rs +634 -0
- quickpaver-0.8.0/tests/test_mesh.py +287 -0
- quickpaver-0.8.0/tests/test_quality.py +250 -0
- quickpaver-0.8.0/tests/test_sampling.py +164 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tox.ini +0 -1
- {quickpaver-0.7.0 → quickpaver-0.8.0}/uv.lock +13 -5
- {quickpaver-0.7.0 → quickpaver-0.8.0}/.codacy.yml +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/.codespellrc +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/.coveragerc +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/.gitignore +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/.readthedocs.yml +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/AUTHORS.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/CONTRIBUTING.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/LICENSE +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/MANIFEST.in +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/Makefile +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/benchmarks/cold.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/benchmarks/run_bench.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/benchmarks/scenarios.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/benchmarks/tilebench.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/bibliography.bib +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/Makefile +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/make.bat +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/_static/.gitkeep +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/_templates/autosummary/base.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/_templates/autosummary/class.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/_templates/autosummary/module.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/api_reference.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/authors.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/bibliography.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/changelog.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/conf.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/contributing.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/index.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/installation.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/notebooks/regular_paving_examples.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/notebooks/transfer_matrix_examples.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/readme.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/docs/sources/usage.rst +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/notebooks/regular_paving_examples.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/notebooks/transfer_matrix_examples.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/pyproject.toml +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/__about__.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/_grid.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/_plot.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/_tiling.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/_tm_test_utils.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/_transfer_matrix.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/_types.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/data/__init__.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/data/corsica.geojson +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/data/france.geojson +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/python/quickpaver/py.typed +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/src/clip.rs +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/src/geom.rs +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/src/surface.rs +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/src/transfer.rs +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/__init__.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/conftest.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_data.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_grid.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_plot.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_tiling.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_tiling_fast_paths.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_transfer_matrix.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_transfer_matrix_internals.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_transfer_matrix_mixed_polygon.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_transfer_matrix_rectilinear.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_transfer_matrix_rust.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_transfer_matrix_trimesh.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_trimesh_flat.py +0 -0
- {quickpaver-0.7.0 → quickpaver-0.8.0}/tests/test_types.py +0 -0
|
@@ -2,6 +2,41 @@
|
|
|
2
2
|
Changelog
|
|
3
3
|
==============
|
|
4
4
|
|
|
5
|
+
0.8.0 (2026-11-27)
|
|
6
|
+
------------------
|
|
7
|
+
|
|
8
|
+
New API (Rust kernels, GIL released, no JIT compilation):
|
|
9
|
+
|
|
10
|
+
* ENH: ``multipolygon_quality``: roundness quality of every cell of a tessellation
|
|
11
|
+
(``2r/R`` for triangles, ``(r_in / r_circ) / cos(pi / n)`` around the centroid or given
|
|
12
|
+
centres for other polygons), from Shapely polygons or ``(n, k, 2)`` vertex arrays such as
|
|
13
|
+
those of ``gen_polygonal_tiling_arrays`` (no GEOS at all on that path). Everything is
|
|
14
|
+
computed relative to the cell, so the scores keep full precision far from the origin
|
|
15
|
+
(e.g. projected coordinates).
|
|
16
|
+
* ENH: ``triangle_anisotropy_quality``, ``square_anisotropy_quality`` and
|
|
17
|
+
``hexagon_anisotropy_quality``: closed-form quality of stretched regular cells. Tilings
|
|
18
|
+
with ``anisotropy_ratio=a`` score exactly ``triangle(a)``, ``square(a)`` and
|
|
19
|
+
``hexagon(1/a)``.
|
|
20
|
+
* ENH: ``poisson_disk_sampling``: variable-radius Poisson disk sampling (Bridson) on a
|
|
21
|
+
pixel radius map. Every pair of points is at least ``r_i + r_j`` apart, and the set is
|
|
22
|
+
maximal (a fill pass seeds the regions that growth cannot reach, e.g. across sharp radius
|
|
23
|
+
jumps). Neighbour search uses one hash grid per radius octave and a min / max pyramid of
|
|
24
|
+
the radius map, so the cost per point stays flat whatever the radius contrast. Random
|
|
25
|
+
numbers come from xoshiro256++ and directions from a libm-free cosine / sine: a seed gives
|
|
26
|
+
bit-identical points on every platform.
|
|
27
|
+
* ENH: VTK meshes (optional PyVista dependency): ``shapely_polygons_to_vtu`` (polygon
|
|
28
|
+
mesh whose cells share their vertices, merged by single linkage within ``merge_tol``
|
|
29
|
+
with a linear-time grid hash, rings oriented counter-clockwise, float64 points),
|
|
30
|
+
``create_unstructured_mesh``, ``pv_extrude`` (layered, terrain-following extrusion to
|
|
31
|
+
wedges, hexahedra, pentagonal / hexagonal prisms and polyhedra, all oriented for positive
|
|
32
|
+
volumes and outward faces, upwards or downwards) and ``get_ncell4poly``. Meshes of
|
|
33
|
+
10^5 - 10^6 cells are built in about a second.
|
|
34
|
+
|
|
35
|
+
Packaging:
|
|
36
|
+
|
|
37
|
+
* BUILD: drop the stale ``NUMBA_DISABLE_JIT`` from ``tox.ini``.
|
|
38
|
+
* DOCS: README note on the Claude-assisted migration of the kernels to Rust.
|
|
39
|
+
|
|
5
40
|
0.7.0 (2026-11-26)
|
|
6
41
|
------------------
|
|
7
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quickpaver
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: Intended Audience :: Science/Research
|
|
@@ -76,6 +76,13 @@ needed to install the package. Functions such as
|
|
|
76
76
|
also return plain NumPy arrays for very large problems, where creating millions of Shapely
|
|
77
77
|
objects would dominate the run time.
|
|
78
78
|
|
|
79
|
+
The package also measures the **roundness quality** of the cells of any tessellation
|
|
80
|
+
(tilings, triangulations, Voronoi diagrams) with ``multipolygon_quality``, and generates
|
|
81
|
+
**variable-density blue-noise point sets** with ``poisson_disk_sampling`` (e.g. the seeds of
|
|
82
|
+
a graded Voronoi mesh), and turns polygons into **VTK meshes** with shared vertices,
|
|
83
|
+
extruded into layered 3D meshes (``shapely_polygons_to_vtu``, ``pv_extrude``; optional
|
|
84
|
+
PyVista dependency).
|
|
85
|
+
|
|
79
86
|
===============
|
|
80
87
|
🚀 Quick start
|
|
81
88
|
===============
|
|
@@ -443,6 +450,59 @@ Of course, it works with holes
|
|
|
443
450
|
:width: 60%
|
|
444
451
|
:align: center
|
|
445
452
|
|
|
453
|
+
Cell quality and point sampling
|
|
454
|
+
-------------------------------
|
|
455
|
+
|
|
456
|
+
``multipolygon_quality`` scores every cell from ``1`` (regular polygon) towards ``0``
|
|
457
|
+
(distorted): ``2r/R`` for triangles, ``(r_in / r_circ) / cos(pi / n)`` for other polygons.
|
|
458
|
+
It accepts Shapely polygons or, fastest, the vertex arrays of ``gen_polygonal_tiling_arrays``.
|
|
459
|
+
Closed forms give the expected score of a stretched regular cell.
|
|
460
|
+
|
|
461
|
+
.. code-block:: python
|
|
462
|
+
|
|
463
|
+
import numpy as np
|
|
464
|
+
import shapely
|
|
465
|
+
|
|
466
|
+
vertices, _, _ = quickpaver.gen_polygonal_tiling_arrays(
|
|
467
|
+
shapely.box(0, 0, 100, 100), quickpaver.PolygonType.TRIANGLE, 2.0, anisotropy_ratio=2.0
|
|
468
|
+
)
|
|
469
|
+
quality = quickpaver.multipolygon_quality(vertices) # all 0.8017...
|
|
470
|
+
quickpaver.triangle_anisotropy_quality(2.0) # 0.8017...
|
|
471
|
+
|
|
472
|
+
``poisson_disk_sampling`` draws points whose spacing follows a radius map (in pixels):
|
|
473
|
+
every pair of points is at least ``r_i + r_j`` apart, and no room is left for another point.
|
|
474
|
+
|
|
475
|
+
.. code-block:: python
|
|
476
|
+
|
|
477
|
+
yy, xx = np.mgrid[0:400, 0:600]
|
|
478
|
+
radius = 2.0 + 0.03 * np.hypot(xx - 300, yy - 200) # finer in the centre
|
|
479
|
+
n_points, xy = quickpaver.poisson_disk_sampling(radius, seed=0)
|
|
480
|
+
domain = shapely.box(0, 0, 600, 400)
|
|
481
|
+
cells = shapely.intersection(
|
|
482
|
+
shapely.get_parts(shapely.voronoi_polygons(shapely.MultiPoint(xy), extend_to=domain)),
|
|
483
|
+
domain,
|
|
484
|
+
) # graded Voronoi mesh
|
|
485
|
+
|
|
486
|
+
Polygons become a PyVista mesh with shared vertices, which can be extruded into a
|
|
487
|
+
layered 3D mesh (``pip install quickpaver[pyvista]``):
|
|
488
|
+
|
|
489
|
+
.. code-block:: python
|
|
490
|
+
|
|
491
|
+
surface = quickpaver.shapely_polygons_to_vtu(cells, z=0.0)
|
|
492
|
+
volume = quickpaver.pv_extrude(surface, thickness=[1.0, 2.0, 5.0]) # 3 layers
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
===================
|
|
496
|
+
🤖 Acknowledgements
|
|
497
|
+
===================
|
|
498
|
+
|
|
499
|
+
The code of ``quickpaver`` was improved with the help of
|
|
500
|
+
`Claude <https://www.anthropic.com/claude>`_ (Anthropic), especially for the migration
|
|
501
|
+
from a `numba <https://numba.pydata.org/>`_ code base to a Rust backend
|
|
502
|
+
(`PyO3 <https://pyo3.rs>`_ + `rayon <https://github.com/rayon-rs/rayon>`_). Compiled
|
|
503
|
+
ahead of time and shipped in the wheels, the Rust kernels remove the JIT compilation time
|
|
504
|
+
at the first call and run in parallel without holding the GIL, for much better
|
|
505
|
+
performance. Every change is covered by the test suite.
|
|
446
506
|
|
|
447
507
|
===========
|
|
448
508
|
🔑 License
|
|
@@ -26,6 +26,13 @@ needed to install the package. Functions such as
|
|
|
26
26
|
also return plain NumPy arrays for very large problems, where creating millions of Shapely
|
|
27
27
|
objects would dominate the run time.
|
|
28
28
|
|
|
29
|
+
The package also measures the **roundness quality** of the cells of any tessellation
|
|
30
|
+
(tilings, triangulations, Voronoi diagrams) with ``multipolygon_quality``, and generates
|
|
31
|
+
**variable-density blue-noise point sets** with ``poisson_disk_sampling`` (e.g. the seeds of
|
|
32
|
+
a graded Voronoi mesh), and turns polygons into **VTK meshes** with shared vertices,
|
|
33
|
+
extruded into layered 3D meshes (``shapely_polygons_to_vtu``, ``pv_extrude``; optional
|
|
34
|
+
PyVista dependency).
|
|
35
|
+
|
|
29
36
|
===============
|
|
30
37
|
🚀 Quick start
|
|
31
38
|
===============
|
|
@@ -393,6 +400,59 @@ Of course, it works with holes
|
|
|
393
400
|
:width: 60%
|
|
394
401
|
:align: center
|
|
395
402
|
|
|
403
|
+
Cell quality and point sampling
|
|
404
|
+
-------------------------------
|
|
405
|
+
|
|
406
|
+
``multipolygon_quality`` scores every cell from ``1`` (regular polygon) towards ``0``
|
|
407
|
+
(distorted): ``2r/R`` for triangles, ``(r_in / r_circ) / cos(pi / n)`` for other polygons.
|
|
408
|
+
It accepts Shapely polygons or, fastest, the vertex arrays of ``gen_polygonal_tiling_arrays``.
|
|
409
|
+
Closed forms give the expected score of a stretched regular cell.
|
|
410
|
+
|
|
411
|
+
.. code-block:: python
|
|
412
|
+
|
|
413
|
+
import numpy as np
|
|
414
|
+
import shapely
|
|
415
|
+
|
|
416
|
+
vertices, _, _ = quickpaver.gen_polygonal_tiling_arrays(
|
|
417
|
+
shapely.box(0, 0, 100, 100), quickpaver.PolygonType.TRIANGLE, 2.0, anisotropy_ratio=2.0
|
|
418
|
+
)
|
|
419
|
+
quality = quickpaver.multipolygon_quality(vertices) # all 0.8017...
|
|
420
|
+
quickpaver.triangle_anisotropy_quality(2.0) # 0.8017...
|
|
421
|
+
|
|
422
|
+
``poisson_disk_sampling`` draws points whose spacing follows a radius map (in pixels):
|
|
423
|
+
every pair of points is at least ``r_i + r_j`` apart, and no room is left for another point.
|
|
424
|
+
|
|
425
|
+
.. code-block:: python
|
|
426
|
+
|
|
427
|
+
yy, xx = np.mgrid[0:400, 0:600]
|
|
428
|
+
radius = 2.0 + 0.03 * np.hypot(xx - 300, yy - 200) # finer in the centre
|
|
429
|
+
n_points, xy = quickpaver.poisson_disk_sampling(radius, seed=0)
|
|
430
|
+
domain = shapely.box(0, 0, 600, 400)
|
|
431
|
+
cells = shapely.intersection(
|
|
432
|
+
shapely.get_parts(shapely.voronoi_polygons(shapely.MultiPoint(xy), extend_to=domain)),
|
|
433
|
+
domain,
|
|
434
|
+
) # graded Voronoi mesh
|
|
435
|
+
|
|
436
|
+
Polygons become a PyVista mesh with shared vertices, which can be extruded into a
|
|
437
|
+
layered 3D mesh (``pip install quickpaver[pyvista]``):
|
|
438
|
+
|
|
439
|
+
.. code-block:: python
|
|
440
|
+
|
|
441
|
+
surface = quickpaver.shapely_polygons_to_vtu(cells, z=0.0)
|
|
442
|
+
volume = quickpaver.pv_extrude(surface, thickness=[1.0, 2.0, 5.0]) # 3 layers
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
===================
|
|
446
|
+
🤖 Acknowledgements
|
|
447
|
+
===================
|
|
448
|
+
|
|
449
|
+
The code of ``quickpaver`` was improved with the help of
|
|
450
|
+
`Claude <https://www.anthropic.com/claude>`_ (Anthropic), especially for the migration
|
|
451
|
+
from a `numba <https://numba.pydata.org/>`_ code base to a Rust backend
|
|
452
|
+
(`PyO3 <https://pyo3.rs>`_ + `rayon <https://github.com/rayon-rs/rayon>`_). Compiled
|
|
453
|
+
ahead of time and shipped in the wheels, the Rust kernels remove the JIT compilation time
|
|
454
|
+
at the first call and run in parallel without holding the GIL, for much better
|
|
455
|
+
performance. Every change is covered by the test suite.
|
|
396
456
|
|
|
397
457
|
===========
|
|
398
458
|
🔑 License
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Time ``multipolygon_quality``, ``poisson_disk_sampling`` and the VTK mesh helpers
|
|
2
|
+
(best of 3 runs).
|
|
3
|
+
|
|
4
|
+
usage: python benchmarks/bench_quality_sampling.py [--scale S]
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import time
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
import shapely
|
|
12
|
+
|
|
13
|
+
import quickpaver as qp
|
|
14
|
+
|
|
15
|
+
p = argparse.ArgumentParser()
|
|
16
|
+
p.add_argument("--scale", type=float, default=1.0)
|
|
17
|
+
a = p.parse_args()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def best(fn, repeat=3):
|
|
21
|
+
fn()
|
|
22
|
+
t = float("inf")
|
|
23
|
+
for _ in range(repeat):
|
|
24
|
+
t0 = time.perf_counter()
|
|
25
|
+
fn()
|
|
26
|
+
t = min(t, time.perf_counter() - t0)
|
|
27
|
+
return t
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
print("quickpaver", qp.__version__)
|
|
31
|
+
|
|
32
|
+
# --- cell quality -----------------------------------------------------------
|
|
33
|
+
n = max(10, int(300_000 * a.scale))
|
|
34
|
+
ang = np.linspace(0, 2 * np.pi, 7)[:-1]
|
|
35
|
+
c = np.random.default_rng(0).uniform(0, 3000, (n, 2))
|
|
36
|
+
rings = np.stack([c[:, None, 0] + 1.1 * np.cos(ang), c[:, None, 1] + np.sin(ang)], -1)
|
|
37
|
+
polys = shapely.polygons(rings)
|
|
38
|
+
mp = shapely.MultiPolygon(list(polys))
|
|
39
|
+
for name, arg in [
|
|
40
|
+
("quality MultiPolygon", mp),
|
|
41
|
+
("quality Polygon array", polys),
|
|
42
|
+
("quality (n, 6, 2) array", rings),
|
|
43
|
+
]:
|
|
44
|
+
t = best(lambda: qp.multipolygon_quality(arg))
|
|
45
|
+
print(f"{name:28s} n={n:8d} {t * 1e3:8.1f} ms")
|
|
46
|
+
|
|
47
|
+
# --- Poisson disk sampling --------------------------------------------------
|
|
48
|
+
h, w = max(10, int(2000 * a.scale**0.5)), max(10, int(3000 * a.scale**0.5))
|
|
49
|
+
xx = np.arange(w)[None, :] * np.ones((h, 1))
|
|
50
|
+
fields = {
|
|
51
|
+
"uniform r=1": np.full((h, w), 1.0),
|
|
52
|
+
"uniform r=3": np.full((h, w), 3.0),
|
|
53
|
+
"gradient 2..20": 2.0 + 18.0 * xx / (w - 1),
|
|
54
|
+
"step 1.5 / 40": np.where(xx < w // 2, 1.5, 40.0),
|
|
55
|
+
}
|
|
56
|
+
for name, r in fields.items():
|
|
57
|
+
r = r.astype(np.float32)
|
|
58
|
+
t = best(lambda: qp.poisson_disk_sampling(r, seed=1))
|
|
59
|
+
npts = qp.poisson_disk_sampling(r, seed=1)[0]
|
|
60
|
+
print(
|
|
61
|
+
f"pds {name:24s} n={npts:8d} {t * 1e3:8.1f} ms {t / npts * 1e9:7.0f} ns/point"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# --- VTK meshes (needs pyvista) ---------------------------------------------
|
|
65
|
+
try:
|
|
66
|
+
import pyvista # noqa: F401
|
|
67
|
+
except ImportError:
|
|
68
|
+
print("pyvista not installed: mesh benchmarks skipped")
|
|
69
|
+
else:
|
|
70
|
+
n_seeds = max(10, int(100_000 * a.scale))
|
|
71
|
+
seeds = np.random.default_rng(0).uniform(0, 1e5, (n_seeds, 2))
|
|
72
|
+
box = shapely.box(0, 0, 1e5, 1e5)
|
|
73
|
+
diagram = shapely.voronoi_polygons(shapely.MultiPoint(seeds), extend_to=box)
|
|
74
|
+
cells = shapely.intersection(shapely.get_parts(diagram), box)
|
|
75
|
+
t = best(lambda: qp.shapely_polygons_to_vtu(cells))
|
|
76
|
+
print(f"{'mesh shapely_polygons_to_vtu':28s} n={len(cells):8d} {t * 1e3:8.1f} ms")
|
|
77
|
+
surf = qp.shapely_polygons_to_vtu(cells)
|
|
78
|
+
t = best(lambda: qp.pv_extrude(surf, [1.0] * 10))
|
|
79
|
+
print(
|
|
80
|
+
f"{'mesh pv_extrude (10 layers)':28s} n={10 * len(cells):8d} {t * 1e3:8.1f} ms"
|
|
81
|
+
)
|
|
@@ -9,9 +9,12 @@ geographical test contours. The package is designed around cell-based geometry:
|
|
|
9
9
|
tiles, polygons, and grid cells are represented explicitly and can be combined
|
|
10
10
|
with NumPy arrays, Shapely geometries, and sparse SciPy matrices.
|
|
11
11
|
|
|
12
|
-
The public API is grouped into
|
|
12
|
+
The public API is grouped into seven main areas:
|
|
13
13
|
|
|
14
14
|
- polygon and tiling generation;
|
|
15
|
+
- cell quality metrics;
|
|
16
|
+
- point sampling;
|
|
17
|
+
- VTK meshes (surface meshes and layered extrusion);
|
|
15
18
|
- transfer-matrix construction;
|
|
16
19
|
- geographical test contours;
|
|
17
20
|
- rectilinear-grid utilities.
|
|
@@ -50,6 +53,47 @@ both the generated polygons and adjacency information between kept tiles.
|
|
|
50
53
|
adjacency_to_edges
|
|
51
54
|
draw_adjacency
|
|
52
55
|
|
|
56
|
+
Cell quality
|
|
57
|
+
^^^^^^^^^^^^
|
|
58
|
+
|
|
59
|
+
Roundness quality of the cells of a tessellation (triangulations, tilings,
|
|
60
|
+
Voronoi diagrams): ``1`` for a regular polygon, decreasing towards ``0`` as the
|
|
61
|
+
cell is distorted, plus closed forms for stretched regular cells.
|
|
62
|
+
|
|
63
|
+
.. autosummary::
|
|
64
|
+
:toctree: _autosummary
|
|
65
|
+
|
|
66
|
+
multipolygon_quality
|
|
67
|
+
triangle_anisotropy_quality
|
|
68
|
+
square_anisotropy_quality
|
|
69
|
+
hexagon_anisotropy_quality
|
|
70
|
+
|
|
71
|
+
Point sampling
|
|
72
|
+
^^^^^^^^^^^^^^
|
|
73
|
+
|
|
74
|
+
Blue-noise point sets whose local density follows a radius map (e.g. seeds of
|
|
75
|
+
a graded Voronoi mesh).
|
|
76
|
+
|
|
77
|
+
.. autosummary::
|
|
78
|
+
:toctree: _autosummary
|
|
79
|
+
|
|
80
|
+
poisson_disk_sampling
|
|
81
|
+
|
|
82
|
+
VTK meshes
|
|
83
|
+
^^^^^^^^^^
|
|
84
|
+
|
|
85
|
+
PyVista / VTK meshes from polygons: surface meshes whose cells share their
|
|
86
|
+
vertices, and layered (terrain-following) extrusion to 3D cells. Requires
|
|
87
|
+
the optional PyVista dependency (``pip install quickpaver[pyvista]``).
|
|
88
|
+
|
|
89
|
+
.. autosummary::
|
|
90
|
+
:toctree: _autosummary
|
|
91
|
+
|
|
92
|
+
shapely_polygons_to_vtu
|
|
93
|
+
create_unstructured_mesh
|
|
94
|
+
pv_extrude
|
|
95
|
+
get_ncell4poly
|
|
96
|
+
|
|
53
97
|
Transfer matrices
|
|
54
98
|
^^^^^^^^^^^^^^^^^
|
|
55
99
|
|
|
@@ -134,7 +178,20 @@ from quickpaver._grid import (
|
|
|
134
178
|
span_to_node_numbers_2d,
|
|
135
179
|
span_to_node_numbers_3d,
|
|
136
180
|
)
|
|
181
|
+
from quickpaver._mesh import (
|
|
182
|
+
create_unstructured_mesh,
|
|
183
|
+
get_ncell4poly,
|
|
184
|
+
pv_extrude,
|
|
185
|
+
shapely_polygons_to_vtu,
|
|
186
|
+
)
|
|
137
187
|
from quickpaver._plot import adjacency_to_edges, draw_adjacency
|
|
188
|
+
from quickpaver._quality import (
|
|
189
|
+
hexagon_anisotropy_quality,
|
|
190
|
+
multipolygon_quality,
|
|
191
|
+
square_anisotropy_quality,
|
|
192
|
+
triangle_anisotropy_quality,
|
|
193
|
+
)
|
|
194
|
+
from quickpaver._sampling import poisson_disk_sampling
|
|
138
195
|
from quickpaver._tiling import (
|
|
139
196
|
Disk,
|
|
140
197
|
PolygonType,
|
|
@@ -208,4 +265,13 @@ __all__ = [
|
|
|
208
265
|
"adjacency_by_shared_vertices",
|
|
209
266
|
"adjacency_to_edges",
|
|
210
267
|
"draw_adjacency",
|
|
268
|
+
"multipolygon_quality",
|
|
269
|
+
"triangle_anisotropy_quality",
|
|
270
|
+
"square_anisotropy_quality",
|
|
271
|
+
"hexagon_anisotropy_quality",
|
|
272
|
+
"poisson_disk_sampling",
|
|
273
|
+
"shapely_polygons_to_vtu",
|
|
274
|
+
"create_unstructured_mesh",
|
|
275
|
+
"pv_extrude",
|
|
276
|
+
"get_ncell4poly",
|
|
211
277
|
]
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
# Copyright (c) 2026 Antoine COLLET
|
|
3
|
+
|
|
4
|
+
"""VTK / PyVista meshes from polygons: surface meshes with shared vertices and
|
|
5
|
+
layered extrusion to 3D (terrain-following) meshes.
|
|
6
|
+
|
|
7
|
+
The geometry (vertex merging, cell orientation, 3D cell definitions) runs in
|
|
8
|
+
Rust with the GIL released; PyVista is only used to wrap the resulting arrays
|
|
9
|
+
and is an optional dependency (``pip install quickpaver[pyvista]``).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from typing import TYPE_CHECKING, Any, Iterable, Optional, Sequence, Union
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
from quickpaver import _quickpaver as _rs
|
|
19
|
+
from quickpaver._quality import PolygonsLike, _vertex_buffer
|
|
20
|
+
from quickpaver._types import ArrayLike, NDArrayFloat
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
23
|
+
import pyvista as pv
|
|
24
|
+
|
|
25
|
+
#: VTK cell type of polygons.
|
|
26
|
+
_VTK_POLYGON = 7
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _pyvista() -> Any:
|
|
30
|
+
try:
|
|
31
|
+
import pyvista as pv
|
|
32
|
+
except ImportError as exc: # pragma: no cover - depends on the environment
|
|
33
|
+
raise ImportError(
|
|
34
|
+
"PyVista is required to build VTK meshes. "
|
|
35
|
+
"Install it with `pip install quickpaver[pyvista]`."
|
|
36
|
+
) from exc
|
|
37
|
+
return pv
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _points3d(vertices: ArrayLike, z: float = 0.0) -> NDArrayFloat:
|
|
41
|
+
v = np.asarray(vertices, dtype=np.float64)
|
|
42
|
+
if v.ndim != 2 or v.shape[1] not in (2, 3):
|
|
43
|
+
raise ValueError(f"vertices must have shape (n, 2) or (n, 3), got {v.shape}.")
|
|
44
|
+
if v.shape[1] == 2:
|
|
45
|
+
v = np.column_stack([v, np.full(len(v), float(z))])
|
|
46
|
+
return np.ascontiguousarray(v)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_ncell4poly(npoints: int) -> int:
|
|
50
|
+
"""Number of legacy VTK cell-array values of a 3D cell extruded from a polygon.
|
|
51
|
+
|
|
52
|
+
An ``n``-vertex polygon becomes a wedge (``n = 3``), hexahedron (4),
|
|
53
|
+
pentagonal prism (5) or hexagonal prism (6), each written as
|
|
54
|
+
``[2n, ids...]``, or a polyhedron (``n >= 7``) written as
|
|
55
|
+
``[n_items, n_faces, face_0..., face_1..., ...]``.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
npoints : int
|
|
60
|
+
Number of vertices of the polygon exterior (closing vertex excluded).
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
int
|
|
65
|
+
Number of values of the 3D cell in a legacy VTK cell array.
|
|
66
|
+
|
|
67
|
+
Raises
|
|
68
|
+
------
|
|
69
|
+
ValueError
|
|
70
|
+
If ``npoints < 3`` (not a polygon).
|
|
71
|
+
|
|
72
|
+
Examples
|
|
73
|
+
--------
|
|
74
|
+
>>> [get_ncell4poly(n) for n in (3, 4, 5, 6, 7)]
|
|
75
|
+
[7, 9, 11, 13, 53]
|
|
76
|
+
"""
|
|
77
|
+
if npoints < 3:
|
|
78
|
+
raise ValueError(
|
|
79
|
+
"The number of exterior points for the polygon should be at least 3."
|
|
80
|
+
)
|
|
81
|
+
if npoints <= 6:
|
|
82
|
+
return 1 + 2 * npoints
|
|
83
|
+
return 2 + (npoints + 1) * 2 + npoints * 5
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def create_unstructured_mesh(
|
|
87
|
+
vertices: ArrayLike,
|
|
88
|
+
connectivities: Union[Sequence[Union[Sequence[int], np.ndarray]], np.ndarray],
|
|
89
|
+
) -> "pv.UnstructuredGrid":
|
|
90
|
+
"""Polygon mesh from vertices and cell connectivities.
|
|
91
|
+
|
|
92
|
+
Parameters
|
|
93
|
+
----------
|
|
94
|
+
vertices : ArrayLike
|
|
95
|
+
Vertex coordinates, shape ``(n_vertices, 2)`` (placed at ``z = 0``) or
|
|
96
|
+
``(n_vertices, 3)``.
|
|
97
|
+
connectivities : Sequence[Sequence[int]] or ArrayLike
|
|
98
|
+
Vertex ids of every cell, in ring order: a list of lists (any sizes)
|
|
99
|
+
or an ``(n_cells, k)`` integer array. Vertices can be shared by
|
|
100
|
+
several cells.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
pyvista.UnstructuredGrid
|
|
105
|
+
Mesh of ``VTK_POLYGON`` cells (a :class:`vtk.vtkUnstructuredGrid`
|
|
106
|
+
subclass).
|
|
107
|
+
|
|
108
|
+
Raises
|
|
109
|
+
------
|
|
110
|
+
ValueError
|
|
111
|
+
If a cell has fewer than 3 vertices or references a missing vertex.
|
|
112
|
+
|
|
113
|
+
Examples
|
|
114
|
+
--------
|
|
115
|
+
>>> mesh = create_unstructured_mesh(
|
|
116
|
+
... [[0, 0], [1, 0], [1, 1], [0, 1], [2, 0]], [[0, 1, 2, 3], [1, 4, 2]]
|
|
117
|
+
... )
|
|
118
|
+
>>> mesh.n_points, mesh.n_cells
|
|
119
|
+
(5, 2)
|
|
120
|
+
"""
|
|
121
|
+
pv = _pyvista()
|
|
122
|
+
pts = _points3d(vertices)
|
|
123
|
+
flat: np.ndarray
|
|
124
|
+
if isinstance(connectivities, np.ndarray) and connectivities.ndim == 2:
|
|
125
|
+
conn = connectivities.astype(np.int64, copy=False)
|
|
126
|
+
counts = np.full(len(conn), conn.shape[1], dtype=np.int64)
|
|
127
|
+
flat = conn.ravel()
|
|
128
|
+
else:
|
|
129
|
+
rows: Iterable[Union[Sequence[int], np.ndarray]] = connectivities
|
|
130
|
+
cells_list = [np.asarray(c, dtype=np.int64).ravel() for c in rows]
|
|
131
|
+
counts = np.array([len(c) for c in cells_list], dtype=np.int64)
|
|
132
|
+
flat = np.concatenate(cells_list) if cells_list else np.empty(0, dtype=np.int64)
|
|
133
|
+
if np.any(counts < 3):
|
|
134
|
+
raise ValueError("Every cell needs at least 3 vertices.")
|
|
135
|
+
if len(flat) and (int(np.min(flat)) < 0 or int(np.max(flat)) >= len(pts)):
|
|
136
|
+
raise ValueError("A cell references a vertex that does not exist.")
|
|
137
|
+
cells = np.empty(len(flat) + len(counts), dtype=np.int64)
|
|
138
|
+
head = np.cumsum(counts + 1) - (counts + 1)
|
|
139
|
+
is_head = np.zeros(len(cells), dtype=bool)
|
|
140
|
+
is_head[head] = True
|
|
141
|
+
cells[head] = counts
|
|
142
|
+
cells[~is_head] = flat
|
|
143
|
+
types = np.full(len(counts), _VTK_POLYGON, dtype=np.uint8)
|
|
144
|
+
return pv.UnstructuredGrid(cells, types, pts)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def shapely_polygons_to_vtu(
|
|
148
|
+
geoms: PolygonsLike, z: float = 0.0, merge_tol: Optional[float] = None
|
|
149
|
+
) -> "pv.UnstructuredGrid":
|
|
150
|
+
"""Polygon mesh with shared vertices from a set of polygons.
|
|
151
|
+
|
|
152
|
+
Vertices closer than ``merge_tol`` are merged (single-linkage clustering:
|
|
153
|
+
two vertices are merged when a chain of vertices at most ``merge_tol``
|
|
154
|
+
apart joins them) into their mean position, so adjacent cells share their
|
|
155
|
+
points. Every ring is oriented counter-clockwise (cell normals towards
|
|
156
|
+
``+z``) and vertices collapsed by the merge are removed from the ring.
|
|
157
|
+
Holes are ignored.
|
|
158
|
+
|
|
159
|
+
Parameters
|
|
160
|
+
----------
|
|
161
|
+
geoms : shapely.MultiPolygon, Sequence[shapely.Polygon] or NDArrayFloat
|
|
162
|
+
The cells: any input of :func:`~quickpaver.multipolygon_quality`, e.g.
|
|
163
|
+
Voronoi cells, a MultiPolygon, or the ``(n, k, 2)`` vertex array of
|
|
164
|
+
:func:`~quickpaver.gen_polygonal_tiling_arrays`.
|
|
165
|
+
z : float, default 0.0
|
|
166
|
+
Altitude of every point.
|
|
167
|
+
merge_tol : float, optional
|
|
168
|
+
Merge distance, in the units of the coordinates. By default
|
|
169
|
+
``1e-9`` times the largest extent of the polygons, which merges the
|
|
170
|
+
copies of a shared vertex (identical up to rounding) and nothing
|
|
171
|
+
else. Use a larger value for polygons whose shared vertices only
|
|
172
|
+
nearly coincide.
|
|
173
|
+
|
|
174
|
+
Returns
|
|
175
|
+
-------
|
|
176
|
+
pyvista.UnstructuredGrid
|
|
177
|
+
Mesh of ``VTK_POLYGON`` cells, in the order of the polygons.
|
|
178
|
+
|
|
179
|
+
Raises
|
|
180
|
+
------
|
|
181
|
+
ValueError
|
|
182
|
+
If a polygon is empty or keeps fewer than 3 distinct vertices after
|
|
183
|
+
merging, or if ``merge_tol`` is negative.
|
|
184
|
+
|
|
185
|
+
Examples
|
|
186
|
+
--------
|
|
187
|
+
>>> import shapely
|
|
188
|
+
>>> a, b = shapely.box(0, 0, 1, 1), shapely.box(1, 0, 2, 1)
|
|
189
|
+
>>> mesh = shapely_polygons_to_vtu([a, b], z=5.0)
|
|
190
|
+
>>> mesh.n_points, mesh.n_cells
|
|
191
|
+
(6, 2)
|
|
192
|
+
"""
|
|
193
|
+
pv = _pyvista()
|
|
194
|
+
xy, offsets, closed = _vertex_buffer(geoms)
|
|
195
|
+
if merge_tol is None:
|
|
196
|
+
v = xy.reshape(-1, 2)
|
|
197
|
+
extent = float(np.max(np.ptp(v, axis=0))) if len(v) else 0.0
|
|
198
|
+
merge_tol = 1e-9 * extent
|
|
199
|
+
merge_tol = float(merge_tol)
|
|
200
|
+
if not merge_tol >= 0:
|
|
201
|
+
raise ValueError(f"merge_tol must be >= 0, got {merge_tol}.")
|
|
202
|
+
points, cells = _rs.polygon_mesh(xy, offsets, closed, merge_tol)
|
|
203
|
+
n_cells = len(offsets) - 1
|
|
204
|
+
types = np.full(n_cells, _VTK_POLYGON, dtype=np.uint8)
|
|
205
|
+
return pv.UnstructuredGrid(cells, types, _points3d(points, z))
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def pv_extrude(surfmesh: Any, thickness: ArrayLike) -> "pv.UnstructuredGrid":
|
|
209
|
+
"""Extrude a surface mesh into layers of 3D cells (terrain-following mesh).
|
|
210
|
+
|
|
211
|
+
Every point of the surface is repeated on ``len(thickness) + 1`` levels,
|
|
212
|
+
level ``k + 1`` being level ``k`` shifted vertically by ``thickness[k]``,
|
|
213
|
+
so the layers follow the surface topography. Every 2D cell gives one 3D
|
|
214
|
+
cell per layer: a wedge (triangle), hexahedron (quadrilateral), pentagonal
|
|
215
|
+
or hexagonal prism, or a polyhedron for 7 or more vertices. Cells are
|
|
216
|
+
oriented so that VTK sees positive volumes and outward polyhedron faces,
|
|
217
|
+
whatever the orientation of the 2D cells.
|
|
218
|
+
|
|
219
|
+
Parameters
|
|
220
|
+
----------
|
|
221
|
+
surfmesh : pyvista.DataSet
|
|
222
|
+
Surface mesh of 2D cells (triangles, quads, pixels or polygons), e.g.
|
|
223
|
+
from :func:`shapely_polygons_to_vtu`. Other datasets (e.g. a
|
|
224
|
+
``PolyData``) are cast to an unstructured grid.
|
|
225
|
+
thickness : ArrayLike
|
|
226
|
+
Thickness of every layer (non-zero, finite, all of the same sign:
|
|
227
|
+
positive to stack the layers upwards, negative downwards).
|
|
228
|
+
|
|
229
|
+
Returns
|
|
230
|
+
-------
|
|
231
|
+
pyvista.UnstructuredGrid
|
|
232
|
+
The 3D mesh; cell ``i * n_layers + j`` is surface cell ``i`` in layer
|
|
233
|
+
``j``. Cell data:
|
|
234
|
+
|
|
235
|
+
- ``"Volume"``: horizontal area of the surface cell times the layer
|
|
236
|
+
thickness (its exact volume);
|
|
237
|
+
- ``"Layer"``: layer index (uint16);
|
|
238
|
+
- ``"Cell centers"``: if the surface has a ``"Cell centers"`` cell
|
|
239
|
+
array ``(n, 3)``, its points moved to the middle of every layer
|
|
240
|
+
(``z + sum(thickness[:j]) + thickness[j] / 2``).
|
|
241
|
+
|
|
242
|
+
Raises
|
|
243
|
+
------
|
|
244
|
+
ValueError
|
|
245
|
+
If the thicknesses are invalid, or a cell is not a 2D cell with at
|
|
246
|
+
least 3 points.
|
|
247
|
+
|
|
248
|
+
Examples
|
|
249
|
+
--------
|
|
250
|
+
>>> import shapely
|
|
251
|
+
>>> surf = shapely_polygons_to_vtu([shapely.box(0, 0, 2, 1)])
|
|
252
|
+
>>> vol = pv_extrude(surf, [1.0, 0.5])
|
|
253
|
+
>>> vol.n_cells, [float(v) for v in vol["Volume"]]
|
|
254
|
+
(2, [2.0, 1.0])
|
|
255
|
+
"""
|
|
256
|
+
pv = _pyvista()
|
|
257
|
+
th = np.atleast_1d(np.asarray(thickness, dtype=np.float64))
|
|
258
|
+
if th.ndim != 1 or len(th) == 0:
|
|
259
|
+
raise ValueError("thickness must be a non-empty 1D sequence.")
|
|
260
|
+
if not np.all(np.isfinite(th)) or np.any(th == 0):
|
|
261
|
+
raise ValueError("Every thickness must be finite and non-zero.")
|
|
262
|
+
if np.any(th > 0) and np.any(th < 0):
|
|
263
|
+
raise ValueError("Every thickness must have the same sign.")
|
|
264
|
+
nl = len(th)
|
|
265
|
+
if nl > np.iinfo(np.uint16).max + 1:
|
|
266
|
+
raise ValueError(f"At most {np.iinfo(np.uint16).max + 1} layers.")
|
|
267
|
+
if not isinstance(surfmesh, pv.UnstructuredGrid):
|
|
268
|
+
surfmesh = surfmesh.cast_to_unstructured_grid()
|
|
269
|
+
|
|
270
|
+
pts = np.ascontiguousarray(surfmesh.points, dtype=np.float64)
|
|
271
|
+
cells, types, area = _rs.extrude_cells(
|
|
272
|
+
np.ascontiguousarray(surfmesh.cells, dtype=np.int64),
|
|
273
|
+
np.ascontiguousarray(surfmesh.celltypes, dtype=np.uint8),
|
|
274
|
+
pts,
|
|
275
|
+
nl,
|
|
276
|
+
bool(th[0] < 0),
|
|
277
|
+
)
|
|
278
|
+
nc = len(pts)
|
|
279
|
+
points = np.tile(pts, (nl + 1, 1))
|
|
280
|
+
for i in range(nl):
|
|
281
|
+
points[(i + 1) * nc : (i + 2) * nc, 2] = (
|
|
282
|
+
points[i * nc : (i + 1) * nc, 2] + th[i]
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
mesh = pv.UnstructuredGrid(cells, types, points)
|
|
286
|
+
n2d = len(area)
|
|
287
|
+
mesh.cell_data["Volume"] = np.outer(area, np.abs(th)).ravel()
|
|
288
|
+
mesh.cell_data["Layer"] = np.tile(np.arange(nl, dtype=np.uint16), n2d)
|
|
289
|
+
|
|
290
|
+
if "Cell centers" in surfmesh.cell_data.keys():
|
|
291
|
+
cc = np.asarray(surfmesh.cell_data["Cell centers"], dtype=np.float64)
|
|
292
|
+
cc = cc.reshape(n2d, -1)
|
|
293
|
+
mid = np.concatenate([[0.0], np.cumsum(th)[:-1]]) + th / 2.0
|
|
294
|
+
out = np.repeat(cc[:, None, :], nl, axis=1)
|
|
295
|
+
out[:, :, 2] += mid[None, :]
|
|
296
|
+
mesh.cell_data["Cell centers"] = out.reshape(n2d * nl, -1)
|
|
297
|
+
return mesh
|