MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Plot.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "PlotSource.hpp"
4#include "PlotSpec.hpp"
5#include "SeriesBuilder.hpp"
6
8class Surface;
9}
10
12
13/**
14 * @brief Place a plot element onto a Surface using a pre-built FormaBuffer.
15 *
16 * Constructs a Mapped<shared_ptr<PlotContainer>> from the geometry function
17 * carried by @p spec, registers the element on @p surface's layer, and runs
18 * one initial sync so the first frame has valid geometry. Sets
19 * force_redraw_on_sync so geometry regenerates on every sync() call
20 * the container pointer is stable across frames but its data changes each frame.
21 *
22 * Buffer construction and scheduling are the caller's responsibility.
23 * Use Portal::Forma::create_buffer(surface.window(), spec.capacity_for(N),
24 * spec.topology) to build the buffer, and schedule_metro to drive sync()
25 * at the desired rate.
26 *
27 * @param surface Surface to register the element on.
28 * @param buf Pre-built, registered FormaBuffer sized for this encoding.
29 * Use spec.capacity_for(N) and spec.topology to construct it.
30 * @param spec Result of a SeriesBuilder terminal. Carries the geometry
31 * function, topology, and capacity arithmetic for this encoding.
32 * Raw GeometryFn callers are responsible for calling
33 * container->process_default() inside their function;
34 * SeriesBuilder terminals call it internally.
35 * @param container PlotContainer with series bound and marked ready for
36 * processing. Becomes the initial MappedState value.
37 * @return Fully constructed Mapped with element registered on the surface layer.
38 * Call sync() each frame to drive geometry updates.
39 */
40[[nodiscard]] MAYAFLUX_API
41 Mapped<std::shared_ptr<Kakshya::PlotContainer>>
42 place(
43 Surface& surface,
44 std::shared_ptr<Buffers::FormaBuffer> buf,
45 SeriesSpec spec,
46 std::shared_ptr<Kakshya::PlotContainer> container);
47
48/**
49 * @brief Place a text label element onto @p surface using a pre-built buffer.
50 *
51 * @p buf must have been created with an additional_textures slot named "text"
52 * (or equivalent). Buffer construction is the caller's responsibility;
53 * Portal::Forma::plot() handles this automatically.
54 *
55 * @param surface Target surface.
56 * @param buf FormaBuffer with a texture slot. One buffer per label.
57 * @param spec Label geometry and style.
58 * @param relate_to If non-zero, the produced element is related to this id.
59 * @return Element id of the produced label element.
60 */
61[[nodiscard]] MAYAFLUX_API uint32_t place_label(
62 Surface& surface,
63 std::shared_ptr<Buffers::FormaBuffer> buf,
64 const LabelSpec& spec,
65 uint32_t relate_to = 0);
66
67/**
68 * @brief Place a filled rectangle element onto @p surface using a pre-built buffer.
69 *
70 * @p buf must be a plain TRIANGLE_STRIP FormaBuffer with no texture slot.
71 * Buffer construction is the caller's responsibility.
72 *
73 * @param surface Target surface.
74 * @param buf FormaBuffer sized for 4 vertices.
75 * @param spec Rectangle geometry and color.
76 * @param relate_to If non-zero, the produced element is related to this id.
77 * @return Element id of the produced rect element.
78 */
79[[nodiscard]] MAYAFLUX_API uint32_t place_rect(
80 Surface& surface,
81 std::shared_ptr<Buffers::FormaBuffer> buf,
82 const RectSpec& spec,
83 uint32_t relate_to = 0);
84
85/**
86 * @brief Begin a Series chain.
87 *
88 * Convenience constructor for GeometryFn<shared_ptr<PlotContainer>>.
89 * Illustrative, not idiomatic. The raw GeometryFn lambda is always the
90 * primary path and is preferred when the builder cannot express what you need.
91 *
92 * @code
93 * // 7 SPATIAL_Y series -> 7 waveforms, blue palette
94 * auto geom = Plot::series()
95 * .y(Role::SPATIAL_Y, AxisRange{}.auto_scale(), { 0.2F, 0.8F, 1.0F })
96 * .as_waveform()
97 * .thickness(1.5F)
98 * .done();
99 *
100 * // Lissajous scatter, X and Y each with their own range
101 * auto geom = Plot::series()
102 * .x(Role::SPATIAL_X, AxisRange{}.range(-1.F, 1.F))
103 * .y(Role::SPATIAL_Y, AxisRange{}.range(-1.F, 1.F), { 0.9F, 0.3F, 0.8F })
104 * .as_scatter()
105 * .point_size(3.F)
106 * .done();
107 * @endcode
108 */
109[[nodiscard]] inline Series series()
110{
111 return Series {};
112}
113
114/**
115 * @brief Begin a Source chain.
116 *
117 * Constructs a PlotContainer incrementally via .as().from() pairs.
118 * The raw PlotContainer API remains available after .build() for cases
119 * the builder cannot express.
120 *
121 * @code
122 * auto container = Plot::source()
123 * .as("fm_sine", 512, Role::SPATIAL_Y, DataModality::AUDIO_1D).from(sine)
124 * .as("mod", 512, Role::SPATIAL_Y, DataModality::AUDIO_1D).from(mod)
125 * .build();
126 * @endcode
127 */
128[[nodiscard]] inline Source source()
129{
130 return Source {};
131}
132
133} // namespace MayaFlux::Portal::Forma::Plot
Convenience constructor for GeometryFn<shared_ptr<PlotContainer>>.
Chainable builder for PlotContainer construction.
Source source()
Begin a Source chain.
Definition Plot.hpp:128
Series series()
Begin a Series chain.
Definition Plot.hpp:109
uint32_t place_label(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, const LabelSpec &spec, uint32_t relate_to)
Place a text label element onto surface using a pre-built buffer.
Definition Plot.cpp:15
Mapped< std::shared_ptr< Kakshya::PlotContainer > > place(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, SeriesSpec spec, std::shared_ptr< Kakshya::PlotContainer > container)
Place a plot element onto a Surface using a pre-built FormaBuffer.
Definition Plot.cpp:81
uint32_t place_rect(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, const RectSpec &spec, uint32_t relate_to)
Place a filled rectangle element onto surface using a pre-built buffer.
Definition Plot.cpp:53