Repository navigation
Conversation
… typemaps)
First cut of the pycvc SWIG module (Modernization Phase 13 design, G5 in
the 2026-07-15 near-term goals). New CVC_BUILD_PYTHON CMake option
(default OFF) builds a _pycvc extension from four hand-curated .i
fragments under src/pycvc/:
- app.i: hidden cvc::app module-context singleton (lazily constructed,
never exposed to Python)
- volume.i: dimension/bounding_box/voxels/volume with numpy conversion
(copy-in/copy-out, (Z,Y,X) C-order maps onto the libcvc voxel
layout so conversion is a flat memcpy); bilateralFilter/
anisotropicDiffusion/gdtvFilter wrapped via %extend so the
stale cached min/max is invalidated after in-place filtering
- ops.i: vol_normalize/scale/clip/clamp_min/mask/inverse_mask/
downsample/compute_stats
- sdf.i: minimal cvc::geometry (numpy mesh in/out) + sdf() gated on
CVC_ENABLE_SDF + generate_sphere/generate_cube
Deliberately not wrapped: GUI/Qt, state/state_exec/distributed state,
energy/docking, directors/callbacks, volume file I/O.
Verified: src/pycvc/tests/test_roundtrip.py (7 tests) passes against a
Release build — numpy float32 (32,32,8) round-trips exactly, bilateral
filter smooths (std 0.288 -> 0.037) with finite values, vol_normalize
stretches the filtered field to exactly [0,1], and a sphere mesh ->
16^3 SDF -> numpy round trip shows the inside/outside sign change.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First working cut of pycvc — the SWIG Python bindings the Modernization Plan Phase 13 designed but never built (zero
.ifiles existed until now). Scope is a deliberately minimal first wrap surface: enough to manufacture a smoothed risk field r̃ and a mesh→SDF→numpy φ from Python, nothing more.Base: branched from
30e079d(post-#101 master, before the volrover3 extraction landed).src/pycvc/is new and the two CMakeLists edits are one-liners, so it should rebase cleanly onto the lean-SDK master; happy to rebase in review if preferred.What's wrapped
One module
pycvc, four hand-curated.ifragments undersrc/pycvc/(no raw libcvc headers are%included — they are boost/CGAL-heavy and SWIG chokes on the template depth):app.i—cvc::appas a hidden, lazily-constructed module singleton. Python never sees a context; every wrapped op threads it through internally. (Deliberately leaked at shutdown to avoid static-destruction-order issues with the app's boost threads.)volume.i—dimension,bounding_box,voxels,volumewith numpy conversion; dims/spacing/bbox accessors,volume::interpolate,np.asarray(vol)/vol.shapesugar.pycvc.volume(np_array[, bbox])constructs from any 3D array.ops.i—vol_normalize,vol_scale,vol_clip,vol_clamp_min,vol_mask,vol_inverse_mask,vol_downsample,compute_stats.sdf.i— minimalcvc::geometry(numpy mesh in/out: points(N,3)float64, tris(M,3)uint64),generate_sphere/generate_cube, andsdf(geom, x, y, z[, bbox][, flip_normals])gated onCVC_ENABLE_SDFat both SWIG-time and compile-time (the gate is ON in our standard builds and pulls no extra deps, so no fragment had to be dropped — when a build disables SDF the function simply doesn't exist in the module).Smoothing:
voxels.bilateralFilter,anisotropicDiffusion,gdtvFilter— wrapped via%extendrather than declared directly, because the C++ filters readmin()/max()before filtering and never callunsetMinMax(), so a followingvol_normalizewould remap against stale pre-filter bounds (found while verifying; the binding invalidates the cache after each filter call, and the pipeline test locks the behavior in). Upstream fix to the filters themselves is a separate follow-up.Not wrapped (by design): GUI/Qt,
cvc::state/state_exec/distributed state, energy/docking, directors/callbacks, volume file I/O.NumPy strategy: copy-in / copy-out
A C-ordered
(Z, Y, X)array maps 1:1 onto the libcvc voxel layout (x fastest), so each direction is a single flatmemcpy:pycvc.volume(arr)copies in through the raw-pointervolumector;vol.to_numpy()/np.asarray(vol)copies out viaPyArray_SimpleNew. Hand-written helpers against the numpy C API — notnumpy.i(not shipped in numpy wheels) and not zero-copy. Zero-copy out (PyArray_SimpleNewFromData+PyArray_BASEholding the owning voxels alive) is the flagged next step; copies side-step the shared_array/copy-on-write lifetime hazards and are noise next to the filters this surface exists for. dtypes: uint8/16/32, float32/64 map to UChar/UShort/UInt/Float/Double; everything else force-casts to float32. 2D rasters are the degenerateZDim()==1case (arr[None]).Build integration
CVC_BUILD_PYTHON(default OFF) →src/pycvc/viaswig_add_library, linkingcvc::cvc+Python3::Module+Python3::NumPy; extension + proxy land in<build>/python/./usr/bin/swig4.0— the cvcpkg swig 4.4.1 recipe exists in libcvc-deps but isn't built into the local deps prefix yet;find_package(SWIG 4.0)will pick the prefix one up once it is), Python 3.12.3 + NumPy 2.5.1, the usualdeps/prefix (Boost 1.86, CGAL 6.0.1), Release, CUDA off.CVC_ENABLE_SDF/CVC_ENABLE_MESHERas-Don the.i), and the wrap compile inherits them from thecvctarget's PUBLIC definitions — the binding can't drift from the library build.Verification
src/pycvc/tests/test_roundtrip.py— 7/7 passed (Release build, 3.5s):(32,32,8)→volume→np.asarrayround-trips bit-exact, shape/dtype preservedbilateralFilter(200, 1.5, 2): values changed, all finite, std 0.288 → 0.037anisotropicDiffusion(5): changed, finite, smoothervol_normalize(v, 0, 1)→ exactly[0.0, 1.0], argmax preservedinterpolateat a grid point == array value[0,1](regression for the stale min/max fix)sdf16³ → numpy: finite, min −0.963 < 0 < max 1.616 (inside/outside sign change)Run:
PYTHONPATH=<build>/python python -m pytest src/pycvc/tests/test_roundtrip.py -vHonest gaps / next steps
Py_BEGIN_ALLOW_THREADSyet; single-threaded Python callers won't notice.ZDim()==1) filter behavior unvalidated — the 2D-raster path needs its own test before downstream code relies on it.CVC_BUILD_PYTHON=ONjob once the SWIG dep story lands in CI.python_sdistrecipe (recipes/pycvc, Phase-7 mechanism) so downstream Python packages import from the hermetic prefix; then volrover embedded-Python (G6) consumes the same module. Version lock-steppycvc == libcvc.unsetMinMax()fix + regression test (separate PR).