MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
RegionUtils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "CoordUtils.hpp"
4
7
8namespace MayaFlux::Kakshya {
9
10/** @brief Remove the channel dimension from a Region.
11 * @param region The original Region.
12 * @param dimensions Dimension descriptors to identify the channel dimension.
13 * @return New Region without the channel dimension.
14 *
15 * This function identifies the channel dimension based on the provided dimension descriptors
16 * and removes it from the region's start and end coordinates.
17 *
18 * This is useful for operations that need to ignore the channel dimension, such as spatial-only processing
19 * or planar data handling.
20 */
21Region remove_channel_dimension(const Region& region, const std::vector<DataDimension>& dimensions);
22
23/**
24@brief Get all non-channel dimensions from a list of dimensions.
25 * @param dimensions Vector of DataDimension descriptors.
26 * @return Vector of DataDimensions excluding the channel dimension.
27 *
28 * This function filters out the dimension marked as 'channel' from the provided list of dimensions.
29 * It is useful for operations that need to focus on spatial or temporal dimensions only.
30 */
31std::vector<DataDimension> get_non_channel_dimensions(const std::vector<DataDimension>& dimensions);
32
33/** @brief Flatten a vector of channel data into a single vector.
34 * @tparam T Data type.
35 * @param channel_data Vector of vectors, each representing a channel's data.
36 * @return Single flattened vector containing all channel data in sequence.
37 *
38 * This function concatenates the data from multiple channels into a single continuous vector.
39 * It is useful for operations that require planar data to be processed as a single array.
40 */
41template <typename T>
42std::vector<T> flatten_channels(const std::vector<std::vector<T>>& channel_data)
43{
44 std::vector<T> result;
45 size_t total_size = 0;
46 for (const auto& channel : channel_data) {
47 total_size += channel.size();
48 }
49 result.reserve(total_size);
50
51 for (const auto& channel : channel_data) {
52 result.insert(result.end(), channel.begin(), channel.end());
53 }
54 return result;
55}
56
57/**
58 * @brief Extract a region of data from a flat data span using a Region and dimension info.
59 * @tparam T Data type.
60 * @param source_data Source data span.
61 * @param region Region to extract.
62 * @param dimensions Dimension descriptors.
63 * @return Vector containing the extracted region data.
64 * @throws std::out_of_range if region is out of bounds.
65 */
66template <typename T>
67std::vector<T> extract_region_data(const std::span<const T>& source_data, const Region& region, const std::vector<DataDimension>& dimensions)
68{
69 for (size_t i = 0; i < region.start_coordinates.size(); ++i) {
70 if (region.end_coordinates[i] > 0 && (region.end_coordinates[i] >= dimensions[i].size)) {
71 throw std::out_of_range("Requested region is out of bounds for dimension " + std::to_string(i));
72 }
73 }
74
75 uint64_t region_size = region.get_volume();
76 std::vector<T> result;
77 result.reserve(region_size);
78
79 std::vector<uint64_t> current = region.start_coordinates;
80 while (true) {
81 uint64_t linear_index = coordinates_to_linear(current, dimensions);
82 result.push_back(source_data[linear_index]);
83
84 bool done = true;
85 for (int dim = current.size() - 1; dim >= 0; --dim) {
86 if (current[dim] < region.end_coordinates[dim]) {
87 current[dim]++;
88 done = false;
89 break;
90 }
91 current[dim] = region.start_coordinates[dim];
92 }
93 if (done)
94 break;
95 }
96 return result;
97}
98
99/**
100 * @brief Extract region data from planar storage (separate per channel/variant)
101 * @tparam T Data type
102 * @param source_variants Vector of data spans (one per channel/variant)
103 * @param region Region to extract
104 * @param dimensions Dimension descriptors
105 * @param flatten If true, return single flattened vector; if false, return per-channel vectors
106 * @return Vector of vectors (per-channel) or single flattened vector
107 */
108template <typename T>
109std::vector<std::vector<T>> extract_region_data(
110 const std::vector<std::span<const T>>& source_data,
111 const Region& region,
112 const std::vector<DataDimension>& dimensions,
113 bool flatten = false)
114{
115 std::vector<std::vector<T>> results;
116
117 for (size_t idx = 0; idx < source_data.size(); ++idx) {
118
119 Region channel_region = remove_channel_dimension(region, dimensions);
120
121 auto channel_data = extract_region_data(
122 source_data[idx],
123 channel_region,
124 get_non_channel_dimensions(dimensions));
125
126 results.push_back(std::move(channel_data));
127 }
128
129 if (flatten) {
130 return { flatten_channels(results) };
131 }
132
133 return results;
134}
135
136/**
137 * @brief Extract data for multiple regions from multi-channel source data.
138 * @tparam T Data type.
139 * @param source_spans Vector of source data spans (one per channel).
140 * @param group Group of regions to extract.
141 * @param dimensions Dimension descriptors.
142 * @param organization Storage organization strategy.
143 * @return Vector of vectors, each containing extracted data for one region.
144 */
145template <typename T>
146std::vector<std::vector<T>> extract_group_data(
147 const std::vector<std::span<const T>>& source_spans,
148 const RegionGroup& group,
149 const std::vector<DataDimension>& dimensions,
150 OrganizationStrategy organization)
151{
152 std::vector<std::vector<T>> result;
153 result.reserve(group.regions.size());
154
155 for (const auto& region : group.regions) {
156 auto region_data = extract_region_data<T>(source_spans, region, dimensions, organization);
157
158 if (organization == OrganizationStrategy::INTERLEAVED) {
159 if (result.empty())
160 result.resize(1);
161
162 for (size_t i = 0; i < region_data[0].size(); i++) {
163 result[0].push_back(region_data[0][i]);
164 }
165 } else {
166 if (result.empty())
167 result.resize(region_data.size());
168
169 auto channel_pairs = std::views::zip(result, region_data);
170 auto total_sizes = channel_pairs | std::views::transform([](auto&& pair) {
171 return std::get<0>(pair).size() + std::get<1>(pair).size();
172 });
173
174 size_t i = 0;
175 for (auto size : total_sizes) {
176 result[i].reserve(size);
177 std::ranges::copy(region_data[i],
178 std::back_inserter(result[i]));
179 ++i;
180 }
181 }
182 }
183
184 return result;
185}
186
187/**
188 * @brief Extract data for multiple segments from multi-channel source data.
189 * @tparam T Data type.
190 * @param segments Vector of region segments to extract.
191 * @param source_spans Vector of source data spans (one per channel).
192 * @param dimensions Dimension descriptors.
193 * @param organization Storage organization strategy.
194 * @return Vector of vectors, each containing extracted data for one segment.
195 */
196template <typename T>
197std::vector<std::vector<T>> extract_segments_data(
198 const std::vector<RegionSegment>& segments,
199 const std::vector<std::span<const T>>& source_spans,
200 const std::vector<DataDimension>& dimensions,
201 OrganizationStrategy organization)
202{
203 if (source_spans.size() != 1) {
204 throw std::invalid_argument("Source spans cannot be empty");
205 }
206
207 std::vector<std::vector<T>> result;
208
209 for (const auto& segment : segments) {
210 if (segment.is_cached && !segment.cache.data.empty()) {
211 for (const auto& variant : segment.cache.data) {
212 std::vector<T> converted;
213 auto span = extract_from_variant<T>(variant, converted);
214 std::vector<T> cached_data(span.begin(), span.end());
215
216 if (organization == OrganizationStrategy::INTERLEAVED) {
217 if (result.empty())
218 result.resize(1);
219 std::ranges::copy(cached_data, std::back_inserter(result[0]));
220 } else {
221 if (result.size() <= result.size())
222 result.resize(result.size() + 1);
223 result.back() = std::move(cached_data);
224 }
225 }
226 } else {
227 auto region_data = extract_region_data<T>(source_spans, segment.source_region, dimensions, organization);
228
229 if (organization == OrganizationStrategy::INTERLEAVED) {
230 if (result.empty())
231 result.resize(1);
232 std::ranges::copy(region_data[0], std::back_inserter(result[0]));
233 } else {
234 if (result.empty())
235 result.resize(region_data.size());
236 for (size_t i = 0; i < region_data.size(); ++i) {
237 std::ranges::copy(region_data[i], std::back_inserter(result[i]));
238 }
239 }
240 }
241 }
242
243 return result;
244}
245
246/**
247 * @brief Extract a region of data from a vector using a Region and dimension info.
248 * @tparam T Data type.
249 * @param data Source data vector.
250 * @param region Region to extract.
251 * @param dimensions Dimension descriptors.
252 * @return Vector containing the extracted region data.
253 */
254template <typename T>
255std::vector<T> extract_region(
256 const std::vector<T>& data,
257 const Region& region,
258 const std::vector<DataDimension>& dimensions)
259{
260 std::span<const T> data_span(data.data(), data.size());
261 return extract_region_data(data_span, region, dimensions);
262}
263
264/**
265 * @brief Extract a region of data from vector of vectors (planar data).
266 * @tparam T Data type.
267 * @param source_data Vector of vectors containing source data (one per channel).
268 * @param region Region to extract.
269 * @param dimensions Dimension descriptors.
270 * @return Vector of vectors (channels) containing extracted data.
271 */
272template <typename T>
273std::vector<std::vector<T>> extract_region(
274 const std::vector<std::vector<T>>& source_data,
275 const Region& region,
276 const std::vector<DataDimension>& dimensions)
277{
278 std::vector<std::span<const T>> source_spans;
279 source_spans.reserve(source_data.size());
280
281 for (const auto& channel : source_data) {
282 source_spans.emplace_back(channel.data(), channel.size());
283 }
284
285 return extract_region_data(source_spans, region, dimensions);
286}
287
288/**
289 * @brief Extract a region of data with organization strategy.
290 * @tparam T Data type.
291 * @param source_spans Vector of source data spans (one per channel).
292 * @param region Region to extract.
293 * @param dimensions Dimension descriptors.
294 * @param organization Storage organization strategy.
295 * @return Vector of vectors (channels) containing extracted data.
296 */
297template <typename T>
299 const std::vector<std::span<const T>>& source_spans,
300 const Region& region,
301 const std::vector<DataDimension>& dimensions,
302 OrganizationStrategy organization)
303{
304 if (organization == OrganizationStrategy::INTERLEAVED) {
305 return std::vector<std::vector<T>> {
306 extract_region_data(source_spans[0], region, dimensions)
307 };
308 }
309
310 return extract_region_data(source_spans, region, dimensions);
311}
312
313/**
314 * @brief Write or update a region of data in a flat data span (interleaved).
315 * @tparam T Data type.
316 * @param dest_data Destination data span (to be updated).
317 * @param source_data Source data span (to write from).
318 * @param region Region to update.
319 * @param dimensions Dimension descriptors.
320 */
321template <typename T>
323 std::span<T> dest_data,
324 std::span<const T> source_data,
325 const Region& region,
326 const std::vector<DataDimension>& dimensions)
327{
328 std::vector<uint64_t> current = region.start_coordinates;
329 size_t source_index = 0;
330 while (source_index < source_data.size()) {
331 uint64_t linear_index = coordinates_to_linear(current, dimensions);
332 dest_data[linear_index] = source_data[source_index++];
333 bool done = true;
334 /* for (size_t dim = 0; dim < current.size(); ++dim) {
335 if (current[dim] < region.end_coordinates[dim]) {
336 current[dim]++;
337 done = false;
338 break;
339 }
340 current[dim] = region.start_coordinates[dim];
341 } */
342 for (int dim = static_cast<int>(current.size()) - 1; dim >= 0; --dim) {
343 if (current[dim] < region.end_coordinates[dim]) {
344 current[dim]++;
345 done = false;
346 break;
347 }
348 current[dim] = region.start_coordinates[dim];
349 }
350
351 if (done)
352 break;
353 }
354}
355
356/**
357 * @brief Write or update a region of data in planar storage.
358 * @tparam T Data type.
359 * @param dest_spans Vector of destination data spans (one per channel).
360 * @param source_data Vector of source data spans (one per channel).
361 * @param region Region to update (includes channel dimension).
362 * @param dimensions Dimension descriptors (includes channel dimension).
363 */
364template <typename T>
366 std::vector<std::span<T>>& dest_spans,
367 const std::vector<std::span<const T>>& source_data,
368 const Region& region,
369 const std::vector<DataDimension>& dimensions)
370{
371 size_t channel_dim_idx = 0;
372 for (size_t i = 0; i < dimensions.size(); ++i) {
373 if (dimensions[i].role == DataDimension::Role::CHANNEL) {
374 channel_dim_idx = i;
375 break;
376 }
377 }
378
379 size_t start_channel = region.start_coordinates[channel_dim_idx];
380 size_t end_channel = region.end_coordinates[channel_dim_idx];
381
382 for (size_t ch = start_channel; ch <= end_channel && ch < dest_spans.size(); ++ch) {
383 size_t source_channel_idx = ch - start_channel;
384 if (source_channel_idx >= source_data.size())
385 continue;
386
387 Region channel_region = remove_channel_dimension(region, dimensions);
388 auto non_channel_dims = get_non_channel_dimensions(dimensions);
389
391 dest_spans[ch],
392 source_data[source_channel_idx],
393 channel_region,
394 non_channel_dims);
395 }
396}
397
398/**
399 * @brief Write or update a region of data with organization strategy.
400 * @tparam T Data type.
401 * @param dest_spans Vector of destination data spans (one per channel).
402 * @param source_data Vector of source data spans (one per channel).
403 * @param region Region to update.
404 * @param dimensions Dimension descriptors.
405 * @param organization Storage organization strategy.
406 */
407template <typename T>
409 std::vector<std::span<T>>& dest_spans,
410 const std::vector<std::span<const T>>& source_data,
411 const Region& region,
412 const std::vector<DataDimension>& dimensions,
413 OrganizationStrategy organization)
414{
415 if (organization == OrganizationStrategy::INTERLEAVED) {
416 set_or_update_region_data(dest_spans[0], source_data[0], region, dimensions);
417 } else {
418 set_or_update_region_data(dest_spans, source_data, region, dimensions);
419 }
420}
421
422/**
423 * @brief Calculate the total number of elements in a region.
424 * @param region Region to query.
425 * @return Product of spans across all dimensions.
426 */
427uint64_t calculate_region_size(const Region& region);
428
429/**
430 * @brief Get an attribute value from a Region by key.
431 * @tparam T Expected type.
432 * @param region Region to query.
433 * @param key Attribute key.
434 * @return Optional value if present and convertible.
435 */
436template <typename T>
437std::optional<T> get_region_attribute(const Region& region, const std::string& key)
438{
439 auto it = region.attributes.find(key);
440 if (it != region.attributes.end()) {
441 try {
442 return safe_any_cast<T>(it->second);
443 } catch (const std::bad_any_cast&) {
444 return std::nullopt;
445 }
446 }
447 return std::nullopt;
448}
449
450/**
451 * @brief Set an attribute value on a Region.
452 * @param region Region to modify.
453 * @param key Attribute key.
454 * @param value Value to set.
455 */
456void set_region_attribute(Region& region, const std::string& key, std::any value);
457
458/**
459 * @brief Find all regions in a RegionGroup with a given label.
460 * @param group RegionGroup to search.
461 * @param label Label to match.
462 * @return Vector of matching Regions.
463 */
464std::vector<Region> find_regions_with_label(const RegionGroup& group, const std::string& label);
465
466/**
467 * @brief Find all regions in a RegionGroup with a specific attribute value.
468 * @param group RegionGroup to search.
469 * @param key Attribute key.
470 * @param value Attribute value to match.
471 * @return Vector of matching Regions.
472 */
473std::vector<Region> find_regions_with_attribute(const RegionGroup& group, const std::string& key, const std::any& value);
474
475/**
476 * @brief Find all regions in a RegionGroup that contain the given coordinates.
477 * @param group RegionGroup to search.
478 * @param coordinates N-dimensional coordinates.
479 * @return Vector of matching Regions.
480 */
481std::vector<Region> find_regions_containing_coordinates(const RegionGroup& group, const std::vector<uint64_t>& coordinates);
482
483/**
484 * @brief Translate a Region by an offset vector.
485 * @param region Region to translate.
486 * @param offset Offset for each dimension (can be negative).
487 * @return New translated Region.
488 */
489Region translate_region(const Region& region, const std::vector<int64_t>& offset);
490
491/**
492 * @brief Scale a Region about its center by the given factors.
493 * @param region Region to scale.
494 * @param factors Scaling factors for each dimension.
495 * @return New scaled Region.
496 */
497Region scale_region(const Region& region, const std::vector<double>& factors);
498
499/**
500 * @brief Get the bounding region that contains all regions in a RegionGroup.
501 * @param group RegionGroup to query.
502 * @return Region representing the bounding box.
503 */
504Region get_bounding_region(const RegionGroup& group);
505
506/**
507 * @brief Sort a vector of Regions by a specific dimension.
508 * @param regions Vector of Regions to sort.
509 * @param dimension Dimension index to sort by.
510 */
511void sort_regions_by_dimension(std::vector<Region>& regions, size_t dimension);
512
513/**
514 * @brief Sort a vector of Regions by a specific attribute (numeric).
515 * @param regions Vector of Regions to sort.
516 * @param attr_name Attribute name to sort by.
517 */
518void sort_regions_by_attribute(std::vector<Region>& regions, const std::string& attr_name);
519
520/**
521 * @brief Add a named reference region to a reference list.
522 * @param refs Reference list (name, Region) pairs.
523 * @param name Name for the reference.
524 * @param region Region to add.
525 */
526void add_reference_region(std::vector<std::pair<std::string, Region>>& refs, const std::string& name, const Region& region);
527
528/**
529 * @brief Remove a named reference region from a reference list.
530 * @param refs Reference list (name, Region) pairs.
531 * @param name Name of the reference to remove.
532 */
533void remove_reference_region(std::vector<std::pair<std::string, Region>>& refs, const std::string& name);
534
535/**
536 * @brief Get a named reference region from a reference list.
537 * @param refs Reference list (name, Region) pairs.
538 * @param name Name of the reference to retrieve.
539 * @return Optional Region if found.
540 */
541std::optional<Region> get_reference_region(const std::vector<std::pair<std::string, Region>>& refs, const std::string& name);
542
543/**
544 * @brief Find all references in a reference list that overlap a given region.
545 * @param refs Reference list (name, Region) pairs.
546 * @param region Region to check for overlap.
547 * @return Vector of (name, Region) pairs that overlap.
548 */
549std::vector<std::pair<std::string, Region>> find_references_in_region(const std::vector<std::pair<std::string, Region>>& refs, const Region& region);
550
551/**
552 * @brief Add a RegionGroup to a group map.
553 * @param groups Map of group name to RegionGroup.
554 * @param group RegionGroup to add.
555 */
556void add_region_group(std::unordered_map<std::string, RegionGroup>& groups, const RegionGroup& group);
557
558/**
559 * @brief Get a RegionGroup by name from a group map.
560 * @param groups Map of group name to RegionGroup.
561 * @param name Name of the group to retrieve.
562 * @return Optional RegionGroup if found.
563 */
564std::optional<RegionGroup> get_region_group(const std::unordered_map<std::string, RegionGroup>& groups, const std::string& name);
565
566/**
567 * @brief Remove a RegionGroup by name from a group map.
568 * @param groups Map of group name to RegionGroup.
569 * @param name Name of the group to remove.
570 */
571void remove_region_group(std::unordered_map<std::string, RegionGroup>& groups, const std::string& name);
572
573/**
574 * @brief Calculate output region bounds from current position and shape.
575 * @param current_pos Current position coordinates.
576 * @param output_shape Desired output shape.
577 * @return Region representing the output bounds.
578 */
579Region calculate_output_region(const std::vector<uint64_t>& current_pos,
580 const std::vector<uint64_t>& output_shape);
581
582/**
583 *@brief Calculate output region for frame-based processing.
584 * @param current_frame Current frame index.
585 * @param frames_to_process Number of frames to process.
586 * @param container Container providing layout information.
587 * @return Region representing the output bounds for the specified frames.
588 */
589Region calculate_output_region(uint64_t current_frame,
590 uint64_t frames_to_process,
591 const std::shared_ptr<SignalSourceContainer>& container);
592
593/**
594 * @brief Check if region access will be contiguous in memory.
595 * @param region Region to check.
596 * @param container Container providing layout information.
597 * @return True if access is contiguous, false otherwise.
598 */
599bool is_region_access_contiguous(const Region& region,
600 const std::shared_ptr<SignalSourceContainer>& container);
601
602/**
603 * @brief Extract all regions from container's region groups.
604 * @param container Container to extract regions from.
605 * @return Vector of structured region information.
606 */
607std::vector<std::unordered_map<std::string, std::any>> extract_all_regions_info(const std::shared_ptr<SignalSourceContainer>& container);
608
609/**
610 * @brief Extract bounds information from region group.
611 * @param group Region group to analyze.
612 * @return Map containing group bounds metadata.
613 */
614std::unordered_map<std::string, std::any> extract_group_bounds_info(const RegionGroup& group);
615
616/**
617 * @brief Extract metadata from region segments.
618 * @param segments Vector of region segments.
619 * @return Vector of metadata maps, one per segment.
620 */
621std::vector<std::unordered_map<std::string, std::any>> extract_segments_metadata(const std::vector<RegionSegment>& segments);
622
623/**
624 * @brief Extract structured bounds information from region.
625 * @param region The region to analyze.
626 * @return Map containing bounds metadata.
627 */
628std::unordered_map<std::string, std::any> extract_region_bounds_info(const Region& region);
629
630/**
631 * @brief Find optimal region containing given position.
632 * @param position Coordinates to search for.
633 * @param regions Vector of regions to search within.
634 * @return Optional index of containing region.
635 */
636std::optional<size_t> find_region_for_position(const std::vector<uint64_t>& position,
637 const std::vector<Region>& regions);
638
639/**
640 * @brief Find the index of the region containing the given position.
641 * @param position N-dimensional coordinates.
642 * @param regions vector of OrganizedRegions
643 * @return Optional index of the containing region, or std::nullopt if not found.
644 */
645std::optional<size_t> find_region_for_position(const std::vector<uint64_t>& position, std::vector<OrganizedRegion> regions);
646
647}
uint64_t coordinates_to_linear(const std::vector< uint64_t > &coords, const std::vector< DataDimension > &dimensions)
Convert N-dimensional coordinates to a linear index for interleaved data.
Definition CoordUtils.cpp:6
std::vector< T > extract_region(const std::vector< T > &data, const Region &region, const std::vector< DataDimension > &dimensions)
Extract a region of data from a vector using a Region and dimension info.
void set_region_attribute(Region &region, const std::string &key, std::any value)
Set an attribute value on a Region.
Region remove_channel_dimension(const Region &region, const std::vector< DataDimension > &dimensions)
Remove the channel dimension from a Region.
std::vector< std::vector< T > > extract_segments_data(const std::vector< RegionSegment > &segments, const std::vector< std::span< const T > > &source_spans, const std::vector< DataDimension > &dimensions, OrganizationStrategy organization)
Extract data for multiple segments from multi-channel source data.
void sort_regions_by_attribute(std::vector< Region > &regions, const std::string &attr_name)
Sort a vector of Regions by a specific attribute (numeric).
std::optional< T > get_region_attribute(const Region &region, const std::string &key)
Get an attribute value from a Region by key.
std::optional< RegionGroup > get_region_group(const std::unordered_map< std::string, RegionGroup > &groups, const std::string &name)
Get a RegionGroup by name from a group map.
std::vector< Region > find_regions_with_label(const RegionGroup &group, const std::string &label)
Find all regions in a RegionGroup with a given label.
bool is_region_access_contiguous(const Region &region, const std::shared_ptr< SignalSourceContainer > &container)
Check if region access will be contiguous in memory.
std::unordered_map< std::string, std::any > extract_region_bounds_info(const Region &region)
Extract structured bounds information from region.
std::vector< T > flatten_channels(const std::vector< std::vector< T > > &channel_data)
Flatten a vector of channel data into a single vector.
void add_reference_region(std::vector< std::pair< std::string, Region > > &refs, const std::string &name, const Region &region)
Add a named reference region to a reference list.
Region translate_region(const Region &region, const std::vector< int64_t > &offset)
Translate a Region by an offset vector.
void add_region_group(std::unordered_map< std::string, RegionGroup > &groups, const RegionGroup &group)
Add a RegionGroup to a group map.
Region scale_region(const Region &region, const std::vector< double > &factors)
Scale a Region about its center by the given factors.
std::vector< std::vector< T > > extract_group_data(const std::vector< std::span< const T > > &source_spans, const RegionGroup &group, const std::vector< DataDimension > &dimensions, OrganizationStrategy organization)
Extract data for multiple regions from multi-channel source data.
OrganizationStrategy
Data organization strategy for multi-channel/multi-frame data.
Definition NDData.hpp:46
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)
std::vector< std::unordered_map< std::string, std::any > > extract_segments_metadata(const std::vector< RegionSegment > &segments)
Extract metadata from region segments.
void remove_region_group(std::unordered_map< std::string, RegionGroup > &groups, const std::string &name)
Remove a RegionGroup by name from a group map.
std::unordered_map< std::string, std::any > extract_group_bounds_info(const RegionGroup &group)
Extract bounds information from region group.
std::vector< Region > find_regions_containing_coordinates(const RegionGroup &group, const std::vector< uint64_t > &coordinates)
Find all regions in a RegionGroup that contain the given coordinates.
void remove_reference_region(std::vector< std::pair< std::string, Region > > &refs, const std::string &name)
Remove a named reference region from a reference list.
std::vector< T > extract_region_data(const std::span< const T > &source_data, const Region &region, const std::vector< DataDimension > &dimensions)
Extract a region of data from a flat data span using a Region and dimension info.
std::vector< Region > find_regions_with_attribute(const RegionGroup &group, const std::string &key, const std::any &value)
Find all regions in a RegionGroup with a specific attribute value.
std::vector< std::unordered_map< std::string, std::any > > extract_all_regions_info(const std::shared_ptr< SignalSourceContainer > &container)
Extract all regions from container's region groups.
Region get_bounding_region(const RegionGroup &group)
Get the bounding region that contains all regions in a RegionGroup.
std::vector< std::pair< std::string, Region > > find_references_in_region(const std::vector< std::pair< std::string, Region > > &refs, const Region &region)
Find all references in a reference list that overlap a given region.
std::optional< size_t > find_region_for_position(const std::vector< uint64_t > &position, const std::vector< Region > &regions)
Find optimal region containing given position.
Region calculate_output_region(const std::vector< uint64_t > &current_pos, const std::vector< uint64_t > &output_shape)
Calculate output region bounds from current position and shape.
uint64_t calculate_region_size(const Region &region)
Calculate the total number of elements in a region.
std::optional< Region > get_reference_region(const std::vector< std::pair< std::string, Region > > &refs, const std::string &name)
Get a named reference region from a reference list.
void set_or_update_region_data(std::span< T > dest_data, std::span< const T > source_data, const Region &region, const std::vector< DataDimension > &dimensions)
Write or update a region of data in a flat data span (interleaved).
std::vector< DataDimension > get_non_channel_dimensions(const std::vector< DataDimension > &dimensions)
Get all non-channel dimensions from a list of dimensions.
void sort_regions_by_dimension(std::vector< Region > &regions, size_t dimension)
Sort a vector of Regions by a specific dimension.
@ CHANNEL
Parallel streams (audio channels, color channels)
std::vector< Region > regions
Collection of regions belonging to this group.
Organizes related signal regions into a categorized collection.
std::unordered_map< std::string, std::any > attributes
Flexible key-value store for region-specific attributes.
Definition Region.hpp:75
uint64_t get_volume() const
Get the total volume (number of elements) in the region.
Definition Region.hpp:295
std::vector< uint64_t > end_coordinates
Ending frame index (inclusive)
Definition Region.hpp:72
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
Definition Region.hpp:69
Represents a point or span in N-dimensional space.
Definition Region.hpp:67