MayaFlux 1.0.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 FormaTarget.
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 when
20 * the container pointer is stable but its data changes.
21 *
22 * Buffer construction and scheduling are the caller's responsibility.
23 * Create a batch with surface.render_config(), then pass a slice with
24 * spec.topology. Other plot geometry can use slices of that batch.
25 *
26 * @param surface Surface to register the element on.
27 * @param buf Target the series draws into, a slice of spec.topology.
28 * @param spec Result of a SeriesBuilder terminal. Carries the geometry
29 * function and input topology for this encoding.
30 * Raw GeometryFn callers are responsible for calling
31 * container->process_default() inside their function;
32 * SeriesBuilder terminals call it internally.
33 * @param container PlotContainer with series bound and marked ready for
34 * processing. Becomes the initial MappedState value.
35 * @return Fully constructed Mapped with element registered on the surface layer.
36 * Call sync() each frame to drive geometry updates.
37 */
38[[nodiscard]] MAYAFLUX_API
39 Mapped<std::shared_ptr<Kakshya::PlotContainer>>
40 place(
41 Surface& surface,
42 FormaTarget buf,
43 SeriesSpec spec,
44 std::shared_ptr<Kakshya::PlotContainer> container);
45
46/**
47 * @brief Place a text label element onto @p surface using a text-capable target.
48 *
49 * @p buf must have been created with an additional_textures slot named "text"
50 * (or equivalent). Buffer construction is the caller's responsibility;
51 * Portal::Forma::plot() handles this automatically.
52 *
53 * @param surface Target surface.
54 * @param buf TRIANGLE_LIST slice of a text-capable buffer. Labels may
55 * share that buffer.
56 * @param spec Label geometry and style.
57 * @param relate_to If non-zero, the produced element is related to this id.
58 * @return Element id of the produced label element.
59 */
60[[nodiscard]] MAYAFLUX_API uint32_t place_label(
61 Surface& surface,
62 FormaTarget buf,
63 const LabelSpec& spec,
64 uint32_t relate_to = 0);
65
66/**
67 * @brief Place a filled rectangle element onto @p surface using a target.
68 *
69 * @p buf should be a TRIANGLE_STRIP slice of the plot batch. A plot batch
70 * may also contain text slices. Buffer construction is the caller's responsibility.
71 *
72 * @param surface Target surface.
73 * @param buf Target for the four rectangle vertices.
74 * @param spec Rectangle geometry and color.
75 * @param relate_to If non-zero, the produced element is related to this id.
76 * @return Element id of the produced rect element.
77 */
78[[nodiscard]] MAYAFLUX_API uint32_t place_rect(
79 Surface& surface,
80 FormaTarget buf,
81 const RectSpec& spec,
82 uint32_t relate_to = 0);
83
84/**
85 * @brief Begin a Series chain.
86 *
87 * Convenience constructor for GeometryFn<shared_ptr<PlotContainer>>.
88 * Illustrative, not idiomatic. The raw GeometryFn lambda is always the
89 * primary path and is preferred when the builder cannot express what you need.
90 *
91 * @code
92 * // 7 SPATIAL_Y series -> 7 waveforms, blue palette
93 * auto geom = Plot::series()
94 * .y(Role::SPATIAL_Y, AxisRange{}.auto_scale(), { 0.2F, 0.8F, 1.0F })
95 * .as_waveform()
96 * .thickness(1.5F)
97 * .done();
98 *
99 * // Lissajous scatter, X and Y each with their own range
100 * auto geom = Plot::series()
101 * .x(Role::SPATIAL_X, AxisRange{}.range(-1.F, 1.F))
102 * .y(Role::SPATIAL_Y, AxisRange{}.range(-1.F, 1.F), { 0.9F, 0.3F, 0.8F })
103 * .as_scatter()
104 * .point_size(3.F)
105 * .done();
106 * @endcode
107 */
108[[nodiscard]] inline Series series()
109{
110 return Series {};
111}
112
113/**
114 * @brief Begin a Source chain.
115 *
116 * Constructs a PlotContainer incrementally via .as().from() pairs.
117 * The raw PlotContainer API remains available after .build() for cases
118 * the builder cannot express.
119 *
120 * @code
121 * auto container = Plot::source()
122 * .as("fm_sine", 512, Role::SPATIAL_Y, DataModality::AUDIO_1D).from(sine)
123 * .as("mod", 512, Role::SPATIAL_Y, DataModality::AUDIO_1D).from(mod)
124 * .build();
125 * @endcode
126 */
127[[nodiscard]] inline Source source()
128{
129 return Source {};
130}
131
132} // namespace MayaFlux::Portal::Forma::Plot
Convenience constructor for GeometryFn<shared_ptr<PlotContainer>>.
Chainable builder for PlotContainer construction.
Mapped< std::shared_ptr< Kakshya::PlotContainer > > place(Surface &surface, FormaTarget buf, SeriesSpec spec, std::shared_ptr< Kakshya::PlotContainer > container)
Place a plot element onto a Surface using a FormaTarget.
Definition Plot.cpp:96
Source source()
Begin a Source chain.
Definition Plot.hpp:127
uint32_t place_label(Surface &surface, FormaTarget buf, const LabelSpec &spec, uint32_t relate_to)
Place a text label element onto surface using a text-capable target.
Definition Plot.cpp:15
Series series()
Begin a Series chain.
Definition Plot.hpp:108
uint32_t place_rect(Surface &surface, FormaTarget buf, const RectSpec &spec, uint32_t relate_to)
Place a filled rectangle element onto surface using a target.
Definition Plot.cpp:68