CorePlotting::SceneBuilder
CorePlotting::SceneBuilder
Helper class for constructing RenderableScene objects. More…
#include <SceneBuilder.hpp>
Public Functions
| Name | |
|---|---|
| SceneBuilder() =default | |
| SceneBuilder & | setBounds(BoundingBox const & bounds) Set world-space bounds for the scene (required for spatial indexing). |
| SceneBuilder & | setViewState(ViewState const & state) Set View and Projection matrices from ViewState. |
| SceneBuilder & | setMatrices(glm::mat4 const & view, glm::mat4 const & projection) Manually set View and Projection matrices. |
| SceneBuilder & | setSelectedEntities(std::unordered_set< EntityId > const & selected) Set the selection state for the scene. |
| SceneBuilder & | setSelectedEntities(std::unordered_set< EntityId > && selected) Set the selection state for the scene (move version). |
| template <MappedElementRange R> SceneBuilder & |
addGlyphs(std::string const & series_key, R && elements, GlyphStyle const & style ={}) Add glyphs from a range of mapped elements. |
| template <MappedRectRange R> SceneBuilder & |
addRectangles(std::string const & series_key, R && elements, RectangleStyle const & style ={}) Add rectangles from a range of mapped rect elements. |
| template <MappedVertexRange R> SceneBuilder & |
addPolyLine(std::string const & series_key, R && vertices, EntityId entity_id, PolyLineStyle const & style ={}) Add a single polyline from a range of vertices. |
| template <MappedLineRange R> SceneBuilder & |
addPolyLines(std::string const & series_key, R && lines, PolyLineStyle const & style ={}) Add multiple polylines from a range of line views. |
| SceneBuilder & | addPolyLineBatch(RenderablePolyLineBatch const & batch) Add a polyline batch to the scene. |
| SceneBuilder & | addPolyLineBatch(RenderablePolyLineBatch && batch) Add a polyline batch to the scene (move version). |
| SceneBuilder & | addGlyphBatch(RenderableGlyphBatch const & batch) Add a glyph batch to the scene. |
| SceneBuilder & | addGlyphBatch(RenderableGlyphBatch && batch) Add a glyph batch to the scene (move version). |
| SceneBuilder & | addRectangleBatch(RenderableRectangleBatch const & batch) Add a rectangle batch to the scene. |
| SceneBuilder & | addRectangleBatch(RenderableRectangleBatch && batch) Add a rectangle batch to the scene (move version). |
| SceneBuilder & | buildSpatialIndex(BoundingBox const & bounds) Manually build spatial index from all batches. |
| RenderableScene | build() Finalize and return the constructed scene. |
| void | reset() Reset builder to empty state. |
| std::map< size_t, std::string > const & | getRectangleBatchKeyMap() const Get mapping from batch index to series key. |
| std::map< size_t, std::string > const & | getGlyphBatchKeyMap() const Get mapping from glyph batch index to series key. |
Detailed Description
class CorePlotting::SceneBuilder;Helper class for constructing RenderableScene objects.
Provides a fluent interface for building scenes incrementally:
- Set bounds (required for spatial indexing of discrete elements)
- Add mapped elements using range-based API:
- addGlyphs() for discrete points/events
- addRectangles() for intervals
- addPolyLine()/addPolyLines() for continuous data
- Optionally set View/Projection matrices
- Call build() to finalize the scene
Example usage with TimeSeriesMapper: ```cpp
using namespace CorePlotting;
RenderableScene scene = SceneBuilder() .setBounds(bounds) .setViewState(view_state) .addGlyphs(“trial1”, TimeSeriesMapper::mapEvents(events1, layout1, tf)) .addGlyphs(“trial2”, TimeSeriesMapper::mapEvents(events2, layout2, tf)) .addRectangles(“intervals”, TimeSeriesMapper::mapIntervals(intervals, layout, tf)) .build();
The builder creates both rendering geometry AND spatial index from the same position data, ensuring they remain synchronized.
## Public Functions Documentation
### function SceneBuilder
```cpp
SceneBuilder() =default
function setBounds
SceneBuilder & setBounds(
BoundingBox const & bounds
)Set world-space bounds for the scene (required for spatial indexing).
Parameters:
- bounds World-space bounding box
Return: Reference to this builder for chaining
Must be called before adding any series. The bounds define the QuadTree coverage area for hit testing.
function setViewState
SceneBuilder & setViewState(
ViewState const & state
)Set View and Projection matrices from ViewState.
Parameters:
- state Current camera/viewport state
Return: Reference to this builder for chaining
function setMatrices
SceneBuilder & setMatrices(
glm::mat4 const & view,
glm::mat4 const & projection
)Manually set View and Projection matrices.
Parameters:
- view View matrix
- projection Projection matrix
Return: Reference to this builder for chaining
function setSelectedEntities
SceneBuilder & setSelectedEntities(
std::unordered_set< EntityId > const & selected
)Set the selection state for the scene.
Parameters:
- selected Set of selected EntityIds
Return: Reference to this builder for chaining
Selected EntityIds will be stored in the scene and used to populate selection_flags in rectangle batches during build().
function setSelectedEntities
SceneBuilder & setSelectedEntities(
std::unordered_set< EntityId > && selected
)Set the selection state for the scene (move version).
Parameters:
- selected Set of selected EntityIds (will be moved)
Return: Reference to this builder for chaining
function addGlyphs
template <MappedElementRange R>
SceneBuilder & addGlyphs(
std::string const & series_key,
R && elements,
GlyphStyle const & style ={}
)Add glyphs from a range of mapped elements.
Parameters:
- series_key Unique identifier for this series (for hit test results)
- elements Range of MappedElement (x, y, entity_id)
- style Optional styling (glyph type, size, color, model matrix)
Template Parameters:
- R Range type satisfying [MappedElementRange] concept
Return: Reference to this builder for chaining
Creates a glyph batch for rendering AND inserts into spatial index. Single traversal: positions go to both GPU buffer and QuadTree.
function addRectangles
template <MappedRectRange R>
SceneBuilder & addRectangles(
std::string const & series_key,
R && elements,
RectangleStyle const & style ={}
)Add rectangles from a range of mapped rect elements.
Parameters:
- series_key Unique identifier for this series
- elements Range of MappedRectElement (x, y, width, height, entity_id)
- style Optional styling (color, model matrix)
Template Parameters:
- R Range type satisfying [MappedRectRange] concept
Return: Reference to this builder for chaining
Creates a rectangle batch for rendering AND inserts centers into spatial index.
function addPolyLine
template <MappedVertexRange R>
SceneBuilder & addPolyLine(
std::string const & series_key,
R && vertices,
EntityId entity_id,
PolyLineStyle const & style ={}
)Add a single polyline from a range of vertices.
Parameters:
- series_key Unique identifier for this series
- vertices Range of MappedVertex (x, y)
- entity_id EntityId for the entire line
- style Optional styling (thickness, color, model matrix)
Template Parameters:
- R Range type satisfying [MappedVertexRange] concept
Return: Reference to this builder for chaining
Creates a polyline batch for a single continuous line. Does NOT add to spatial index (polylines typically use compute shader hit testing).
function addPolyLines
template <MappedLineRange R>
SceneBuilder & addPolyLines(
std::string const & series_key,
R && lines,
PolyLineStyle const & style ={}
)Add multiple polylines from a range of line views.
Parameters:
- series_key Unique identifier for this series
- lines Range of MappedLineView (entity_id + vertices)
- style Optional styling (thickness, color, model matrix)
Template Parameters:
- R Range type satisfying [MappedLineRange] concept
Return: Reference to this builder for chaining
Creates a polyline batch with multiple lines. Each line view provides its own entity_id and vertex range.
function addPolyLineBatch
SceneBuilder & addPolyLineBatch(
RenderablePolyLineBatch const & batch
)Add a polyline batch to the scene.
Parameters:
- batch Batch to add (will be copied)
Return: Reference to this builder for chaining
function addPolyLineBatch
SceneBuilder & addPolyLineBatch(
RenderablePolyLineBatch && batch
)Add a polyline batch to the scene (move version).
Parameters:
- batch Batch to add (will be moved)
Return: Reference to this builder for chaining
function addGlyphBatch
SceneBuilder & addGlyphBatch(
RenderableGlyphBatch const & batch
)Add a glyph batch to the scene.
Parameters:
- batch Batch to add (will be copied)
Return: Reference to this builder for chaining
function addGlyphBatch
SceneBuilder & addGlyphBatch(
RenderableGlyphBatch && batch
)Add a glyph batch to the scene (move version).
Parameters:
- batch Batch to add (will be moved)
Return: Reference to this builder for chaining
function addRectangleBatch
SceneBuilder & addRectangleBatch(
RenderableRectangleBatch const & batch
)Add a rectangle batch to the scene.
Parameters:
- batch Batch to add (will be copied)
Return: Reference to this builder for chaining
function addRectangleBatch
SceneBuilder & addRectangleBatch(
RenderableRectangleBatch && batch
)Add a rectangle batch to the scene (move version).
Parameters:
- batch Batch to add (will be moved)
Return: Reference to this builder for chaining
function buildSpatialIndex
SceneBuilder & buildSpatialIndex(
BoundingBox const & bounds
)Manually build spatial index from all batches.
Parameters:
- bounds World-space bounds for the QuadTree
Return: Reference to this builder for chaining
Note: For new code, prefer addGlyphs/addRectangles which populate the spatial index automatically. This method is for custom geometry.
function build
RenderableScene build()Finalize and return the constructed scene.
Exceptions:
- std::runtime_error if discrete elements added without bounds
Return: Complete RenderableScene ready for rendering
Creates spatial index if bounds were set and discrete elements were added.
function reset
void reset()Reset builder to empty state.
Clears all batches, spatial index data, and matrices. Called automatically by build().
function getRectangleBatchKeyMap
inline std::map< size_t, std::string > const & getRectangleBatchKeyMap() constGet mapping from batch index to series key.
Useful for SceneHitTester::queryIntervals which needs to map batch indices back to series identifiers.
function getGlyphBatchKeyMap
inline std::map< size_t, std::string > const & getGlyphBatchKeyMap() constGet mapping from glyph batch index to series key.
Updated on 2026-11-13 at 20:25:42 +0000