vvox 0.4.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.
Files changed (51) hide show
  1. vvox-0.4.0/CHANGELOG.md +30 -0
  2. vvox-0.4.0/LICENSE +28 -0
  3. vvox-0.4.0/MANIFEST.in +7 -0
  4. vvox-0.4.0/PKG-INFO +269 -0
  5. vvox-0.4.0/README.md +236 -0
  6. vvox-0.4.0/benchmarks/RESULTS.md +213 -0
  7. vvox-0.4.0/benchmarks/benchmark_vvox.py +176 -0
  8. vvox-0.4.0/benchmarks/gyroid-preview.png +0 -0
  9. vvox-0.4.0/benchmarks/torus-preview.png +0 -0
  10. vvox-0.4.0/docs/design.md +192 -0
  11. vvox-0.4.0/docs/development.md +243 -0
  12. vvox-0.4.0/docs/usage.md +283 -0
  13. vvox-0.4.0/docs/voxelization-semantics.md +87 -0
  14. vvox-0.4.0/environment.yml +18 -0
  15. vvox-0.4.0/pyproject.toml +70 -0
  16. vvox-0.4.0/setup.cfg +4 -0
  17. vvox-0.4.0/src/vvox/__init__.py +31 -0
  18. vvox-0.4.0/src/vvox/__main__.py +4 -0
  19. vvox-0.4.0/src/vvox/backend.py +210 -0
  20. vvox-0.4.0/src/vvox/backends/__init__.py +11 -0
  21. vvox-0.4.0/src/vvox/backends/base.py +38 -0
  22. vvox-0.4.0/src/vvox/backends/cpu.py +654 -0
  23. vvox-0.4.0/src/vvox/backends/cuda.py +475 -0
  24. vvox-0.4.0/src/vvox/backends/selection.py +77 -0
  25. vvox-0.4.0/src/vvox/cli.py +248 -0
  26. vvox-0.4.0/src/vvox/errors.py +30 -0
  27. vvox-0.4.0/src/vvox/io.py +56 -0
  28. vvox-0.4.0/src/vvox/kernels.py +901 -0
  29. vvox-0.4.0/src/vvox/mesh.py +658 -0
  30. vvox-0.4.0/src/vvox/pipeline.py +135 -0
  31. vvox-0.4.0/src/vvox/robust.py +628 -0
  32. vvox-0.4.0/src/vvox/semantics.py +31 -0
  33. vvox-0.4.0/src/vvox/types.py +419 -0
  34. vvox-0.4.0/src/vvox.egg-info/PKG-INFO +269 -0
  35. vvox-0.4.0/src/vvox.egg-info/SOURCES.txt +49 -0
  36. vvox-0.4.0/src/vvox.egg-info/dependency_links.txt +1 -0
  37. vvox-0.4.0/src/vvox.egg-info/entry_points.txt +2 -0
  38. vvox-0.4.0/src/vvox.egg-info/requires.txt +21 -0
  39. vvox-0.4.0/src/vvox.egg-info/top_level.txt +1 -0
  40. vvox-0.4.0/tests/test_backend_equivalence.py +50 -0
  41. vvox-0.4.0/tests/test_backend_selection.py +79 -0
  42. vvox-0.4.0/tests/test_cli.py +36 -0
  43. vvox-0.4.0/tests/test_cpu_backend.py +123 -0
  44. vvox-0.4.0/tests/test_cuda_environment.py +86 -0
  45. vvox-0.4.0/tests/test_cuda_overrides.py +102 -0
  46. vvox-0.4.0/tests/test_fixed_grid.py +103 -0
  47. vvox-0.4.0/tests/test_io.py +140 -0
  48. vvox-0.4.0/tests/test_mesh.py +310 -0
  49. vvox-0.4.0/tests/test_pipeline.py +60 -0
  50. vvox-0.4.0/tests/test_semantics.py +74 -0
  51. vvox-0.4.0/tests/test_types.py +173 -0
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ Notable user-facing changes to `vvox` are recorded here. The project follows
4
+ [Semantic Versioning](https://semver.org/) for its distribution version and
5
+ separately records voxelization semantics in result diagnostics.
6
+
7
+ ## 0.4.0 - 2026-11-29
8
+
9
+ Initial public release of `vvox`.
10
+
11
+ ### Added
12
+
13
+ - `vvox` distribution, Python package, and command-line interface.
14
+ - Numba CPU and CuPy CUDA backends behind one public API.
15
+ - Automatic backend selection with explicit CPU and CUDA modes.
16
+ - Version 2 signed-winding, boundary, and robust-resolution semantics.
17
+ - Auto-derived and caller-defined Cartesian grids.
18
+ - Bit-packed dense occupancy grids and sparse occupancy grids that store only
19
+ active `8x8x8` voxel blocks.
20
+ - Reusable prepared meshes and validation-only prepared-surface re-entry.
21
+ - Structured repair reports and voxelization diagnostics.
22
+ - Environment-local CuPy kernel caching for named Conda, micromamba, and
23
+ virtual environments.
24
+
25
+ ### Changed
26
+
27
+ - Public arrays now use `(x, y, z)` order by default; `(z, y, x)` remains
28
+ available explicitly.
29
+ - CUDA and Numba are optional backend dependencies rather than import-time
30
+ requirements.
vvox-0.4.0/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Chi Chung Li
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vvox-0.4.0/MANIFEST.in ADDED
@@ -0,0 +1,7 @@
1
+ include CHANGELOG.md
2
+ include environment.yml
3
+ recursive-include docs *.md
4
+ recursive-include benchmarks *.md *.py
5
+ include benchmarks/torus-preview.png
6
+ include benchmarks/gyroid-preview.png
7
+ recursive-include tests *.py
vvox-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,269 @@
1
+ Metadata-Version: 2.4
2
+ Name: vvox
3
+ Version: 0.4.0
4
+ Summary: Robust CPU and CUDA mesh voxelizer with built-in 3MF support and repair reporting.
5
+ Author: Chi Chung Li
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Source, https://github.com/alvinccli/vvox
8
+ Project-URL: Documentation, https://github.com/alvinccli/vvox/blob/v0.4.0/docs/usage.md
9
+ Project-URL: Issues, https://github.com/alvinccli/vvox/issues
10
+ Project-URL: Changelog, https://github.com/alvinccli/vvox/blob/v0.4.0/CHANGELOG.md
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy>=1.26
18
+ Requires-Dist: trimesh>=4.6
19
+ Requires-Dist: networkx>=3.2
20
+ Requires-Dist: lxml>=6.0
21
+ Provides-Extra: cpu
22
+ Requires-Dist: numba>=0.61; extra == "cpu"
23
+ Provides-Extra: cuda
24
+ Requires-Dist: cupy-cuda12x[ctk]>=13.3; (platform_system == "Windows" or platform_system == "Linux") and extra == "cuda"
25
+ Provides-Extra: dev
26
+ Requires-Dist: build; extra == "dev"
27
+ Requires-Dist: pytest>=8.3; extra == "dev"
28
+ Requires-Dist: ruff; extra == "dev"
29
+ Requires-Dist: twine; extra == "dev"
30
+ Provides-Extra: repair
31
+ Requires-Dist: pymeshfix>=0.18; extra == "repair"
32
+ Dynamic: license-file
33
+
34
+ # vvox
35
+
36
+ `vvox` turns triangle meshes into filled 3D masks for image analysis or
37
+ simulation. Load an STL, OBJ, or 3MF file, or pass a
38
+ `trimesh.Trimesh` or your own vertex and face arrays directly from Python.
39
+
40
+ ## Why use vvox?
41
+
42
+ - **Repair common mesh defects before voxelizing.** Built-in cleanup merges
43
+ duplicate vertices, removes duplicate or degenerate triangles, and can
44
+ close small holes and correct inconsistent face winding. The optional
45
+ MeshFix pass can help with larger gaps. [See what changed in the repair report](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#inspect-a-mesh-repair)
46
+ - **Match your simulation or image grid.** Supply the shape, origin, and voxel
47
+ size to align the mask with an existing grid of cubic voxels, or let `vvox`
48
+ fit the grid to the mesh. Use `prepare_mesh` once to reuse the same geometry
49
+ at several resolutions.
50
+ - **Voxelize hollow parts and overlapping solids.** An inward-facing inner
51
+ shell defines a cavity, and overlapping outward-facing shells stay filled.
52
+ Both backends count voxel centers on the surface as occupied and check
53
+ ambiguous crossings in float64, then with exact arithmetic if needed.
54
+ - **Keep large masks compact.** For the 514³ gyroid below, the packed dense
55
+ mask stores one bit for every voxel (1 for occupied, 0 for empty) and uses
56
+ 16.97 MB. The sparse mask skips entirely empty 8 × 8 × 8 blocks and uses
57
+ 8.96 MB. The same mask in a NumPy `uint8` array uses one byte per voxel,
58
+ or 135.8 MB.
59
+ - **Accelerate the same Python code with CUDA.** On the 514³ gyroid, a
60
+ GTX 1070 Ti was 2.7× as fast as a Ryzen 5 1600X (median of five warm
61
+ calls). Both returned byte-identical dense and sparse outputs.
62
+
63
+ [Install vvox](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#installation) · [Try the Python example](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#python-quick-start) · [Use the command line](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#command-line)
64
+
65
+ ## Voxelizing a sheet gyroid
66
+
67
+ A thin wall winds through this cube, separating two networks of channels.
68
+ The 3D view and middle slice show the occupied voxels at pitch 1/64.
69
+ The benchmark uses the same 241,824-triangle mesh at each resolution.
70
+
71
+ ![Voxelized sheet gyroid with openings on the cube faces, beside an XY slice showing the thin curved walls between the channels.](https://raw.githubusercontent.com/alvinccli/vvox/v0.4.0/benchmarks/gyroid-preview.png)
72
+
73
+ | Pitch | Padded grid | Grid cells | CPU median | CUDA median |
74
+ |---|---:|---:|---:|---:|
75
+ | 1/64 | 130³ | 2,197,000 | 8.91 s | 4.04 s |
76
+ | 1/128 | 258³ | 17,173,512 | 7.97 s | 2.19 s |
77
+ | 1/256 | 514³ | 135,796,744 | 13.28 s | 4.97 s |
78
+
79
+ Going from 130³ to 258³ halves the voxel size. Each tile of 16 × 16 columns
80
+ covers a smaller area of the gyroid. Rays that need exact arithmetic check
81
+ fewer triangles on average, cutting the total exact checks from 39,738 to
82
+ 20,117. Both backends do these checks on the CPU, so both benefit.
83
+ [Timing breakdown](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md#gyroid-timing-breakdown)
84
+
85
+ The table reports medians of five warm calls on a Ryzen 5 1600X and a GeForce GTX
86
+ 1070 Ti. Each call returned both packed dense and sparse occupancy to the
87
+ host. The finest grid has 61.8× as many cells as the coarsest. It took
88
+ 1.49× as long on CPU and 1.23× as long on CUDA. The two backends matched
89
+ both output hashes at every pitch.
90
+ [First-call timings, output sizes, and reproduction commands](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md#generated-sheet-gyroid)
91
+
92
+ To run the gyroid demo from a checkout, install the CPU backend and run
93
+
94
+ ```console
95
+ python -m pip install ".[cpu]"
96
+ python benchmarks/benchmark_vvox.py --shape gyroid --extent 2 --pitch 0.015625 --prepared --backend cpu
97
+ ```
98
+
99
+ The script generates the mesh locally. Use `--pitch 0.0078125` or
100
+ `--pitch 0.00390625` for the finer grids. With the CUDA backend installed,
101
+ use `--backend cuda` to run the same cases on an NVIDIA GPU.
102
+
103
+ ## Installation
104
+
105
+ For CPU voxelization, install the Numba backend.
106
+
107
+ ```console
108
+ python -m pip install "vvox[cpu]"
109
+ ```
110
+
111
+ From a source checkout, use `python -m pip install ".[cpu]"` in the repository
112
+ root.
113
+
114
+ For an NVIDIA GPU on Windows or Linux with a CUDA 12-compatible driver, install
115
+ the CUDA backend on its own or alongside the CPU backend.
116
+
117
+ ```console
118
+ python -m pip install "vvox[cuda]" # CuPy CUDA backend
119
+ python -m pip install "vvox[cpu,cuda]" # both backends, auto prefers CUDA
120
+ ```
121
+
122
+ The base distribution can be imported on its own. Voxelization requires at
123
+ least one installed backend. With both installed, `backend="auto"` prefers
124
+ an available CUDA device. Set `backend="cpu"` or `backend="cuda"` to choose
125
+ explicitly.
126
+
127
+ If open or nonmanifold edges remain after standard cleanup, the optional
128
+ `repair` extra lets `vvox` try MeshFix. In a test with a cylinder missing
129
+ its top cap, MeshFix closed all 12 remaining boundary edges. To install
130
+ it alongside the CPU backend, run
131
+
132
+ ```console
133
+ python -m pip install "vvox[cpu,repair]"
134
+ ```
135
+
136
+ See the [MeshFix licensing and research citation terms](https://github.com/pyvista/pymeshfix/blob/main/README.rst#algorithm-and-citation-policy).
137
+
138
+ ## Python quick start
139
+
140
+ Voxelize a unit cube with four voxels along each edge.
141
+
142
+ ```python
143
+ import trimesh
144
+
145
+ from vvox import voxelize_mesh
146
+
147
+ result = voxelize_mesh(
148
+ trimesh.creation.box(),
149
+ pitch=0.25,
150
+ outputs=("dense", "sparse"),
151
+ backend="auto",
152
+ )
153
+
154
+ occupancy_xyz = result.to_numpy()
155
+ print(int(occupancy_xyz.sum())) # 64 occupied voxels
156
+ print(result.diagnostics.backend)
157
+ ```
158
+
159
+ To use your own part, replace `trimesh.creation.box()` with a path such as
160
+ `"part.3mf"` and set `pitch` in the mesh's length units. The result stays in
161
+ memory. Inspect `result.repair_report` for mesh cleanup and repairs, or
162
+ `result.diagnostics` for the backend, semantics version, and counts of columns
163
+ that needed extra precision. Call `vvox.io.write_result(...)` to save it.
164
+
165
+ ### Inspect a mesh repair
166
+
167
+ Removing one triangle from a box leaves three exposed edges. Built-in
168
+ cleanup closes this hole, and the report lets you check that the surface
169
+ is watertight before voxelization.
170
+
171
+ ```python
172
+ import trimesh
173
+ from vvox import prepare_mesh
174
+
175
+ box = trimesh.creation.box()
176
+ box.faces = box.faces[1:] # Remove one triangle.
177
+ prepared = prepare_mesh(box)
178
+ report = prepared.repair_report
179
+ print(report.initial.boundary_edge_count, report.final.boundary_edge_count) # 3 0
180
+ print(report.final.watertight) # True
181
+ ```
182
+
183
+ Pass `prepared` to `voxelize_mesh` to reuse the repaired surface. If the
184
+ final surface is still open or has inconsistent face winding, `prepare_mesh`
185
+ raises `InvalidMeshError` with the repair report attached.
186
+
187
+ ### A hollow shape on a fixed grid
188
+
189
+ Generate a torus and voxelize it on a caller-defined grid. Requesting sparse
190
+ output stores occupancy in active `8 × 8 × 8` bricks.
191
+
192
+ ```python
193
+ import trimesh
194
+
195
+ from vvox import voxelize_mesh_on_grid
196
+
197
+ ring = trimesh.creation.torus(
198
+ major_radius=0.875, minor_radius=0.125, major_sections=128, minor_sections=32
199
+ )
200
+ result = voxelize_mesh_on_grid(
201
+ ring,
202
+ shape_xyz=(128, 128, 128),
203
+ origin_xyz=(-1, -1, -1),
204
+ pitch=1 / 64,
205
+ outputs=("sparse",),
206
+ )
207
+ occupancy = result.to_numpy() # Expand the bricks to inspect individual voxels.
208
+ print(occupancy[64, 64, 64], occupancy[120, 64, 64]) # 0 in the hole, 1 in the tube
209
+ ```
210
+
211
+ On CPU, sparse-only voxelization builds the bricks directly from the occupied
212
+ intervals. On this grid the ring occupies 272 of 4,096 bricks. The sparse
213
+ arrays use 20,672 bytes, compared with 262,144 bytes for packed dense
214
+ occupancy. Supply the mesh and grid in the same coordinate frame and units.
215
+
216
+ In a separate benchmark at the same pitch, the 8,192-triangle torus took
217
+ 279 ms on CPU and 13.5 ms on CUDA on an auto-fit 130 × 130 × 18 grid
218
+ (five warm calls on the Ryzen 5 1600X and GTX 1070 Ti).
219
+ [Torus preview and timings](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md#generated-torus)
220
+
221
+ ## Command line
222
+
223
+ To use the torus above as a CLI input, run `ring.export("ring.3mf")` in the
224
+ same Python session. Then run the voxelizer from that directory.
225
+
226
+ ```console
227
+ vvox voxelize ring.3mf --pitch 0.015625 --backend auto --outputs dense,sparse --out-dir output
228
+ ```
229
+
230
+ To reproduce the fixed-grid sparse result from the Python example, run
231
+
232
+ ```console
233
+ vvox voxelize ring.3mf --pitch 0.015625 --shape-xyz 128 128 128 --origin-xyz -1 -1 -1 --outputs sparse --out-dir output-fixed
234
+ ```
235
+
236
+ The CLI prints a repair summary and writes the full report under `mesh_repair`
237
+ in `metadata.json`. It also writes the requested `dense.npz` and/or
238
+ `sparse_bricks.npz` files.
239
+
240
+ ## Documentation
241
+
242
+ - [Usage guide](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/usage.md): inputs, grids, backends, outputs, CUDA setup,
243
+ troubleshooting, and complete examples.
244
+ - [Design decisions](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/design.md): architectural choices, tradeoffs, and
245
+ their advantages.
246
+ - [Voxelization semantics](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/voxelization-semantics.md): the formal occupancy and
247
+ numerical-resolution contract.
248
+ - [Development guide](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/development.md): environment setup, repository
249
+ structure, testing, benchmarks, and release checks.
250
+ - [Benchmark snapshot](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md): dated CPU/CUDA development
251
+ measurements.
252
+ - [Changelog](https://github.com/alvinccli/vvox/blob/v0.4.0/CHANGELOG.md): versioned user-facing changes and compatibility
253
+ notes.
254
+
255
+ ## Development
256
+
257
+ The checked-in environment installs the project editable with both backends and
258
+ development tools:
259
+
260
+ ```console
261
+ micromamba create -y -p ./.micromamba -f environment.yml
262
+ micromamba run -p ./.micromamba python -m pytest -q --basetemp .vvox-runtime/pytest-temp tests
263
+ ```
264
+
265
+ See the [development guide](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/development.md) for the complete workflow.
266
+
267
+ ## License
268
+
269
+ `vvox` is distributed under the BSD 3-Clause License. See [LICENSE](https://github.com/alvinccli/vvox/blob/v0.4.0/LICENSE).
vvox-0.4.0/README.md ADDED
@@ -0,0 +1,236 @@
1
+ # vvox
2
+
3
+ `vvox` turns triangle meshes into filled 3D masks for image analysis or
4
+ simulation. Load an STL, OBJ, or 3MF file, or pass a
5
+ `trimesh.Trimesh` or your own vertex and face arrays directly from Python.
6
+
7
+ ## Why use vvox?
8
+
9
+ - **Repair common mesh defects before voxelizing.** Built-in cleanup merges
10
+ duplicate vertices, removes duplicate or degenerate triangles, and can
11
+ close small holes and correct inconsistent face winding. The optional
12
+ MeshFix pass can help with larger gaps. [See what changed in the repair report](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#inspect-a-mesh-repair)
13
+ - **Match your simulation or image grid.** Supply the shape, origin, and voxel
14
+ size to align the mask with an existing grid of cubic voxels, or let `vvox`
15
+ fit the grid to the mesh. Use `prepare_mesh` once to reuse the same geometry
16
+ at several resolutions.
17
+ - **Voxelize hollow parts and overlapping solids.** An inward-facing inner
18
+ shell defines a cavity, and overlapping outward-facing shells stay filled.
19
+ Both backends count voxel centers on the surface as occupied and check
20
+ ambiguous crossings in float64, then with exact arithmetic if needed.
21
+ - **Keep large masks compact.** For the 514³ gyroid below, the packed dense
22
+ mask stores one bit for every voxel (1 for occupied, 0 for empty) and uses
23
+ 16.97 MB. The sparse mask skips entirely empty 8 × 8 × 8 blocks and uses
24
+ 8.96 MB. The same mask in a NumPy `uint8` array uses one byte per voxel,
25
+ or 135.8 MB.
26
+ - **Accelerate the same Python code with CUDA.** On the 514³ gyroid, a
27
+ GTX 1070 Ti was 2.7× as fast as a Ryzen 5 1600X (median of five warm
28
+ calls). Both returned byte-identical dense and sparse outputs.
29
+
30
+ [Install vvox](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#installation) · [Try the Python example](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#python-quick-start) · [Use the command line](https://github.com/alvinccli/vvox/blob/v0.4.0/README.md#command-line)
31
+
32
+ ## Voxelizing a sheet gyroid
33
+
34
+ A thin wall winds through this cube, separating two networks of channels.
35
+ The 3D view and middle slice show the occupied voxels at pitch 1/64.
36
+ The benchmark uses the same 241,824-triangle mesh at each resolution.
37
+
38
+ ![Voxelized sheet gyroid with openings on the cube faces, beside an XY slice showing the thin curved walls between the channels.](https://raw.githubusercontent.com/alvinccli/vvox/v0.4.0/benchmarks/gyroid-preview.png)
39
+
40
+ | Pitch | Padded grid | Grid cells | CPU median | CUDA median |
41
+ |---|---:|---:|---:|---:|
42
+ | 1/64 | 130³ | 2,197,000 | 8.91 s | 4.04 s |
43
+ | 1/128 | 258³ | 17,173,512 | 7.97 s | 2.19 s |
44
+ | 1/256 | 514³ | 135,796,744 | 13.28 s | 4.97 s |
45
+
46
+ Going from 130³ to 258³ halves the voxel size. Each tile of 16 × 16 columns
47
+ covers a smaller area of the gyroid. Rays that need exact arithmetic check
48
+ fewer triangles on average, cutting the total exact checks from 39,738 to
49
+ 20,117. Both backends do these checks on the CPU, so both benefit.
50
+ [Timing breakdown](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md#gyroid-timing-breakdown)
51
+
52
+ The table reports medians of five warm calls on a Ryzen 5 1600X and a GeForce GTX
53
+ 1070 Ti. Each call returned both packed dense and sparse occupancy to the
54
+ host. The finest grid has 61.8× as many cells as the coarsest. It took
55
+ 1.49× as long on CPU and 1.23× as long on CUDA. The two backends matched
56
+ both output hashes at every pitch.
57
+ [First-call timings, output sizes, and reproduction commands](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md#generated-sheet-gyroid)
58
+
59
+ To run the gyroid demo from a checkout, install the CPU backend and run
60
+
61
+ ```console
62
+ python -m pip install ".[cpu]"
63
+ python benchmarks/benchmark_vvox.py --shape gyroid --extent 2 --pitch 0.015625 --prepared --backend cpu
64
+ ```
65
+
66
+ The script generates the mesh locally. Use `--pitch 0.0078125` or
67
+ `--pitch 0.00390625` for the finer grids. With the CUDA backend installed,
68
+ use `--backend cuda` to run the same cases on an NVIDIA GPU.
69
+
70
+ ## Installation
71
+
72
+ For CPU voxelization, install the Numba backend.
73
+
74
+ ```console
75
+ python -m pip install "vvox[cpu]"
76
+ ```
77
+
78
+ From a source checkout, use `python -m pip install ".[cpu]"` in the repository
79
+ root.
80
+
81
+ For an NVIDIA GPU on Windows or Linux with a CUDA 12-compatible driver, install
82
+ the CUDA backend on its own or alongside the CPU backend.
83
+
84
+ ```console
85
+ python -m pip install "vvox[cuda]" # CuPy CUDA backend
86
+ python -m pip install "vvox[cpu,cuda]" # both backends, auto prefers CUDA
87
+ ```
88
+
89
+ The base distribution can be imported on its own. Voxelization requires at
90
+ least one installed backend. With both installed, `backend="auto"` prefers
91
+ an available CUDA device. Set `backend="cpu"` or `backend="cuda"` to choose
92
+ explicitly.
93
+
94
+ If open or nonmanifold edges remain after standard cleanup, the optional
95
+ `repair` extra lets `vvox` try MeshFix. In a test with a cylinder missing
96
+ its top cap, MeshFix closed all 12 remaining boundary edges. To install
97
+ it alongside the CPU backend, run
98
+
99
+ ```console
100
+ python -m pip install "vvox[cpu,repair]"
101
+ ```
102
+
103
+ See the [MeshFix licensing and research citation terms](https://github.com/pyvista/pymeshfix/blob/main/README.rst#algorithm-and-citation-policy).
104
+
105
+ ## Python quick start
106
+
107
+ Voxelize a unit cube with four voxels along each edge.
108
+
109
+ ```python
110
+ import trimesh
111
+
112
+ from vvox import voxelize_mesh
113
+
114
+ result = voxelize_mesh(
115
+ trimesh.creation.box(),
116
+ pitch=0.25,
117
+ outputs=("dense", "sparse"),
118
+ backend="auto",
119
+ )
120
+
121
+ occupancy_xyz = result.to_numpy()
122
+ print(int(occupancy_xyz.sum())) # 64 occupied voxels
123
+ print(result.diagnostics.backend)
124
+ ```
125
+
126
+ To use your own part, replace `trimesh.creation.box()` with a path such as
127
+ `"part.3mf"` and set `pitch` in the mesh's length units. The result stays in
128
+ memory. Inspect `result.repair_report` for mesh cleanup and repairs, or
129
+ `result.diagnostics` for the backend, semantics version, and counts of columns
130
+ that needed extra precision. Call `vvox.io.write_result(...)` to save it.
131
+
132
+ ### Inspect a mesh repair
133
+
134
+ Removing one triangle from a box leaves three exposed edges. Built-in
135
+ cleanup closes this hole, and the report lets you check that the surface
136
+ is watertight before voxelization.
137
+
138
+ ```python
139
+ import trimesh
140
+ from vvox import prepare_mesh
141
+
142
+ box = trimesh.creation.box()
143
+ box.faces = box.faces[1:] # Remove one triangle.
144
+ prepared = prepare_mesh(box)
145
+ report = prepared.repair_report
146
+ print(report.initial.boundary_edge_count, report.final.boundary_edge_count) # 3 0
147
+ print(report.final.watertight) # True
148
+ ```
149
+
150
+ Pass `prepared` to `voxelize_mesh` to reuse the repaired surface. If the
151
+ final surface is still open or has inconsistent face winding, `prepare_mesh`
152
+ raises `InvalidMeshError` with the repair report attached.
153
+
154
+ ### A hollow shape on a fixed grid
155
+
156
+ Generate a torus and voxelize it on a caller-defined grid. Requesting sparse
157
+ output stores occupancy in active `8 × 8 × 8` bricks.
158
+
159
+ ```python
160
+ import trimesh
161
+
162
+ from vvox import voxelize_mesh_on_grid
163
+
164
+ ring = trimesh.creation.torus(
165
+ major_radius=0.875, minor_radius=0.125, major_sections=128, minor_sections=32
166
+ )
167
+ result = voxelize_mesh_on_grid(
168
+ ring,
169
+ shape_xyz=(128, 128, 128),
170
+ origin_xyz=(-1, -1, -1),
171
+ pitch=1 / 64,
172
+ outputs=("sparse",),
173
+ )
174
+ occupancy = result.to_numpy() # Expand the bricks to inspect individual voxels.
175
+ print(occupancy[64, 64, 64], occupancy[120, 64, 64]) # 0 in the hole, 1 in the tube
176
+ ```
177
+
178
+ On CPU, sparse-only voxelization builds the bricks directly from the occupied
179
+ intervals. On this grid the ring occupies 272 of 4,096 bricks. The sparse
180
+ arrays use 20,672 bytes, compared with 262,144 bytes for packed dense
181
+ occupancy. Supply the mesh and grid in the same coordinate frame and units.
182
+
183
+ In a separate benchmark at the same pitch, the 8,192-triangle torus took
184
+ 279 ms on CPU and 13.5 ms on CUDA on an auto-fit 130 × 130 × 18 grid
185
+ (five warm calls on the Ryzen 5 1600X and GTX 1070 Ti).
186
+ [Torus preview and timings](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md#generated-torus)
187
+
188
+ ## Command line
189
+
190
+ To use the torus above as a CLI input, run `ring.export("ring.3mf")` in the
191
+ same Python session. Then run the voxelizer from that directory.
192
+
193
+ ```console
194
+ vvox voxelize ring.3mf --pitch 0.015625 --backend auto --outputs dense,sparse --out-dir output
195
+ ```
196
+
197
+ To reproduce the fixed-grid sparse result from the Python example, run
198
+
199
+ ```console
200
+ vvox voxelize ring.3mf --pitch 0.015625 --shape-xyz 128 128 128 --origin-xyz -1 -1 -1 --outputs sparse --out-dir output-fixed
201
+ ```
202
+
203
+ The CLI prints a repair summary and writes the full report under `mesh_repair`
204
+ in `metadata.json`. It also writes the requested `dense.npz` and/or
205
+ `sparse_bricks.npz` files.
206
+
207
+ ## Documentation
208
+
209
+ - [Usage guide](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/usage.md): inputs, grids, backends, outputs, CUDA setup,
210
+ troubleshooting, and complete examples.
211
+ - [Design decisions](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/design.md): architectural choices, tradeoffs, and
212
+ their advantages.
213
+ - [Voxelization semantics](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/voxelization-semantics.md): the formal occupancy and
214
+ numerical-resolution contract.
215
+ - [Development guide](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/development.md): environment setup, repository
216
+ structure, testing, benchmarks, and release checks.
217
+ - [Benchmark snapshot](https://github.com/alvinccli/vvox/blob/v0.4.0/benchmarks/RESULTS.md): dated CPU/CUDA development
218
+ measurements.
219
+ - [Changelog](https://github.com/alvinccli/vvox/blob/v0.4.0/CHANGELOG.md): versioned user-facing changes and compatibility
220
+ notes.
221
+
222
+ ## Development
223
+
224
+ The checked-in environment installs the project editable with both backends and
225
+ development tools:
226
+
227
+ ```console
228
+ micromamba create -y -p ./.micromamba -f environment.yml
229
+ micromamba run -p ./.micromamba python -m pytest -q --basetemp .vvox-runtime/pytest-temp tests
230
+ ```
231
+
232
+ See the [development guide](https://github.com/alvinccli/vvox/blob/v0.4.0/docs/development.md) for the complete workflow.
233
+
234
+ ## License
235
+
236
+ `vvox` is distributed under the BSD 3-Clause License. See [LICENSE](https://github.com/alvinccli/vvox/blob/v0.4.0/LICENSE).