MayaFlux 0.1.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 67 of file RegionUtils.hpp.

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}
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(), 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: