PlottingSVG::SVGSceneRenderer
PlottingSVG::SVGSceneRenderer
Orchestrates [SVGDocument](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md) assembly, per-batch SVG renderers, and optional decorations. More…
#include <SVGSceneRenderer.hpp>
Public Functions
| Name | |
|---|---|
| SVGSceneRenderer() Construct a renderer with default canvas size (1920×1080), white background, and no scene. |
|
| void | setScene(CorePlotting::RenderableScene const & scene) Bind the scene whose batches and view/projection matrices are exported on [render()](). |
| void | setCanvasSize(int width, int height) Set the pixel width and height used for the root <svg>, viewBox, and all renderers. |
| void | setBackgroundColor(std::string const & hex_color) Set the full-canvas background fill passed to [SVGDocument::setBackground](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-setbackground). |
| void | addDecoration(std::unique_ptr< SVGDecoration > decoration) Take ownership of a decoration drawn after scene batches (merged into layer decorations). |
| void | clearDecorations() Remove and destroy all decorations previously added. |
| std::string | render() const Build the full SVG document for the current state. |
| bool | renderToFile(std::filesystem::path const & path) const Write [render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render) to path as UTF-8 bytes (std::ios::binary). |
Detailed Description
class PlottingSVG::SVGSceneRenderer;Orchestrates [SVGDocument](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md) assembly, per-batch SVG renderers, and optional decorations.
Scene geometry is grouped into fixed layer ids: rectangles, polylines, and glyphs (batches are appended in scene vector order within each layer). Non-empty decoration output is added as layer decorations. If no scene is set, or the scene pointer is null at [render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render) time, the document still contains the default [SVGDocument](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md) metadata and background, with no scene geometry layers.
Public Functions Documentation
function SVGSceneRenderer
SVGSceneRenderer()Construct a renderer with default canvas size (1920×1080), white background, and no scene.
function setScene
void setScene(
CorePlotting::RenderableScene const & scene
)Bind the scene whose batches and view/projection matrices are exported on [render()]().
Precondition:
scenemust remain valid (not destroyed) for every subsequent call to[render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render)or[renderToFile()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-rendertofile)while this pointer is still stored (enforcement: none) [CRITICAL]scene.view_matrixandscene.projection_matrixshould reflect the intended camera transform (enforcement: none — identity produces valid but usually incorrect output) [IMPORTANT]
The renderer reads scene.view_matrix and scene.projection_matrix at [render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render) time to compute the final MVP (projection * view * batch.model_matrix) for every batch. Callers must ensure these matrices reflect the desired camera state before calling [render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render). The RenderableScene defaults are identity, which maps world coordinates directly to NDC — this is almost never the correct camera for a plot widget. Typically the caller copies the same view/projection matrices used by the live OpenGL renderer onto the scene before exporting.
function setCanvasSize
void setCanvasSize(
int width,
int height
)Set the pixel width and height used for the root <svg>, viewBox, and all renderers.
Precondition: width > 0 and height > 0 for a conventional canvas and correct NDC→pixel mapping in batch renderers (enforcement: none) [IMPORTANT]
function setBackgroundColor
void setBackgroundColor(
std::string const & hex_color
)Set the full-canvas background fill passed to [SVGDocument::setBackground](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-setbackground).
Precondition: hex_color must be safe inside a double-quoted XML attribute (see [SVGDocument::setBackground](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-setbackground)) (enforcement: none) [IMPORTANT]
function addDecoration
void addDecoration(
std::unique_ptr< SVGDecoration > decoration
)Take ownership of a decoration drawn after scene batches (merged into layer decorations).
Note: [nullptr] is ignored; no layer entry is added for skipped decorations.
function clearDecorations
void clearDecorations()Remove and destroy all decorations previously added.
function render
std::string render() constBuild the full SVG document for the current state.
Precondition:
- If
[setScene](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-setscene)was called, the referencedRenderableScenemust still be alive when[render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render)runs (see[setScene](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-setscene)). - Batch contents must satisfy the preconditions of
[SVGRectangleRenderer](/api_generated/Classes/classPlottingSVG_1_1SVGRectangleRenderer.md),[SVGPolyLineRenderer](/api_generated/Classes/classPlottingSVG_1_1SVGPolyLineRenderer.md), and[SVGGlyphRenderer](/api_generated/Classes/classPlottingSVG_1_1SVGGlyphRenderer.md)(enforcement: none) [LOW] - Each decoration’s
[render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render)must return safe SVG fragments for[SVGDocument::addElements](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-addelements)(enforcement: none) [LOW]
Postcondition:
- Returns
[SVGDocument::build()](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-build)after configuring background, optional scene layers, and optionaldecorationslayer (only when decoration output is non-empty). - Does not throw under normal
[SVGDocument](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md)and string behavior.
function renderToFile
bool renderToFile(
std::filesystem::path const & path
) constWrite [render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render) to path as UTF-8 bytes (std::ios::binary).
Precondition: path must be openable for output by this process (parent directory exists, permissions, etc.) (enforcement: runtime_check — returns false on failure) [IMPORTANT]
Postcondition: Returns true if the stream was good after writing the full [render()](/api_generated/Classes/classPlottingSVG_1_1SVGSceneRenderer.md#function-render) result; otherwise false (including when the file could not be opened).
Updated on 2026-11-13 at 20:25:41 +0000