MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ done()

SeriesSpec MayaFlux::Portal::Forma::Plot::FilledWaveformBuilder::done ( ) const

Definition at line 434 of file SeriesBuilder.cpp.

435{
436 auto x_mappings = m_state.x_mappings();
437 auto y_mappings = m_state.y_mappings();
438 const auto global_palette = m_state.palette();
439 const float baseline_data = m_baseline;
440
441 return {
442 .fn = [x_mappings, y_mappings, global_palette, baseline_data](
443 const std::shared_ptr<Kakshya::PlotContainer>& container,
444 std::vector<uint8_t>& out,
445 Element&) mutable {
446 if (!container)
447 return;
448
449 container->process_default();
450
451 struct SeriesEntry {
452 std::span<const double> data;
453 size_t mapping_index;
454 size_t index_within_mapping;
455 };
456 std::vector<SeriesEntry> y_entries;
457 for (size_t mi = 0; mi < y_mappings.size(); ++mi) {
458 auto sv = series_for_mapping(*container, y_mappings[mi]);
459 for (size_t si = 0; si < sv.size(); ++si)
460 y_entries.push_back({ .data = sv[si], .mapping_index = mi, .index_within_mapping = si });
461 }
462 if (y_entries.empty())
463 return;
464
465 AxisRange x_range = merge_axis(x_mappings);
466 AxisRange y_range = merge_axis(y_mappings);
467
468 std::vector<std::span<const double>> all_y;
469 all_y.reserve(y_entries.size());
470 for (const auto& e : y_entries)
471 all_y.push_back(e.data);
472 apply_auto_scale(y_range, all_y);
473
474 std::vector<std::span<const double>> all_x;
475 if (!x_mappings.empty()) {
476 all_x = series_for_mapping(*container, x_mappings[0]);
477 apply_auto_scale(x_range, all_x);
478 } else {
479 x_range = AxisRange {}.range(-1.F, 1.F);
480 }
481
482 const float baseline_ndc = y_range.to_ndc(baseline_data);
483
484 out.clear();
485
486 for (size_t ei = 0; ei < y_entries.size(); ++ei) {
487 const auto& entry = y_entries[ei];
488 const size_t n = entry.data.size();
489 if (n == 0)
490 continue;
491
492 const glm::vec3 color = resolve_color(
493 y_mappings[entry.mapping_index], global_palette, entry.index_within_mapping);
494
495 const size_t x_idx = std::min(ei, all_x.empty() ? size_t(0) : all_x.size() - 1);
496 const bool has_x = !all_x.empty() && all_x[x_idx].size() == n;
497
498 const size_t pre_size = out.size();
499
500 for (size_t i = 0; i < n; ++i) {
501 const float px = has_x
502 ? x_range.to_ndc(static_cast<float>(all_x[x_idx][i]))
503 : x_range.to_ndc(x_range.min
504 + static_cast<float>(i) / static_cast<float>(std::max<size_t>(n - 1, 1))
505 * (x_range.max - x_range.min));
506
507 const float py = y_range.to_ndc(static_cast<float>(entry.data[i]));
508
509 write_vertex(out, { px, py, 0.F }, color, 1.F);
510 write_vertex(out, { px, baseline_ndc, 0.F }, color, 0.F);
511 }
512
513 if (ei + 1 < y_entries.size() && out.size() > pre_size) {
514 const size_t last = out.size() - k_stride;
515 out.insert(out.end(), out.begin() + static_cast<ptrdiff_t>(last), out.end());
516 }
517 } },
519 .capacity_for = [](uint64_t n) { return n * 2 * k_stride + 128; },
520 .background_fn = m_state.has_background()
521 ? std::optional<GeometryFn<float>> { background(
523 : std::nullopt,
524 .plot_bounds = m_state.plot_bounds(),
525 .labels = m_state.labels(),
526 .tick_labels = m_state.resolved_tick_labels(),
527 .legend = m_state.legend_spec(),
528 };
529}
const std::vector< LabelSpec > & labels() const
std::vector< TickLabelsSpec > resolved_tick_labels() const
Resolve pending fluent tick requests into concrete tick label specs.
Kinesis::AABB2D background_bounds() const
const std::vector< AxisMapping > & x_mappings() const
const std::optional< LegendSpec > & legend_spec() const
const std::optional< Kinesis::AABB2D > & plot_bounds() const
const std::vector< glm::vec3 > & palette() const
const std::vector< AxisMapping > & y_mappings() const
void apply_auto_scale(AxisRange &range, const std::vector< std::span< const double > > &series)
Apply auto-scaling to an AxisRange from a set of series.
Definition PlotSpec.cpp:53
GeometryFn< float > background(Kinesis::AABB2D bounds, glm::vec3 color, const std::shared_ptr< Core::VKImage > &texture)
TRIANGLE_STRIP background quad for a plot area.
Definition PlotSpec.cpp:88

References MayaFlux::Portal::Forma::Plot::apply_auto_scale(), MayaFlux::Portal::Forma::Plot::background(), MayaFlux::Portal::Forma::Plot::Series::background_bounds(), MayaFlux::Portal::Forma::Plot::Series::background_color(), MayaFlux::Portal::Forma::Plot::Series::has_background(), MayaFlux::Portal::Forma::Plot::Series::labels(), MayaFlux::Portal::Forma::Plot::Series::legend_spec(), m_baseline, m_state, MayaFlux::Portal::Forma::Plot::AxisRange::max, MayaFlux::Portal::Forma::Plot::AxisRange::min, MayaFlux::Portal::Forma::Plot::Series::palette(), MayaFlux::Portal::Forma::Plot::Series::plot_bounds(), MayaFlux::Portal::Forma::Plot::AxisRange::range(), MayaFlux::Portal::Forma::Plot::Series::resolved_tick_labels(), MayaFlux::Portal::Forma::Plot::AxisRange::to_ndc(), MayaFlux::Portal::Graphics::TRIANGLE_STRIP, MayaFlux::Portal::Forma::Plot::Series::x_mappings(), and MayaFlux::Portal::Forma::Plot::Series::y_mappings().

+ Here is the call graph for this function: