picopie 0.2.1__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.
Files changed (54) hide show
  1. picopie-0.2.1/LICENSE +210 -0
  2. picopie-0.2.1/MANIFEST.in +5 -0
  3. picopie-0.2.1/NOTICE +10 -0
  4. picopie-0.2.1/PKG-INFO +156 -0
  5. picopie-0.2.1/PLAN.md +147 -0
  6. picopie-0.2.1/README.md +110 -0
  7. picopie-0.2.1/ROADMAP.md +106 -0
  8. picopie-0.2.1/pyproject.toml +134 -0
  9. picopie-0.2.1/setup.cfg +4 -0
  10. picopie-0.2.1/setup.py +37 -0
  11. picopie-0.2.1/src/picogk/__init__.py +81 -0
  12. picopie-0.2.1/src/picogk/_assets/viewer_environment.zip +0 -0
  13. picopie-0.2.1/src/picogk/_base.py +68 -0
  14. picopie-0.2.1/src/picogk/_errors.py +15 -0
  15. picopie-0.2.1/src/picogk/_fast.py +26 -0
  16. picopie-0.2.1/src/picogk/_fastloop.c +29234 -0
  17. picopie-0.2.1/src/picogk/_fastloop.pyx +128 -0
  18. picopie-0.2.1/src/picogk/_native/__init__.py +0 -0
  19. picopie-0.2.1/src/picogk/_native/_gen_prototypes.py +233 -0
  20. picopie-0.2.1/src/picogk/_native/ctypes_types.py +157 -0
  21. picopie-0.2.1/src/picogk/_native/headers/PicoGK.h +752 -0
  22. picopie-0.2.1/src/picogk/_native/headers/PicoGKApiTypes.h +174 -0
  23. picopie-0.2.1/src/picogk/_native/loader.py +101 -0
  24. picopie-0.2.1/src/picogk/_native/prototypes.py +212 -0
  25. picopie-0.2.1/src/picogk/_native/runtime.py +71 -0
  26. picopie-0.2.1/src/picogk/fields.py +266 -0
  27. picopie-0.2.1/src/picogk/lattice.py +45 -0
  28. picopie-0.2.1/src/picogk/library.py +184 -0
  29. picopie-0.2.1/src/picogk/mesh.py +226 -0
  30. picopie-0.2.1/src/picogk/metadata.py +178 -0
  31. picopie-0.2.1/src/picogk/polyline.py +67 -0
  32. picopie-0.2.1/src/picogk/py.typed +0 -0
  33. picopie-0.2.1/src/picogk/types.py +98 -0
  34. picopie-0.2.1/src/picogk/vdb.py +198 -0
  35. picopie-0.2.1/src/picogk/viewer.py +509 -0
  36. picopie-0.2.1/src/picogk/viz.py +149 -0
  37. picopie-0.2.1/src/picogk/voxels.py +431 -0
  38. picopie-0.2.1/src/picopie.egg-info/PKG-INFO +156 -0
  39. picopie-0.2.1/src/picopie.egg-info/SOURCES.txt +52 -0
  40. picopie-0.2.1/src/picopie.egg-info/dependency_links.txt +1 -0
  41. picopie-0.2.1/src/picopie.egg-info/requires.txt +18 -0
  42. picopie-0.2.1/src/picopie.egg-info/top_level.txt +1 -0
  43. picopie-0.2.1/tests/test_api_extras.py +103 -0
  44. picopie-0.2.1/tests/test_core.py +163 -0
  45. picopie-0.2.1/tests/test_coverage_gaps.py +127 -0
  46. picopie-0.2.1/tests/test_fastloop.py +156 -0
  47. picopie-0.2.1/tests/test_fuzz.py +182 -0
  48. picopie-0.2.1/tests/test_hardening.py +219 -0
  49. picopie-0.2.1/tests/test_parity_csharp.py +164 -0
  50. picopie-0.2.1/tests/test_perf.py +80 -0
  51. picopie-0.2.1/tests/test_phase1.py +164 -0
  52. picopie-0.2.1/tests/test_phase1_coverage.py +264 -0
  53. picopie-0.2.1/tests/test_viewer.py +211 -0
  54. picopie-0.2.1/tests/test_viz.py +214 -0
picopie-0.2.1/LICENSE ADDED
@@ -0,0 +1,210 @@
1
+ Copyright 2026 Mohammadreza Hajianpour <hajianpour.mr@gmail.com>
2
+ Copyright 2026 Vish Vadlamani <global.takeover7@gmail.com>
3
+
4
+ PicoPie is a Python port and binding of PicoGK (https://github.com/leap71/PicoGK),
5
+ which is Copyright (c) LEAP 71 and licensed under the Apache License, Version 2.0.
6
+ PicoPie is distributed under the same license (Apache-2.0), reproduced in full below.
7
+
8
+ -------------------------------------------------------------------------------
9
+
10
+ Apache License
11
+ Version 2.0, January 2004
12
+ http://www.apache.org/licenses/
13
+
14
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
15
+
16
+ 1. Definitions.
17
+
18
+ "License" shall mean the terms and conditions for use, reproduction,
19
+ and distribution as defined by Sections 1 through 9 of this document.
20
+
21
+ "Licensor" shall mean the copyright owner or entity authorized by
22
+ the copyright owner that is granting the License.
23
+
24
+ "Legal Entity" shall mean the union of the acting entity and all
25
+ other entities that control, are controlled by, or are under common
26
+ control with that entity. For the purposes of this definition,
27
+ "control" means (i) the power, direct or indirect, to cause the
28
+ direction or management of such entity, whether by contract or
29
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
30
+ outstanding shares, or (iii) beneficial ownership of such entity.
31
+
32
+ "You" (or "Your") shall mean an individual or Legal Entity
33
+ exercising permissions granted by this License.
34
+
35
+ "Source" form shall mean the preferred form for making modifications,
36
+ including but not limited to software source code, documentation
37
+ source, and configuration files.
38
+
39
+ "Object" form shall mean any form resulting from mechanical
40
+ transformation or translation of a Source form, including but
41
+ not limited to compiled object code, generated documentation,
42
+ and conversions to other media types.
43
+
44
+ "Work" shall mean the work of authorship, whether in Source or
45
+ Object form, made available under the License, as indicated by a
46
+ copyright notice that is included in or attached to the work
47
+ (an example is provided in the Appendix below).
48
+
49
+ "Derivative Works" shall mean any work, whether in Source or Object
50
+ form, that is based on (or derived from) the Work and for which the
51
+ editorial revisions, annotations, elaborations, or other modifications
52
+ represent, as a whole, an original work of authorship. For the purposes
53
+ of this License, Derivative Works shall not include works that remain
54
+ separable from, or merely link (or bind by name) to the interfaces of,
55
+ the Work and Derivative Works thereof.
56
+
57
+ "Contribution" shall mean any work of authorship, including
58
+ the original version of the Work and any modifications or additions
59
+ to that Work or Derivative Works thereof, that is intentionally
60
+ submitted to Licensor for inclusion in the Work by the copyright owner
61
+ or by an individual or Legal Entity authorized to submit on behalf of
62
+ the copyright owner. For the purposes of this definition, "submitted"
63
+ means any form of electronic, verbal, or written communication sent
64
+ to the Licensor or its representatives, including but not limited to
65
+ communication on electronic mailing lists, source code control systems,
66
+ and issue tracking systems that are managed by, or on behalf of, the
67
+ Licensor for the purpose of discussing and improving the Work, but
68
+ excluding communication that is conspicuously marked or otherwise
69
+ designated in writing by the copyright owner as "Not a Contribution."
70
+
71
+ "Contributor" shall mean Licensor and any individual or Legal Entity
72
+ on behalf of whom a Contribution has been received by Licensor and
73
+ subsequently incorporated within the Work.
74
+
75
+ 2. Grant of Copyright License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ copyright license to reproduce, prepare Derivative Works of,
79
+ publicly display, publicly perform, sublicense, and distribute the
80
+ Work and such Derivative Works in Source or Object form.
81
+
82
+ 3. Grant of Patent License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ (except as stated in this section) patent license to make, have made,
86
+ use, offer to sell, sell, import, and otherwise transfer the Work,
87
+ where such license applies only to those patent claims licensable
88
+ by such Contributor that are necessarily infringed by their
89
+ Contribution(s) alone or by combination of their Contribution(s)
90
+ with the Work to which such Contribution(s) was submitted. If You
91
+ institute patent litigation against any entity (including a
92
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
93
+ or a Contribution incorporated within the Work constitutes direct
94
+ or contributory patent infringement, then any patent licenses
95
+ granted to You under this License for that Work shall terminate
96
+ as of the date such litigation is filed.
97
+
98
+ 4. Redistribution. You may reproduce and distribute copies of the
99
+ Work or Derivative Works thereof in any medium, with or without
100
+ modifications, and in Source or Object form, provided that You
101
+ meet the following conditions:
102
+
103
+ (a) You must give any other recipients of the Work or
104
+ Derivative Works a copy of this License; and
105
+
106
+ (b) You must cause any modified files to carry prominent notices
107
+ stating that You changed the files; and
108
+
109
+ (c) You must retain, in the Source form of any Derivative Works
110
+ that You distribute, all copyright, patent, trademark, and
111
+ attribution notices from the Source form of the Work,
112
+ excluding those notices that do not pertain to any part of
113
+ the Derivative Works; and
114
+
115
+ (d) If the Work includes a "NOTICE" text file as part of its
116
+ distribution, then any Derivative Works that You distribute must
117
+ include a readable copy of the attribution notices contained
118
+ within such NOTICE file, excluding those notices that do not
119
+ pertain to any part of the Derivative Works, in at least one
120
+ of the following places: within a NOTICE text file distributed
121
+ as part of the Derivative Works; within the Source form or
122
+ documentation, if provided along with the Derivative Works; or,
123
+ within a display generated by the Derivative Works, if and
124
+ wherever such third-party notices normally appear. The contents
125
+ of the NOTICE file are for informational purposes only and
126
+ do not modify the License. You may add Your own attribution
127
+ notices within Derivative Works that You distribute, alongside
128
+ or as an addendum to the NOTICE text from the Work, provided
129
+ that such additional attribution notices cannot be construed
130
+ as modifying the License.
131
+
132
+ You may add Your own copyright statement to Your modifications and
133
+ may provide additional or different license terms and conditions
134
+ for use, reproduction, or distribution of Your modifications, or
135
+ for any such Derivative Works as a whole, provided Your use,
136
+ reproduction, and distribution of the Work otherwise complies with
137
+ the conditions stated in this License.
138
+
139
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
140
+ any Contribution intentionally submitted for inclusion in the Work
141
+ by You to the Licensor shall be under the terms and conditions of
142
+ this License, without any additional terms or conditions.
143
+ Notwithstanding the above, nothing herein shall supersede or modify
144
+ the terms of any separate license agreement you may have executed
145
+ with Licensor regarding such Contributions.
146
+
147
+ 6. Trademarks. This License does not grant permission to use the trade
148
+ names, trademarks, service marks, or product names of the Licensor,
149
+ except as required for reasonable and customary use in describing the
150
+ origin of the Work and reproducing the content of the NOTICE file.
151
+
152
+ 7. Disclaimer of Warranty. Unless required by applicable law or
153
+ agreed to in writing, Licensor provides the Work (and each
154
+ Contributor provides its Contributions) on an "AS IS" BASIS,
155
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156
+ implied, including, without limitation, any warranties or conditions
157
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
158
+ PARTICULAR PURPOSE. You are solely responsible for determining the
159
+ appropriateness of using or redistributing the Work and assume any
160
+ risks associated with Your exercise of permissions under this License.
161
+
162
+ 8. Limitation of Liability. In no event and under no legal theory,
163
+ whether in tort (including negligence), contract, or otherwise,
164
+ unless required by applicable law (such as deliberate and grossly
165
+ negligent acts) or agreed to in writing, shall any Contributor be
166
+ liable to You for damages, including any direct, indirect, special,
167
+ incidental, or consequential damages of any character arising as a
168
+ result of this License or out of the use or inability to use the
169
+ Work (including but not limited to damages for loss of goodwill,
170
+ work stoppage, computer failure or malfunction, or any and all
171
+ other commercial damages or losses), even if such Contributor
172
+ has been advised of the possibility of such damages.
173
+
174
+ 9. Accepting Warranty or Additional Liability. While redistributing
175
+ the Work or Derivative Works thereof, You may choose to offer,
176
+ and charge a fee for, acceptance of support, warranty, indemnity,
177
+ or other liability obligations and/or rights consistent with this
178
+ License. However, in accepting such obligations, You may act only
179
+ on Your own behalf and on Your sole responsibility, not on behalf
180
+ of any other Contributor, and only if You agree to indemnify,
181
+ defend, and hold each Contributor harmless for any liability
182
+ incurred by, or claims asserted against, such Contributor by reason
183
+ of your accepting any such warranty or additional liability.
184
+
185
+ END OF TERMS AND CONDITIONS
186
+
187
+ APPENDIX: How to apply the Apache License to your work.
188
+
189
+ To apply the Apache License to your work, attach the following
190
+ boilerplate notice, with the fields enclosed by brackets "[]"
191
+ replaced with your own identifying information. (Don't include
192
+ the brackets!) The text should be enclosed in the appropriate
193
+ comment syntax for the file format. We also recommend that a
194
+ file or class name and description of purpose be included on the
195
+ same "printed page" as the copyright notice for easier
196
+ identification within third-party archives.
197
+
198
+ Copyright 2026 Mohammadreza Hajianpour and Vish Vadlamani
199
+
200
+ Licensed under the Apache License, Version 2.0 (the "License");
201
+ you may not use this file except in compliance with the License.
202
+ You may obtain a copy of the License at
203
+
204
+ http://www.apache.org/licenses/LICENSE-2.0
205
+
206
+ Unless required by applicable law or agreed to in writing, software
207
+ distributed under the License is distributed on an "AS IS" BASIS,
208
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
209
+ See the License for the specific language governing permissions and
210
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ # Ship the Cython source so the fast extension can be (re)built from an sdist.
2
+ include src/picogk/_fastloop.pyx
3
+ include README.md PLAN.md ROADMAP.md
4
+ recursive-include src/picogk/_native/headers *.h
5
+ recursive-include src/picogk/_assets *.zip
picopie-0.2.1/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ PicoPie
2
+ Copyright 2026 Mohammadreza Hajianpour <hajianpour.mr@gmail.com>
3
+ Copyright 2026 Vish Vadlamani <global.takeover7@gmail.com>
4
+
5
+ This product is a Python port and binding of PicoGK
6
+ (https://github.com/leap71/PicoGK), Copyright (c) LEAP 71, licensed under the
7
+ Apache License, Version 2.0.
8
+
9
+ The native runtime it binds (PicoGKRuntime, https://github.com/leap71/PicoGKRuntime)
10
+ is likewise Apache-2.0 and builds upon the OpenVDB and GLFW open-source projects.
picopie-0.2.1/PKG-INFO ADDED
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: picopie
3
+ Version: 0.2.1
4
+ Summary: A Pythonic binding for the PicoGK computational-geometry kernel
5
+ Author-email: Mohammadreza Hajianpour <hajianpour.mr@gmail.com>, Vish Vadlamani <global.takeover7@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Borderliner/PicoPie
8
+ Project-URL: Repository, https://github.com/Borderliner/PicoPie
9
+ Project-URL: Issues, https://github.com/Borderliner/PicoPie/issues
10
+ Project-URL: PicoGK (upstream), https://github.com/leap71/PicoGK
11
+ Keywords: geometry,voxels,openvdb,implicit,cad,additive-manufacturing
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering
24
+ Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ License-File: NOTICE
30
+ Requires-Dist: numpy>=1.23
31
+ Provides-Extra: viz
32
+ Requires-Dist: pillow>=9; extra == "viz"
33
+ Requires-Dist: matplotlib>=3.5; extra == "viz"
34
+ Provides-Extra: docs
35
+ Requires-Dist: mkdocs-material>=9; extra == "docs"
36
+ Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
37
+ Provides-Extra: dev
38
+ Requires-Dist: picopie[viz]; extra == "dev"
39
+ Requires-Dist: pytest>=7; extra == "dev"
40
+ Requires-Dist: pytest-timeout; extra == "dev"
41
+ Requires-Dist: pytest-cov; extra == "dev"
42
+ Requires-Dist: ruff>=0.6; extra == "dev"
43
+ Requires-Dist: mypy>=1.8; extra == "dev"
44
+ Requires-Dist: hypothesis>=6; extra == "dev"
45
+ Dynamic: license-file
46
+
47
+ # PicoPie
48
+
49
+ A **Pythonic binding for [PicoGK](https://github.com/leap71/PicoGK)** — LEAP 71's
50
+ compact computational-geometry kernel for engineering (voxel / level-set modeling
51
+ on OpenVDB).
52
+
53
+ PicoPie binds the *same native runtime* the official C# library uses — so you get
54
+ identical geometry and performance — then wraps it in an idiomatic, NumPy-friendly
55
+ Python API. No .NET, no compiler, no system libraries: just `pip install picopie`.
56
+
57
+ ```python
58
+ import picogk
59
+ from picogk import Voxels
60
+
61
+ picogk.init(voxel_size_mm=0.2)
62
+
63
+ body = Voxels.sphere(radius=10)
64
+ hole = Voxels.sphere(center=(6, 0, 0), radius=6)
65
+ part = body - hole # boolean subtract → new Voxels
66
+ part.shell_(1.0) # hollow to a 1 mm wall (in place)
67
+
68
+ vol, bbox = part.calculate_properties()
69
+ print(f"{vol:.1f} mm³")
70
+ part.to_mesh().save_stl("part.stl")
71
+ ```
72
+
73
+ ## Install
74
+
75
+ ```bash
76
+ pip install picopie # core
77
+ pip install "picopie[viz]" # + headless slice/mesh PNG helpers (Pillow, matplotlib)
78
+ ```
79
+
80
+ or with [uv](https://docs.astral.sh/uv/):
81
+
82
+ ```bash
83
+ uv add picopie
84
+ ```
85
+
86
+ Wheels are self-contained — the native runtime (OpenVDB 13, PicoGK 26.2) and all
87
+ its C++ deps are bundled. Prebuilt for CPython 3.10–3.13 on **Linux (manylinux
88
+ x86-64), macOS (Apple Silicon), and Windows (x64)**.
89
+
90
+ ## Documentation
91
+
92
+ - **[Quickstart](docs/quickstart.md)** · **[Guide](docs/guide.md)** · **[API reference](docs/api.md)**
93
+ - **Tutorials** — [Novice](docs/tutorials/novice/), [Intermediate](docs/tutorials/intermediate/),
94
+ [Advanced](docs/tutorials/advanced/)
95
+ - **[QuickLearn](docs/tutorials/QuickLearn.md)** — the whole API in one annotated file
96
+ (learn-x-in-y-minutes style)
97
+
98
+ ## Features
99
+
100
+ - **`Voxels`** — primitives (`sphere`, `capsule`), booleans (`+ - &`), offsets,
101
+ `shell_` (hollow), implicit SDF modeling, and queries (`is_inside`,
102
+ `closest_point`, `surface_normal`, `ray_cast`, `calculate_properties`).
103
+ - **`Mesh`** — from voxels (marching cubes), NumPy `vertices`/`triangles`, STL/OBJ
104
+ import **and** export.
105
+ - **`Lattice`** (beams + spheres), **`ScalarField`** / **`VectorField`** (bulk
106
+ `set_many`/`get_many`), **`Metadata`**, **`PolyLine`**.
107
+ - **File I/O** — `save_vdb` / `load_vdb` round-trips voxels + fields (OpenVDB).
108
+ - **Headless viz** (`[viz]`) — `save_slice_png`, `save_slice_sheet`, `mesh_preview`.
109
+ - **Interactive viewer** — `picogk.show(part)` (GLFW/OpenGL, orbit camera) and
110
+ `render_png(part, "out.png")` for offscreen renders.
111
+ - **Fast path** — a compiled `_fastloop` extension (~13–28× faster bulk mesh/field
112
+ transfer) with automatic pure-Python fallback.
113
+
114
+ ## Reliability
115
+
116
+ PicoPie is validated against the reference and hardened well beyond a naive binding:
117
+
118
+ - **Parity-tested vs C# PicoGK** on the same runtime — volumes, dims, mesh
119
+ counts/bbox, and geometric queries match to float precision.
120
+ - **Never aborts** — the native runtime is patched so a C++/OpenVDB error surfaces
121
+ as a catchable `PicoGKError` instead of killing the process; non-finite inputs are
122
+ rejected up front. Verified against thousands of fuzzed inputs.
123
+ - **Reproducible & auditable** — every upstream dependency is version-pinned; builds
124
+ ship an SBOM (`sbom.cdx.json`) and hash-pinned build deps.
125
+ - Green CI across Linux/macOS/Windows; mypy + ruff clean; ~190 tests.
126
+
127
+ ## Development
128
+
129
+ ```bash
130
+ git clone https://github.com/Borderliner/PicoPie && cd PicoPie
131
+ python -m venv .venv && source .venv/bin/activate
132
+ scripts/build_runtime.sh # build + stage the native runtime (see below)
133
+ pip install -e ".[dev]"
134
+ pytest
135
+ ```
136
+
137
+ Building the native runtime (Linux) needs system deps:
138
+
139
+ ```bash
140
+ sudo apt-get install -y --no-install-recommends \
141
+ libboost-all-dev libblosc-dev libtbb-dev extra-cmake-modules \
142
+ xorg-dev mesa-common-dev libgl1-mesa-dev ninja-build cmake g++ git
143
+ scripts/build_runtime.sh
144
+ ```
145
+
146
+ PicoPie locates the runtime automatically: bundled in the wheel (`picogk/_lib/`),
147
+ else under `native/`, else via `$PICOGK_RUNTIME` (full path to the shared library).
148
+ Cross-platform wheels are built by `cibuildwheel` in `.github/workflows/wheels.yml`.
149
+
150
+ See [`ROADMAP.md`](ROADMAP.md) for the (now-complete) phase history and
151
+ [`PLAN.md`](PLAN.md) for the architecture rationale.
152
+
153
+ ## License
154
+
155
+ Apache-2.0, matching upstream PicoGK / PicoGKRuntime. Ported by
156
+ Mohammadreza Hajianpour and Vish Vadlamani.
picopie-0.2.1/PLAN.md ADDED
@@ -0,0 +1,147 @@
1
+ # PicoPie — A Python binding for PicoGK
2
+
3
+ > Goal: bring PicoGK's voxel/level-set geometry kernel to Python with an idiomatic,
4
+ > NumPy-friendly API — by binding the **same native runtime** the C# library uses,
5
+ > not by reimplementing the kernel.
6
+
7
+ **Status: shipped.** Released on PyPI as `picopie`; all phases in [`ROADMAP.md`](ROADMAP.md)
8
+ are complete (cross-platform wheels, parity-validated, hardened, interactive viewer).
9
+ This document records the architecture decisions that got us there.
10
+
11
+ ## 1. Strategy (decided)
12
+
13
+ | Decision | Choice | Consequence |
14
+ |---|---|---|
15
+ | Binding mechanism | **ctypes** over the native C ABI + a Pythonic layer on top | No compiler needed by end users; no .NET; full control; mirrors `Internals/Interop.cs` + `Base/*.cs` |
16
+ | Platforms | **Linux + macOS + Windows**, shipped as **bundled wheels** | Native runtime must be built/obtained per-platform and packaged via `cibuildwheel` |
17
+ | Viewer | **Headless first** | Skip the 33 viewer fns + GUI-thread/GIL/main-thread-GL complexity in v1 |
18
+
19
+ ### Why a binding, not a rewrite
20
+ PicoGK is itself a thin wrapper. The real engine is **PicoGKRuntime** (C++ on **OpenVDB**
21
+ sparse level sets + **GLFW/OpenGL** viewer). The C# side is just: `[DllImport]` declarations,
22
+ handle-wrapping classes, and pure-C# conveniences (IO, shapes, numerics). The native boundary
23
+ is a **flat C ABI** — `API/PicoGK.h`, **177 `extern "C"` functions**, every object an opaque
24
+ `uint64_t` handle, trivial packed structs. That maps almost 1:1 onto ctypes. Reimplementing the
25
+ kernel would mean reimplementing OpenVDB — huge and slow. We do what C# does: bind the runtime.
26
+
27
+ ## 2. Native C ABI — the surface we bind
28
+
29
+ - Objects are opaque handles: `PKINSTANCE/PKVOXELS/PKMESH/PKLATTICE/PKSCALARFIELD/PKVECTORFIELD/PKPOLYLINE/PKVDBFILE/PKMETADATA = uint64_t`.
30
+ - First arg of (almost) every function is the **library instance** handle → we hold it as a global singleton, so Python users never pass it (matches C# static `Library`).
31
+ - Structs are `#pragma pack(1)`: `PKVector3{f,f,f}`, `PKVector2`, `PKVector4`, `PKTriangle{i32,i32,i32}`, `PKCoord{i32×3}`, `PKBBox3{vec3,vec3}`, `PKMatrix4x4{vec4×4}`, `PKColorFloat{f×4}`.
32
+ - Library name string: `picogk.26.2` (resolves to `picogk.26.2.dll` / `libpicogk.26.2.dylib` / `libpicogk.26.2.so`).
33
+
34
+ ### Function count by category (177 total)
35
+ `Voxels` 33 · `Viewer` 33 *(skip v1)* · `Library` 24 · `VdbFile` 15 · `Metadata` 15 ·
36
+ `ScalarField` 13 · `Mesh` 13 · `VectorField` 11 · `PolyLine` 9 · `Lattice` 6.
37
+ → **~110 functions for the headless v1.**
38
+
39
+ ### Two facts that shape the design
40
+ 1. **No bulk array transfer.** Mesh verts/tris and field values are accessed one element at a
41
+ time (`Mesh_GetVertex`, `ScalarField_SetValue`, …). Millions of ctypes calls per mesh is a
42
+ real perf cliff → plan a compiled fast-loop (see §6). Not v1-blocking.
43
+ 2. **Implicit modeling is callback-driven** (`Voxels_RenderImplicit(PKPFnfSdf)` called per point).
44
+ A Python SDF lambda per-voxel is very slow. Fast path = native primitives + booleans
45
+ (sphere/capsule/lattice/mesh-render/offset/bool — all present). Python-callback SDFs become an
46
+ opt-in "flexible but slow" mode.
47
+
48
+ ## 3. Package architecture
49
+
50
+ ```
51
+ picopie/ # pip name: picopie · import name: picogk
52
+ ├── pyproject.toml # build via scikit-build-core or setuptools + cibuildwheel
53
+ ├── src/picogk/
54
+ │ ├── __init__.py # public API: init(), Voxels, Mesh, Lattice, ScalarField, ...
55
+ │ ├── _native/
56
+ │ │ ├── loader.py # locate + dlopen runtime (bundled → env var → system)
57
+ │ │ ├── ctypes_types.py # ctypes Structures (_pack_=1) + numpy dtype mirrors
58
+ │ │ ├── prototypes.py # GENERATED: argtypes/restype for every C fn (from PicoGK.h)
59
+ │ │ └── _gen_prototypes.py# header parser/codegen (keeps us in sync per runtime version)
60
+ │ ├── library.py # Library singleton: init(voxel_size), instance handle, log cb
61
+ │ ├── voxels.py # Voxels (primitives, booleans, offsets, volume, slices, render*)
62
+ │ ├── mesh.py # Mesh (+ from_voxels, numpy verts/tris)
63
+ │ ├── lattice.py # Lattice (beams/spheres)
64
+ │ ├── fields.py # ScalarField, VectorField
65
+ │ ├── polyline.py # PolyLine
66
+ │ ├── types.py # Vector3/BBox3/Matrix4x4 helpers ↔ numpy/tuples
67
+ │ ├── metadata.py # field/voxel metadata
68
+ │ ├── io/ # stl/obj export, vdb save/load, png slice export
69
+ │ └── _fastloop/ # OPTIONAL Cython/C ext: bulk mesh/field transfer (Phase 4)
70
+ ├── tests/ # pytest, incl. golden comparisons vs C# PicoGK
71
+ ├── examples/ # gyroid lattice, boolean part, mesh→voxelize→offset→export
72
+ └── native/ # build scripts/CI for PicoGKRuntime per platform
73
+ ```
74
+
75
+ ### Core design rules
76
+ - **Handle lifetime** → each wrapper holds `(instance, handle)`; implement `close()`,
77
+ `__enter__/__exit__`, and `__del__` calling the matching `*_Destroy`. Guard double-free; tear
78
+ down objects before the library instance. Mirrors C# `IDisposable`.
79
+ - **Library singleton** → `picogk.init(voxel_size_mm=0.1)` creates the instance via
80
+ `Library_hCreateInstance`; everything else pulls it implicitly (like C# static `Library`).
81
+ - **Log callback** → register a `PKFInfo` CFUNCTYPE routed to Python `logging`; keep a hard ref
82
+ so it isn't GC'd. Fatal-error flag → raise `PicoGKError`.
83
+ - **NumPy first** → vectors/bboxes accept/return numpy or tuples; fields and mesh buffers expose
84
+ numpy views; conversions centralized in `types.py`.
85
+ - **Prototype codegen** → parse `PicoGK.h` (regular `PICOGK_API <ret> <Name>(<args>);` grammar)
86
+ to generate `prototypes.py`. Re-run per runtime version; no hand-maintained 177-fn table.
87
+
88
+ ## 4. C# → Python mapping
89
+
90
+ | C# (`Base/*.cs`) | Python | Notes |
91
+ |---|---|---|
92
+ | `Library` (static, `Go`) | `picogk.init()` + module globals | hides instance handle |
93
+ | `Voxels` | `picogk.Voxels` | primitives, `+ - &` → `__add__/__sub__/__and__` (BoolAdd/Subtract/Intersect), offsets, `volume()`, slices, `render_mesh/lattice/implicit` |
94
+ | `Mesh` | `picogk.Mesh` | `from_voxels`, `.vertices`/`.triangles` numpy |
95
+ | `Lattice` | `picogk.Lattice` | `add_beam`, `add_sphere` |
96
+ | `ScalarField`/`VectorField` | `picogk.ScalarField`/`VectorField` | get/set, traverse, from-voxels |
97
+ | `PolyLine` | `picogk.PolyLine` | |
98
+ | `BBox3`/`Matrix4x4`/`Vector3` | `picogk.types` | numpy-backed |
99
+ | IO (`MeshIo`,`OpenVdbFile`,`VoxelsIo`,`ImageIo`) | `picogk.io` | STL/OBJ/VDB/PNG |
100
+ | `Viewer` | — | deferred (post-v1) |
101
+ | `Shapes/*`, ShapeKernel | — | follow-on pure-Python port (it's pure C# atop PicoGK) |
102
+
103
+ ## 5. Milestones
104
+
105
+ - **M0 — Runtime on Linux (gating).** Build PicoGKRuntime from source (vcpkg/CMake: OpenVDB, TBB,
106
+ Boost, Blosc, zlib, GLFW). Success: `ctypes.CDLL` loads it and `Library_GetVersion` returns a
107
+ string. *Biggest practical risk; do first.*
108
+ - **M1 — ctypes core.** Header→`prototypes.py` codegen, ctypes structs, loader, `init()`, log
109
+ callback, handle/dispose. Smoke test: create instance → `Voxels.sphere()` → `volume()`.
110
+ - **M2 — Geometry layer.** Voxels (primitives/booleans/offsets/volume/slices/render), Mesh,
111
+ Lattice, ScalarField, VectorField, PolyLine, BBox, metadata, NumPy interop.
112
+ - **M3 — IO + examples.** STL/OBJ export, VDB save/load, PNG slice export; 3 headless examples.
113
+ - **M4 — Performance.** Cython/C `_fastloop` for bulk mesh/field transfer (loops in compiled code
114
+ over the runtime's per-element fns — no runtime rebuild needed); benchmarks.
115
+ - **M5 — Packaging.** `pyproject`, `cibuildwheel` matrix, bundle runtime via
116
+ `auditwheel`/`delocate`/`delvewheel`; reuse LEAP71 prebuilt mac/Windows runtimes to unblock CI.
117
+ - **M6 — Tests vs C# golden + docs.** Compare volumes/bbox/counts/VDB round-trips against C#
118
+ reference scripts; API docs; quickstart.
119
+ - **Later** — native viewer (thread/GIL/main-thread-GL), ShapeKernel port.
120
+
121
+ ## 6. Performance plan
122
+ v1: correctness-first, per-element loops in Python with numpy-shaped properties; document the
123
+ hotspot. Phase 4: small Cython extension that re-declares the runtime's per-element fns and loops
124
+ in C, filling contiguous buffers → single numpy copy. Avoids rebuilding the runtime and keeps the
125
+ ctypes layer pure-Python for everything else.
126
+
127
+ ## 7. Testing
128
+ - Golden comparisons vs C# PicoGK on deterministic ops (sphere volume, boolean volumes, offset
129
+ results, mesh vert/tri counts, voxel dims, VDB round-trip).
130
+ - pytest unit tests per wrapper; memory/handle-leak checks via `Library_n*Allocated` counters.
131
+ - CI runs the headless suite on all three platforms.
132
+
133
+ ## 8. Risks & mitigations
134
+ | Risk | Mitigation |
135
+ |---|---|
136
+ | Building OpenVDB-based runtime on Linux is heavy | Use vcpkg manifest in a manylinux container; cache; reuse LEAP71 prebuilt mac/Win runtimes |
137
+ | Per-element transfer too slow | Cython `_fastloop` (Phase 4); keep ops native where possible |
138
+ | Python-callback SDFs slow | Steer users to native primitives+booleans; mark SDF mode "flexible/slow" |
139
+ | Runtime version drift (`picogk.26.x`) | Generate prototypes from header; pin/version-check at load |
140
+ | Handle lifetime / double-free | Centralized dispose + allocation-counter leak tests |
141
+ | Cross-platform `.so/.dylib/.dll` name resolution | Normalize in `loader.py`; `PICOGK_RUNTIME` env override |
142
+
143
+ ## 9. Immediate next steps
144
+ 1. Scaffold the package (`pyproject.toml`, `src/picogk/`, `tests/`, `examples/`).
145
+ 2. Vendor `PicoGK.h` + `PicoGKApiTypes.h`; write `_gen_prototypes.py` and emit `prototypes.py`.
146
+ 3. Stand up the Linux runtime build (M0) — the gating prerequisite.
147
+ 4. Implement `loader.py` + `library.py` + a smoke test (sphere → volume).
@@ -0,0 +1,110 @@
1
+ # PicoPie
2
+
3
+ A **Pythonic binding for [PicoGK](https://github.com/leap71/PicoGK)** — LEAP 71's
4
+ compact computational-geometry kernel for engineering (voxel / level-set modeling
5
+ on OpenVDB).
6
+
7
+ PicoPie binds the *same native runtime* the official C# library uses — so you get
8
+ identical geometry and performance — then wraps it in an idiomatic, NumPy-friendly
9
+ Python API. No .NET, no compiler, no system libraries: just `pip install picopie`.
10
+
11
+ ```python
12
+ import picogk
13
+ from picogk import Voxels
14
+
15
+ picogk.init(voxel_size_mm=0.2)
16
+
17
+ body = Voxels.sphere(radius=10)
18
+ hole = Voxels.sphere(center=(6, 0, 0), radius=6)
19
+ part = body - hole # boolean subtract → new Voxels
20
+ part.shell_(1.0) # hollow to a 1 mm wall (in place)
21
+
22
+ vol, bbox = part.calculate_properties()
23
+ print(f"{vol:.1f} mm³")
24
+ part.to_mesh().save_stl("part.stl")
25
+ ```
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ pip install picopie # core
31
+ pip install "picopie[viz]" # + headless slice/mesh PNG helpers (Pillow, matplotlib)
32
+ ```
33
+
34
+ or with [uv](https://docs.astral.sh/uv/):
35
+
36
+ ```bash
37
+ uv add picopie
38
+ ```
39
+
40
+ Wheels are self-contained — the native runtime (OpenVDB 13, PicoGK 26.2) and all
41
+ its C++ deps are bundled. Prebuilt for CPython 3.10–3.13 on **Linux (manylinux
42
+ x86-64), macOS (Apple Silicon), and Windows (x64)**.
43
+
44
+ ## Documentation
45
+
46
+ - **[Quickstart](docs/quickstart.md)** · **[Guide](docs/guide.md)** · **[API reference](docs/api.md)**
47
+ - **Tutorials** — [Novice](docs/tutorials/novice/), [Intermediate](docs/tutorials/intermediate/),
48
+ [Advanced](docs/tutorials/advanced/)
49
+ - **[QuickLearn](docs/tutorials/QuickLearn.md)** — the whole API in one annotated file
50
+ (learn-x-in-y-minutes style)
51
+
52
+ ## Features
53
+
54
+ - **`Voxels`** — primitives (`sphere`, `capsule`), booleans (`+ - &`), offsets,
55
+ `shell_` (hollow), implicit SDF modeling, and queries (`is_inside`,
56
+ `closest_point`, `surface_normal`, `ray_cast`, `calculate_properties`).
57
+ - **`Mesh`** — from voxels (marching cubes), NumPy `vertices`/`triangles`, STL/OBJ
58
+ import **and** export.
59
+ - **`Lattice`** (beams + spheres), **`ScalarField`** / **`VectorField`** (bulk
60
+ `set_many`/`get_many`), **`Metadata`**, **`PolyLine`**.
61
+ - **File I/O** — `save_vdb` / `load_vdb` round-trips voxels + fields (OpenVDB).
62
+ - **Headless viz** (`[viz]`) — `save_slice_png`, `save_slice_sheet`, `mesh_preview`.
63
+ - **Interactive viewer** — `picogk.show(part)` (GLFW/OpenGL, orbit camera) and
64
+ `render_png(part, "out.png")` for offscreen renders.
65
+ - **Fast path** — a compiled `_fastloop` extension (~13–28× faster bulk mesh/field
66
+ transfer) with automatic pure-Python fallback.
67
+
68
+ ## Reliability
69
+
70
+ PicoPie is validated against the reference and hardened well beyond a naive binding:
71
+
72
+ - **Parity-tested vs C# PicoGK** on the same runtime — volumes, dims, mesh
73
+ counts/bbox, and geometric queries match to float precision.
74
+ - **Never aborts** — the native runtime is patched so a C++/OpenVDB error surfaces
75
+ as a catchable `PicoGKError` instead of killing the process; non-finite inputs are
76
+ rejected up front. Verified against thousands of fuzzed inputs.
77
+ - **Reproducible & auditable** — every upstream dependency is version-pinned; builds
78
+ ship an SBOM (`sbom.cdx.json`) and hash-pinned build deps.
79
+ - Green CI across Linux/macOS/Windows; mypy + ruff clean; ~190 tests.
80
+
81
+ ## Development
82
+
83
+ ```bash
84
+ git clone https://github.com/Borderliner/PicoPie && cd PicoPie
85
+ python -m venv .venv && source .venv/bin/activate
86
+ scripts/build_runtime.sh # build + stage the native runtime (see below)
87
+ pip install -e ".[dev]"
88
+ pytest
89
+ ```
90
+
91
+ Building the native runtime (Linux) needs system deps:
92
+
93
+ ```bash
94
+ sudo apt-get install -y --no-install-recommends \
95
+ libboost-all-dev libblosc-dev libtbb-dev extra-cmake-modules \
96
+ xorg-dev mesa-common-dev libgl1-mesa-dev ninja-build cmake g++ git
97
+ scripts/build_runtime.sh
98
+ ```
99
+
100
+ PicoPie locates the runtime automatically: bundled in the wheel (`picogk/_lib/`),
101
+ else under `native/`, else via `$PICOGK_RUNTIME` (full path to the shared library).
102
+ Cross-platform wheels are built by `cibuildwheel` in `.github/workflows/wheels.yml`.
103
+
104
+ See [`ROADMAP.md`](ROADMAP.md) for the (now-complete) phase history and
105
+ [`PLAN.md`](PLAN.md) for the architecture rationale.
106
+
107
+ ## License
108
+
109
+ Apache-2.0, matching upstream PicoGK / PicoGKRuntime. Ported by
110
+ Mohammadreza Hajianpour and Vish Vadlamani.