MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SpatialRegionProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @class SpatialRegionProcessor
9 * @brief Parallel spatial extraction processor for image-modality containers.
10 *
11 * Operates on any SignalSourceContainer whose structure carries at least one
12 * spatial dimension (SPATIAL_Y, SPATIAL_X, or SPATIAL_Z). Unlike
13 * RegionOrganizationProcessor — which advances a sequential temporal cursor
14 * through audio regions — this processor extracts *all* active regions on
15 * every process() call, reflecting the parallel readback semantics of spatial
16 * data.
17 *
18 * Region source:
19 * Regions are read from the container's RegionGroup map
20 * (get_all_region_groups()). Each Region inside each group becomes one
21 * OrganizedRegion in m_organized_regions, inheriting both group-level and
22 * region-level attributes. organize_container_data() re-syncs this list
23 * from the live group map, so callers can mutate groups between frames by
24 * calling refresh().
25 *
26 * Processing contract (process()):
27 * - Expects processed_data[0] to hold the full-surface readback as a
28 * std::vector<uint8_t> placed there by the default processor
29 * (e.g. WindowAccessProcessor) before the chain runs.
30 * - Replaces processed_data with one DataVariant per active region,
31 * in group-iteration order, then region-insertion order within each group.
32 * - Each DataVariant carries the attributes from its OrganizedRegion so
33 * downstream consumers can identify the source ("group_name", "region_index").
34 * - If processed_data[0] is absent or empty, state is set to IDLE and the
35 * method returns without modifying processed_data.
36 *
37 * Caching:
38 * Auto-caching is disabled by default. Spatial data from a live surface
39 * changes every frame, so caching individual regions yields no benefit
40 * under normal operation. It can be re-enabled via set_auto_caching(true)
41 * for static or infrequently-updated surfaces (e.g. a paused framebuffer).
42 *
43 * Container neutrality:
44 * No WindowContainer-specific code. Any container that satisfies the
45 * NDDimensionalContainer interface and populates processed_data[0] with a
46 * flat spatial buffer is compatible.
47 */
48class MAYAFLUX_API SpatialRegionProcessor : public RegionProcessorBase {
49public:
51 ~SpatialRegionProcessor() override = default;
52
53 /**
54 * @brief Attach to a spatial container.
55 * Validates that the container has at least one spatial dimension.
56 * Disables auto-caching (appropriate for live surfaces).
57 * Delegates to RegionProcessorBase::on_attach which calls
58 * organize_container_data().
59 * @throws std::invalid_argument if no spatial dimension is found.
60 */
61 void on_attach(const std::shared_ptr<SignalSourceContainer>& container) override;
62
63 /**
64 * @brief Detach; delegates to RegionProcessorBase::on_detach.
65 */
66 void on_detach(const std::shared_ptr<SignalSourceContainer>& container) override;
67
68 /**
69 * @brief Extract all active regions from processed_data[0] in parallel.
70 *
71 * For each OrganizedRegion in m_organized_regions, extracts pixel
72 * data via extract_nd_region and appends to processed_data.
73 * Sets OrganizedRegion::state to ACTIVE during extraction and
74 * PROCESSED on completion. Failed extractions are logged and
75 * skipped without aborting the frame.
76 *
77 * @param container Source container; processed_data[0] must hold the
78 * full-surface buffer.
79 */
80 void process(const std::shared_ptr<SignalSourceContainer>& container) override;
81
82 /**
83 * @brief Re-sync m_organized_regions from the container's current group map.
84 * Call after mutating region groups between frames.
85 */
86 void refresh();
87
88protected:
89 /**
90 * @brief Build m_organized_regions from get_all_region_groups().
91 * Each Region in each RegionGroup becomes one OrganizedRegion whose
92 * attributes include "group_name" (std::string) and "region_index"
93 * (size_t) for downstream identification.
94 */
95 void organize_container_data(
96 const std::shared_ptr<SignalSourceContainer>& container) override;
97};
98
99} // namespace MayaFlux::Kakshya
Base class for N-dimensional region processors.
Parallel spatial extraction processor for image-modality containers.