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

◆ find_regions_with_attribute()

std::vector< Region > MayaFlux::Kakshya::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.

Parameters
groupRegionGroup to search.
keyAttribute key.
valueAttribute value to match.
Returns
Vector of matching Regions.

Definition at line 31 of file RegionUtils.cpp.

32{
33 std::vector<Region> result;
34 std::ranges::copy_if(group.regions, std::back_inserter(result),
35 [&key, &value](const Region& region) {
36 auto attr_it = region.attributes.find(key);
37 if (attr_it != region.attributes.end()) {
38 if (value.type() == typeid(std::string)) {
39 auto region_value = get_region_attribute<std::string>(region, key);
40 auto search_value = std::any_cast<std::string>(value);
41 return region_value.has_value() && *region_value == search_value;
42 }
43 if (value.type() == typeid(double)) {
44 auto region_value = get_region_attribute<double>(region, key);
45 auto search_value = std::any_cast<double>(value);
46 return region_value.has_value() && *region_value == search_value;
47 }
48 if (value.type() == typeid(int)) {
49 auto region_value = get_region_attribute<int>(region, key);
50 auto search_value = std::any_cast<int>(value);
51 return region_value.has_value() && *region_value == search_value;
52 }
53 // TODO: Add more types as needed
54 }
55 return false;
56 });
57 return result;
58}
std::vector< Region > regions
Collection of regions belonging to this group.
Represents a point or span in N-dimensional space.
Definition Region.hpp:67

References MayaFlux::Kakshya::RegionGroup::regions.