5#ifdef MAYAFLUX_PLATFORM_WINDOWS
90 Region(
const std::vector<uint64_t>& coordinates,
91 std::unordered_map<std::string, std::any> attributes = {})
92 : start_coordinates(coordinates)
93 , end_coordinates(coordinates)
94 , attributes(
std::move(attributes))
105 std::vector<uint64_t> end,
106 std::unordered_map<std::string, std::any> attributes = {})
107 : start_coordinates(
std::move(start))
108 , end_coordinates(
std::move(end))
109 , attributes(
std::move(attributes))
121 const std::string& label =
"",
122 const std::any& extra_data = {})
124 std::unordered_map<std::string, std::any> attrs;
126 attrs[
"label"] = label;
127 if (extra_data.has_value())
128 attrs[
"data"] = extra_data;
129 attrs[
"type"] =
"time_point";
130 return Region({ frame }, attrs);
143 const std::string& label =
"",
144 const std::any& extra_data = {})
146 std::unordered_map<std::string, std::any> attrs;
148 attrs[
"label"] = label;
149 if (extra_data.has_value())
150 attrs[
"data"] = extra_data;
151 attrs[
"type"] =
"time_span";
152 return Region({ start_frame }, { end_frame }, attrs);
164 const std::string& label =
"")
166 std::unordered_map<std::string, std::any> attrs;
168 attrs[
"label"] = label;
169 attrs[
"type"] =
"audio_point";
170 return Region({ frame, channel }, attrs);
184 uint32_t start_channel,
185 uint32_t end_channel,
186 const std::string& label =
"")
188 std::unordered_map<std::string, std::any> attrs;
190 attrs[
"label"] = label;
191 attrs[
"type"] =
"audio_region";
192 return Region({ start_frame, start_channel },
193 { end_frame, end_channel }, attrs);
206 uint64_t x2, uint64_t y2,
207 const std::string& label =
"")
209 std::unordered_map<std::string, std::any> attrs;
211 attrs[
"label"] = label;
212 attrs[
"type"] =
"image_rect";
213 return Region({ x1, y1 }, { x2, y2 }, attrs);
229 uint64_t x1, uint64_t y1,
230 uint64_t x2, uint64_t y2,
231 const std::string& label =
"")
233 std::unordered_map<std::string, std::any> attrs;
235 attrs[
"label"] = label;
236 attrs[
"type"] =
"video_region";
237 return Region({ start_frame, x1, y1 },
238 { end_frame, x2, y2 }, attrs);
246 return start_coordinates == end_coordinates;
254 bool contains(
const std::vector<uint64_t>& coordinates)
const
256 if (coordinates.size() != start_coordinates.size())
259 for (
size_t i = 0; i < start_coordinates.size(); i++) {
260 if (coordinates[i] < start_coordinates[i] || coordinates[i] > end_coordinates[i]) {
277 for (
size_t i = 0; i < start_coordinates.size(); i++) {
290 uint64_t
get_span(uint32_t dimension_index = 0)
const
292 if (dimension_index >= start_coordinates.size())
294 return end_coordinates[dimension_index] - start_coordinates[dimension_index] + 1;
304 for (
size_t i = 0; i < start_coordinates.size(); i++) {
305 volume *= get_span(i);
317 if (dimension_index >= start_coordinates.size()) {
320 return end_coordinates[dimension_index] - start_coordinates[dimension_index] + 1;
329 template <
typename T>
332 auto it = attributes.find(key);
333 if (it == attributes.end()) {
337 return safe_any_cast<T>(it->second);
347 attributes[key] = std::move(value);
356 auto label = get_attribute<std::string>(
"label");
357 return label.value_or(
"");
366 set_attribute(
"label", label);
377 for (
size_t i = 0; i < std::min(offset.size(), start_coordinates.size()); i++) {
378 if (offset[i] < 0 && std::abs(offset[i]) >
static_cast<int64_t
>(result.
start_coordinates[i])) {
384 if (offset[i] < 0 && std::abs(offset[i]) >
static_cast<int64_t
>(result.
end_coordinates[i])) {
401 for (
size_t i = 0; i < std::min<size_t>(factors.size(), start_coordinates.size()); i++) {
402 uint64_t center = (start_coordinates[i] + end_coordinates[i]) / 2;
403 uint64_t half_span = get_span(i) / 2;
404 auto new_half_span =
static_cast<uint64_t
>((double)half_span * factors[i]);
421 for (
size_t i = 0; i < start_coordinates.size(); ++i) {
427 for (
size_t i = 0; i < end_coordinates.size(); ++i) {
441 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.