Repository navigation
pycvc/pycvc_gl: bind the LOD family (simplify, pyramids, select, tiles, store) + lod_city example - #511
Merged
Conversation
The LOD family (#483-#505) was C++-only, so Python apps and demos could not build, bake or reload pyramids. Wrap the real headers directly, as the rest of pycvc does: simplify / simplify_progressive / sampled_hausdorff, pyramid_params + the three pyramid builders, the selection math (view_params, quality presets, select_rung, the switch-radius crossovers, bound distance), tile partitioning + build_tiled_pyramids, and the scene.cvch5 store (scene_writer to bytes, scene_reader from a path, trusted bytes or open_verified, index / has / read / write / bake_mesh_asset), plus cvc::thread_pool and app.compute_pool() for the `pool` arguments. The long calls release the GIL with an RAII guard (exception-safe, unlike Py_BEGIN_ALLOW_THREADS), so a loader thread can bake a city while the main thread keeps drawing. Python callbacks (on_tile, group_key) reacquire it on whichever thread C++ runs them, and an exception they raise is carried through the pool and re-raised from the originating call with its type intact. Failures map to ValueError / IndexError / OSError (HDF5) / RuntimeError (SHA-256 mismatch) instead of a blanket RuntimeError. Out-parameters come back as return values and bytes cross as bytes. The store is wrapped only when config.h says HDF5 was built, so a no-HDF5 libcvc still binds (HAVE_LOD_STORE tells Python). The default %exception becomes a macro so this file can install its own mapping and restore the original afterwards. The budget solver is left out: a candidate points at caller-owned per-rung arrays a Python list cannot back safely.
Python could build pyramids but not draw them: wrap the real LodGraphicsNode (setPyramid, progressive setBase + appendRungs, select, setRung, the ladder accessors), SceneGraph.selectLOD / setLODEnabled / lod_stats, and cvc::gl::make_view_params, plus SceneGraph add_lod / add_child_lod / lod_node factories and SceneRenderer.make_view_params, which reads the live camera without a VTK object crossing into Python. setRungStyle takes a Python callable. Its exceptions are deferred and re-raised once the C++ call returns rather than thrown through LodGraphicsNode::addRung, which would orphan a half-built rung child. drawn_rungs() reports the rung ACTORS drawing, since a switch flips vtkProp visibility and never the rung nodes' own flags. examples/lod_city.py runs the whole pipeline on a synthetic city: partition, setBase at once, pyramids built on a loader thread with its own pool while the frame loop keeps selecting (appendRungs keeps rung 0), bake to bytes, open_verified reload, and a camera fly-out printing lod_stats per pose; --render draws each pose offscreen with rung tints. test_pycvc_gl_lod.py runs it headless and requires drawn triangles to drop at least 3x from the near pose to the far one.
…a time Review fixes for the LOD bindings: - tile.geom and tile.cell were %naturalvar members, whose getters return a non-owning pointer INTO the tile -- a use-after-free as soon as the tile proxy is collected (`partition_parts(...)[i].geom`, or keeping `t.geom` from an on_tile callback; valgrind reported invalid reads). They are now properties returning copies (cvc::geometry is copy-on-write, so the copy shares the tile's buffers). Regression test included. - simplify_progressive targets accept numpy integers (PyNumber_Index before PyLong_AsUnsignedLongLong), like the neighbouring typemaps. - to_blob copies into the new bytes object with the GIL released. - The GIL-release tests now time ONE C++ call per assertion, sized to take tens of ms, across the long calls (including the store readers, open_verified, partition_parts, bake_mesh_asset); the old multi-call closure could not fail.
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.
Python access to the LOD surface, so apps and demos can be written in Python.
pycvc
simplify/simplify_progressive, with out-params returned as values.build_mesh_pyramid,build_image_pyramidandbuild_volume_pyramid, pluspyramid_params.view_params, presets,select_rung,switch_radius_mand related helpers.partition_parts,partition_model,partition_components, andbuild_tiled_pyramidswith an optional Pythonon_tilecallback. The GIL is released during the build and reacquired for the callback.scene_writer(file or memory), withto_blob()returningbytes.scene_readeropens a path or (trusted) bytes, andscene_reader.open_verified(bytes, sha256)is the authenticated path. Also read/write,index,hasandbake_mesh_asset.pycvc_gl:
LodGraphicsNode(setPyramid,setBase/appendRungs,setRungStylewith a Python callable,select),SceneGraph.selectLOD/setLODEnabled/lod_stats, andmake_view_params.Example:
lod_citybuilds a synthetic tiled city, builds pyramids on the pool, bakes them to a blob, reloads it withopen_verified, attaches LOD nodes and flies a camera path, printinglod_stats. It runs headless as a test and asserts drawn triangles drop at least 3× far vs near.Review: one major was fixed.
tile.geom/tile.cellwere non-owning pointers into the tile (a use-after-free that valgrind flagged); they are now owned copies, with a regression test, and valgrind is clean. GIL tests now time one C++ call per assertion. Numpy integers are accepted forsimplify_progressivetargets.Known follow-ups (nits):
setRungStyleholds a strong reference to the callable, so a style closing over its own node forms a cycle; documented rather than solved.add_child_lodmaps a missing parent toRuntimeError, where the pycvc calls raiseValueError.Tests:
pycvc_lodandpycvc_gl_lodpass.