84 Region(
const std::vector<uint64_t>& coordinates,
85 std::unordered_map<std::string, std::any> attributes = {})
86 : start_coordinates(coordinates)
87 , end_coordinates(coordinates)
88 , attributes(
std::move(attributes))
99 std::vector<uint64_t> end,
100 std::unordered_map<std::string, std::any> attributes = {})
101 : start_coordinates(
std::move(start))
102 , end_coordinates(
std::move(end))
103 , attributes(
std::move(attributes))
115 const std::string& label =
"",
116 const std::any& extra_data = {})
118 std::unordered_map<std::string, std::any> attrs;
120 attrs[
"label"] = label;
121 if (extra_data.has_value())
122 attrs[
"data"] = extra_data;
123 attrs[
"type"] =
"time_point";
124 return Region({ frame }, attrs);
137 const std::string& label =
"",
138 const std::any& extra_data = {})
140 std::unordered_map<std::string, std::any> attrs;
142 attrs[
"label"] = label;
143 if (extra_data.has_value())
144 attrs[
"data"] = extra_data;
145 attrs[
"type"] =
"time_span";
146 return Region({ start_frame }, { end_frame }, attrs);
158 const std::string& label =
"")
160 std::unordered_map<std::string, std::any> attrs;
162 attrs[
"label"] = label;
163 attrs[
"type"] =
"audio_point";
164 return Region({ frame, channel }, attrs);
178 uint32_t start_channel,
179 uint32_t end_channel,
180 const std::string& label =
"")
182 std::unordered_map<std::string, std::any> attrs;
184 attrs[
"label"] = label;
185 attrs[
"type"] =
"audio_region";
186 return Region({ start_frame, start_channel },
187 { end_frame, end_channel }, attrs);
200 uint64_t x2, uint64_t y2,
201 const std::string& label =
"")
203 std::unordered_map<std::string, std::any> attrs;
205 attrs[
"label"] = label;
206 attrs[
"type"] =
"image_rect";
207 return Region({ x1, y1 }, { x2, y2 }, attrs);
223 uint64_t x1, uint64_t y1,
224 uint64_t x2, uint64_t y2,
225 const std::string& label =
"")
227 std::unordered_map<std::string, std::any> attrs;
229 attrs[
"label"] = label;
230 attrs[
"type"] =
"video_region";
231 return Region({ start_frame, x1, y1 },
232 { end_frame, x2, y2 }, attrs);
240 return start_coordinates == end_coordinates;
248 bool contains(
const std::vector<uint64_t>& coordinates)
const
250 if (coordinates.size() != start_coordinates.size())
253 for (
size_t i = 0; i < start_coordinates.size(); i++) {
254 if (coordinates[i] < start_coordinates[i] || coordinates[i] > end_coordinates[i]) {
271 for (
size_t i = 0; i < start_coordinates.size(); i++) {
284 uint64_t
get_span(uint32_t dimension_index = 0)
const
286 if (dimension_index >= start_coordinates.size())
288 return end_coordinates[dimension_index] - start_coordinates[dimension_index] + 1;
298 for (
size_t i = 0; i < start_coordinates.size(); i++) {
299 volume *= get_span(i);
311 if (dimension_index >= start_coordinates.size()) {
314 return end_coordinates[dimension_index] - start_coordinates[dimension_index] + 1;
323 template <
typename T>
326 auto it = attributes.find(key);
327 if (it == attributes.end()) {
331 return safe_any_cast<T>(it->second);
341 attributes[key] = std::move(value);
350 auto label = get_attribute<std::string>(
"label");
351 return label.value_or(
"");
360 set_attribute(
"label", label);
371 for (
size_t i = 0; i < std::min(offset.size(), start_coordinates.size()); i++) {
372 if (offset[i] < 0 && std::abs(offset[i]) >
static_cast<int64_t
>(result.
start_coordinates[i])) {
378 if (offset[i] < 0 && std::abs(offset[i]) >
static_cast<int64_t
>(result.
end_coordinates[i])) {
395 for (
size_t i = 0; i < std::min<size_t>(factors.size(), start_coordinates.size()); i++) {
396 uint64_t center = (start_coordinates[i] + end_coordinates[i]) / 2;
397 uint64_t half_span = get_span(i) / 2;
398 auto new_half_span =
static_cast<uint64_t
>((double)half_span * factors[i]);
415 for (
size_t i = 0; i < start_coordinates.size(); ++i) {
421 for (
size_t i = 0; i < end_coordinates.size(); ++i) {
435 return !(*
this == other);
RegionSelectionPattern
Describes how regions are selected for processing or playback.
@ RANDOM
Random selection.
@ ROUND_ROBIN
Cycle through regions.
@ SEQUENTIAL
Process regions in order.
@ ALL
Process all regions.
@ CUSTOM
User-defined selection logic.
@ OVERLAP
Overlapping selection.
@ WEIGHTED
Weighted random selection.
@ EXCLUSIVE
Mutually exclusive selection.
RegionTransition
Describes how transitions between regions are handled.
@ GATED
Hard gate between regions.
@ CROSSFADE
Crossfade between regions.
@ IMMEDIATE
No transition, jump directly.
@ CALLBACK
Use callback for custom transition.
RegionState
Processing state for regions.
@ ACTIVE
Currently being processed.
@ READY
Ready for processing.
@ UNLOADING
Being removed from memory.
@ TRANSITIONING
In transition to another region.
@ IDLE
Not being processed.
@ LOADING
Data being loaded.
void set_label(const std::string &label)
Set the label attribute.
uint64_t get_duration(uint32_t dimension_index=0) const
Get the duration (span) along a specific dimension.
bool is_point() const
Check if this region is a single point (start == end).
static Region audio_point(uint64_t frame, uint32_t channel, const std::string &label="")
Create a Region for a single audio sample/channel location.
static Region audio_span(uint64_t start_frame, uint64_t end_frame, uint32_t start_channel, uint32_t end_channel, const std::string &label="")
Create a Region representing a span in audio (frames and channels).
static Region time_span(uint64_t start_frame, uint64_t end_frame, const std::string &label="", const std::any &extra_data={})
Create a Region representing a time span (e.g., a segment of frames).
Region(const std::vector< uint64_t > &coordinates, std::unordered_map< std::string, std::any > attributes={})
Construct a point-like region (single coordinate).
void set_attribute(const std::string &key, std::any value)
Set an attribute value by key.
Region translate(const std::vector< int64_t > &offset) const
Translate the region by an offset vector.
bool operator!=(const Region &other) const
Inequality comparison for Regions.
std::unordered_map< std::string, std::any > attributes
Flexible key-value store for region-specific attributes.
uint64_t get_span(uint32_t dimension_index=0) const
Get the span (length) of the region along a dimension.
Region scale(const std::vector< double > &factors) const
Scale the region about its center by the given factors.
std::optional< T > get_attribute(const std::string &key) const
Get an attribute value by key, with type conversion support.
uint64_t get_volume() const
Get the total volume (number of elements) in the region.
std::vector< uint64_t > end_coordinates
Ending frame index (inclusive)
static Region video_region(uint64_t start_frame, uint64_t end_frame, uint64_t x1, uint64_t y1, uint64_t x2, uint64_t y2, const std::string &label="")
Create a Region representing a region in a video (frames and spatial rectangle).
bool overlaps(const Region &other) const
Check if this region overlaps with another region.
std::string get_label() const
Get the label attribute (if present).
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
bool contains(const std::vector< uint64_t > &coordinates) const
Check if the given coordinates are contained within this region.
static Region image_rect(uint64_t x1, uint64_t y1, uint64_t x2, uint64_t y2, const std::string &label="")
Create a Region representing a rectangular region in an image.
bool operator==(const Region &other) const
Equality comparison for Regions.
Region(std::vector< uint64_t > start, std::vector< uint64_t > end, std::unordered_map< std::string, std::any > attributes={})
Construct a span-like region (start and end coordinates).
static Region time_point(uint64_t frame, const std::string &label="", const std::any &extra_data={})
Create a Region representing a single time point (e.g., a frame or sample).
Represents a point or span in N-dimensional space.