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

◆ extract_region_data() [1/3]

template<typename T >
std::vector< T > MayaFlux::Kakshya::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.

Template Parameters
TData type.
Parameters
source_dataSource data span.
regionRegion to extract.
dimensionsDimension descriptors.
Returns
Vector containing the extracted region data.
Exceptions
std::out_of_rangeif region is out of bounds.

Definition at line 69 of file RegionUtils.hpp.

70{
71 for (size_t i = 0; i < region.start_coordinates.size(); ++i) {
72 if (region.end_coordinates[i] > 0 && (region.end_coordinates[i] >= dimensions[i].size)) {
73 error<std::out_of_range>(
74 Journal::Component::Kakshya, Journal::Context::Runtime,
75 std::source_location::current(),
76 "Requested region is out of bounds for dimension {}",
77 std::to_string(i));
78 }
79 }
80
81 uint64_t region_size = region.get_volume();
82 std::vector<T> result;
83 result.reserve(region_size);
84
85 std::vector<uint64_t> current = region.start_coordinates;
86 while (true) {
87 uint64_t linear_index = coordinates_to_linear(current, dimensions);
88 result.push_back(source_data[linear_index]);
89
90 bool done = true;
91 for (int dim = (int)current.size() - 1; dim >= 0; --dim) {
92 if (current[dim] < region.end_coordinates[dim]) {
93 current[dim]++;
94 done = false;
95 break;
96 }
97 current[dim] = region.start_coordinates[dim];
98 }
99 if (done)
100 break;
101 }
102 return result;
103}
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

References coordinates_to_linear(), MayaFlux::Kakshya::Region::end_coordinates, MayaFlux::Kakshya::Region::get_volume(), MayaFlux::Journal::Kakshya, MayaFlux::Journal::Runtime, and MayaFlux::Kakshya::Region::start_coordinates.

Referenced by extract_region(), extract_region(), extract_region_data(), and extract_region_data().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: