MayaFlux 0.4.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 87 of file RegionUtils.hpp.

88{
89 for (size_t i = 0; i < region.start_coordinates.size(); ++i) {
90 if (region.end_coordinates[i] > 0 && (region.end_coordinates[i] >= dimensions[i].size)) {
91 error<std::out_of_range>(
92 Journal::Component::Kakshya, Journal::Context::Runtime,
93 std::source_location::current(),
94 "Requested region is out of bounds for dimension {}",
95 std::to_string(i));
96 }
97 }
98
99 uint64_t region_size = region.get_volume();
100 std::vector<T> result;
101 result.reserve(region_size);
102
103 std::vector<uint64_t> current = region.start_coordinates;
104 while (true) {
105 uint64_t linear_index = coordinates_to_linear(current, dimensions);
106 result.push_back(source_data[linear_index]);
107
108 bool done = true;
109 for (int dim = (int)current.size() - 1; dim >= 0; --dim) {
110 if (current[dim] < region.end_coordinates[dim]) {
111 current[dim]++;
112 done = false;
113 break;
114 }
115 current[dim] = region.start_coordinates[dim];
116 }
117 if (done)
118 break;
119 }
120 return result;
121}
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: