pilot: Add offscreen 2D world renderer and Python binding (issue #754 PR2)#900
Draft
tigercosmos wants to merge 2 commits into
Draft
pilot: Add offscreen 2D world renderer and Python binding (issue #754 PR2)#900tigercosmos wants to merge 2 commits into
tigercosmos wants to merge 2 commits into
Conversation
…PR1)
Move the body of R2DWidget::paintWorld into a free paint_world_2d routine in new RPainter2d.{hpp,cpp} so the on-screen widget and a future offscreen image renderer share one code path. Pure refactor; pixels unchanged.
…con#754 PR2) Add render_world_2d, a free routine that paints a World into an offscreen QImage through the PR1 paint_world_2d routine with no widget or event loop, and expose it to Python via wrap_pilot.cpp as pilot.render_world_2d (PNG bytes) and pilot.save_world_2d (to a file). Wire both through the _pilot_core bridge. Tests render a known world headless and check the PNG, size, that geometry changes pixels, determinism, and error paths.
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.
This builds on PR1's shared paint_world_2d routine to add an offscreen renderer that needs no widget and no running event loop, so a World can be turned into an image headlessly. The new C++ free function render_world_2d (in RPainter2d) fills the canvas background and draws the world geometry into a QImage; wrap_pilot.cpp exposes it to Python as pilot.render_world_2d, which returns PNG-encoded bytes, and pilot.save_world_2d, which writes a file whose format follows the filename suffix. Both raise ValueError on a None world or a non-positive size. This is the headless capture path the deterministic corpus and the PR3 pixel-test gate need, mirroring R3DWidget's saveImage/clipImage but for the strictly-2D widget.
This is PR2 of the issue-#754 stack and depends on PR1 (#899). Until PR1 merges to master, this PR's diff also includes PR1's commit (the paint_world_2d extraction); the relevant change here is the latest commit, "Add offscreen 2D world renderer and Python binding".
To use it, build a World, frame it with a 2D view transform, and ask for the image. The render functions paint with QPainter, so run them through the pilot binary, which provides the QApplication (plain python3 has none):
The tests in test_pilot_2d.py render a known world headless and assert the result is a valid PNG of the requested size, that a world with geometry does not encode identically to an empty one (something is actually painted), that output is byte-stable across runs, and that the None-world and non-positive-size error paths raise. The endpoint-to-pixel mapping assertions remain PR3's gate.
Related to #754.