Skip to content

pycvc_gl: bind ViewportManager + Viewport — picture-in-picture from Python - #390

Merged
transfix merged 1 commit into
masterfrom
feat/pycvc-viewport-bindings
Sep 21, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/pycvc-viewport-bindings

Conversation

@transfix

Copy link
Copy Markdown
Owner

pycvc_gl: bind ViewportManager + Viewport — picture-in-picture from Python

Closes the largest gap the PiP work left: the whole ViewportManager/Viewport/
input-router surface (cvcGL #384/#386/#387) was C++-only, so volrover3 and
grl-snam — both Python — could not build multi-viewport or minimap layouts. This
wraps it, so the Python API mirrors C++:

vm = pycvc_gl.ViewportManager(scene, 1024, 768, False, "main")
inset = vm.addSceneViewport("inset", scene2, (0.62, 0.05, 0.97, 0.42), 1)
mini  = vm.addMirrorViewport("mini", "main", (0.62, 0.58, 0.97, 0.95), 2)
inset.camera().setMode(pycvc_gl.CameraController.Mode_Fly)  # per-viewport
vm.routeMouseButton(pycvc_gl.ViewportManager.MouseButton_Left, True, x, y)
vp = vm.viewportAt(x, y)          # None over the gutter
frame = vm.frameRGB()            # bytes

Binding details, following the existing pycvc_gl patterns:

  • frameRGB() -> bytes (a scoped typemap, like SceneRenderer's — the SceneRenderer
    one does not apply to ViewportManager).
  • region as a Python 4-sequence in (addSceneViewport/addMirrorViewport) and a
    4-tuple out (Viewport.region()), via in/argout typemaps.
  • Viewport has a private ctor -> %nodefaultctor; it is only ever handed out by
    the manager. renderer()/renderWindow()/mirrorSource() reuse the existing
    vtkRenderer*/vtkRenderWindow* -> live vtkmodules typemaps.
  • KEEPALIVE chain mirrors C++ ownership so a live child pins its parent: the
    manager keeps its scene(s); every handed-out Viewport (primary/viewport/
    viewportAt/activeViewport/add*Viewport) keeps the manager; a Viewport's
    camera() keeps the Viewport.
  • MouseButton enum -> ViewportManager.MouseButton_Left/Middle/Right.

New test_pycvc_gl_viewport.py exercises the surface end to end: auto primary,
addSceneViewport over a second scene + addMirrorViewport, viewportAt (layer/
visibility/inputEnabled/gutter), focus-follows-click into cvc::state, the
per-viewport camera (its state under the viewer tree), region tuples, and
frameRGB bytes — self-skipping without a GL driver, hard-exiting past cvcGL's
static-teardown race like the other pycvc_gl tests.

Validated locally by SWIG generation (all 24 ViewportManager + 15 Viewport
methods, the MouseButton enum, and both typemaps wrap cleanly); the compiled
.pyd + this test run in the cvcpkg pycvc-gl recipe, which builds against the
python-enabled VTK the module needs.

…ython

Closes the largest gap the PiP work left: the whole ViewportManager/Viewport/
input-router surface (cvcGL #384/#386/#387) was C++-only, so volrover3 and
grl-snam — both Python — could not build multi-viewport or minimap layouts. This
wraps it, so the Python API mirrors C++:

    vm = pycvc_gl.ViewportManager(scene, 1024, 768, False, "main")
    inset = vm.addSceneViewport("inset", scene2, (0.62, 0.05, 0.97, 0.42), 1)
    mini  = vm.addMirrorViewport("mini", "main", (0.62, 0.58, 0.97, 0.95), 2)
    inset.camera().setMode(pycvc_gl.CameraController.Mode_Fly)  # per-viewport
    vm.routeMouseButton(pycvc_gl.ViewportManager.MouseButton_Left, True, x, y)
    vp = vm.viewportAt(x, y)          # None over the gutter
    frame = vm.frameRGB()            # bytes

Binding details, following the existing pycvc_gl patterns:
  * frameRGB() -> bytes (a scoped typemap, like SceneRenderer's — the SceneRenderer
    one does not apply to ViewportManager).
  * region as a Python 4-sequence in (addSceneViewport/addMirrorViewport) and a
    4-tuple out (Viewport.region()), via in/argout typemaps.
  * Viewport has a private ctor -> %nodefaultctor; it is only ever handed out by
    the manager. renderer()/renderWindow()/mirrorSource() reuse the existing
    vtkRenderer*/vtkRenderWindow* -> live vtkmodules typemaps.
  * KEEPALIVE chain mirrors C++ ownership so a live child pins its parent: the
    manager keeps its scene(s); every handed-out Viewport (primary/viewport/
    viewportAt/activeViewport/add*Viewport) keeps the manager; a Viewport's
    camera() keeps the Viewport.
  * MouseButton enum -> ViewportManager.MouseButton_Left/Middle/Right.

New test_pycvc_gl_viewport.py exercises the surface end to end: auto primary,
addSceneViewport over a second scene + addMirrorViewport, viewportAt (layer/
visibility/inputEnabled/gutter), focus-follows-click into cvc::state, the
per-viewport camera (its state under the viewer tree), region tuples, and
frameRGB bytes — self-skipping without a GL driver, hard-exiting past cvcGL's
static-teardown race like the other pycvc_gl tests.

Validated locally by SWIG generation (all 24 ViewportManager + 15 Viewport
methods, the MouseButton enum, and both typemaps wrap cleanly); the compiled
.pyd + this test run in the cvcpkg pycvc-gl recipe, which builds against the
python-enabled VTK the module needs.
@transfix
transfix merged commit a3c1e2a into master Sep 21, 2026
13 checks passed
@transfix
transfix deleted the feat/pycvc-viewport-bindings branch September 21, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant