14 : m_window(
std::move(window))
17 error<std::invalid_argument>(
20 std::source_location::current(),
21 "WindowContainer requires a valid window");
28 "WindowContainer created for window '{}' ({}x{})",
39 const auto& fmt =
m_window->get_create_info().container_format;
40 const uint32_t w =
m_window->get_create_info().width;
41 const uint32_t h =
m_window->get_create_info().height;
42 const uint32_t c = fmt.color_channels;
47 {
static_cast<uint64_t
>(h),
static_cast<uint64_t
>(w),
static_cast<uint64_t
>(c) },
50 const size_t sz =
static_cast<size_t>(w) * h * c;
87 if (!src || src->empty())
91 const std::span<const uint8_t> src_span { src->data(), src->size() };
93 std::vector<DataVariant> result;
96 for (
const auto& r : group.regions) {
100 result.emplace_back(extract_nd_region<uint8_t>(src_span, r, dims));
101 }
catch (
const std::exception& e) {
103 "WindowContainer::get_region_data extraction failed — {}", e.what());
114 "WindowContainer::set_region_data — write path not yet implemented");
134 const auto* pixels = std::get_if<std::vector<uint8_t>>(&
m_processed_data[0]);
140 const uint64_t idx = (coordinates[0] * w + coordinates[1]) * c + coordinates[2];
142 if (idx >= pixels->size())
145 return static_cast<double>((*pixels)[idx]) / 255.0;
178 return (v && !v->empty()) ? v->data() :
nullptr;
186 return std::visit([](
const auto& v) {
return !v.empty(); },
m_processed_data[0]);
192 "WindowContainer::load_region — no-op. Register regions via add_region_group()");
198 "WindowContainer::unload_region — no-op. Remove regions via remove_region_group()");
248 if (old == new_state)
257 std::function<
void(
const std::shared_ptr<SignalSourceContainer>&,
ProcessingState)> callback)
281 auto readback = std::make_shared<WindowAccessProcessor>();
282 readback->on_attach(shared_from_this());
370 "WindowContainer::channel_data — not meaningful for interleaved image data; returning full surface");
#define MF_INFO(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
Type-erased accessor for NDData with semantic view construction.
uint64_t coordinates_to_linear_index(const std::vector< uint64_t > &coordinates) const override
Convert coordinates to linear index based on current memory layout.
ProcessingState get_processing_state() const override
Get the current processing state of the container.
std::atomic< uint32_t > m_registered_readers
std::function< void(const std::shared_ptr< SignalSourceContainer > &, ProcessingState)> m_state_callback
std::atomic< ProcessingState > m_processing_state
void set_processing_chain(const std::shared_ptr< DataProcessingChain > &chain) override
Set the processing chain for this container.
void create_default_processor() override
Create and configure a default processor for this container.
DataAccess channel_data(size_t channel_index) override
Get channel data with semantic interpretation.
bool is_region_loaded(const Region ®ion) const override
Always returns true.
void set_memory_layout(MemoryLayout layout) override
Set the memory layout for this container.
WindowContainer(std::shared_ptr< Core::Window > window)
Construct from an existing managed window.
void unregister_dimension_reader(uint32_t dimension_index) override
Unregister a reader for a specific dimension.
void clear() override
Clear all data in the container.
void unregister_state_change_callback() override
Unregister the state change callback, if any.
std::shared_ptr< Core::Window > m_window
uint64_t get_total_elements() const override
Get the total number of elements in the container.
const void * get_raw_data() const override
Get a raw pointer to the underlying data storage.
std::vector< DataDimension > get_dimensions() const override
Get the dimensions describing the structure of the data.
std::atomic< uint32_t > m_consumed_readers
const std::vector< DataVariant > & get_data() override
Get a reference to the raw data stored in the container.
void load_region(const Region ®ion) override
No-op.
void lock() override
Acquire a lock for thread-safe access.
std::shared_mutex m_data_mutex
std::vector< DataVariant > m_processed_data
std::atomic< bool > m_ready_for_processing
const RegionGroup & get_region_group(const std::string &name) const override
Get a region group by name.
std::unordered_map< std::string, RegionGroup > m_region_groups
void mark_dimension_consumed(uint32_t dimension_index, uint32_t reader_id) override
Mark a dimension as consumed for the current processing cycle.
uint32_t register_dimension_reader(uint32_t dimension_index) override
Register a reader for a specific dimension.
std::unordered_map< std::string, RegionGroup > get_all_region_groups() const override
Get all region groups in the container.
ContainerDataStructure m_structure
void unlock() override
Release a previously acquired lock.
std::vector< DataVariant > m_data
void update_processing_state(ProcessingState new_state) override
Update the processing state of the container.
void mark_ready_for_processing(bool ready) override
Mark the container as ready or not ready for processing.
std::vector< DataVariant > get_region_group_data(const RegionGroup &group) const override
Get data for multiple regions efficiently.
std::shared_ptr< DataProcessingChain > m_processing_chain
std::shared_ptr< DataProcessor > m_default_processor
bool has_data() const override
Check if the container currently holds any data.
void remove_region_group(const std::string &name) override
Remove a region group by name.
void set_default_processor(const std::shared_ptr< DataProcessor > &processor) override
Set the default data processor for this container.
MemoryLayout get_memory_layout() const override
Get the memory layout used by this container.
bool has_active_readers() const override
Check if any dimensions currently have active readers.
std::vector< DataVariant > get_segments_data(const std::vector< RegionSegment > &segments) const override
Get data for multiple region segments efficiently.
std::vector< DataVariant > get_region_data(const Region ®ion) const override
Extract data for all regions across all region groups that spatially intersect region.
void set_region_data(const Region ®ion, const std::vector< DataVariant > &data) override
Set data for a specific region.
std::shared_ptr< DataProcessor > get_default_processor() const override
Get the current default data processor.
void unload_region(const Region ®ion) override
No-op.
std::vector< DataAccess > all_channel_data() override
Get all channel data as accessors.
bool all_dimensions_consumed() const override
Check if all active dimensions have been consumed in this cycle.
double get_value_at(const std::vector< uint64_t > &coordinates) const override
Get a single value at the specified coordinates.
std::vector< DataVariant > & get_processed_data() override
Get a mutable reference to the processed data buffer.
void register_state_change_callback(std::function< void(const std::shared_ptr< SignalSourceContainer > &, ProcessingState)> callback) override
Register a callback to be invoked on processing state changes.
std::shared_ptr< DataProcessingChain > get_processing_chain() override
Get the current processing chain for this container.
void process_default() override
Process the container's data using the default processor.
bool is_ready_for_processing() const override
Check if the container is ready for processing.
void set_value_at(const std::vector< uint64_t > &coordinates, double value) override
Set a single value at the specified coordinates.
std::vector< uint64_t > linear_index_to_coordinates(uint64_t linear_index) const override
Convert linear index to coordinates based on current memory layout.
bool try_lock() override
Attempt to acquire a lock without blocking.
std::atomic< uint32_t > m_next_reader_id
void add_region_group(const RegionGroup &group) override
Add a named group of regions to the container.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
ProcessingState
Represents the current processing lifecycle state of a container.
@ IDLE
Container is inactive with no data or not ready for processing.
uint64_t coordinates_to_linear(const std::vector< uint64_t > &coords, const std::vector< DataDimension > &dimensions)
Convert N-dimensional coordinates to a linear index for interleaved data.
@ IMAGE_COLOR
2D RGB/RGBA image
std::vector< uint64_t > linear_to_coordinates(uint64_t index, const std::vector< DataDimension > &dimensions)
Convert a linear index to N-dimensional coordinates for interleaved data.
MemoryLayout
Memory layout for multi-dimensional data.
@ ROW_MAJOR
C/C++ style (last dimension varies fastest)
bool regions_intersect(const Region &r1, const Region &r2) noexcept
Test whether two N-dimensional regions overlap on every shared axis.
std::vector< DataDimension > dimensions
static uint64_t get_height(const std::vector< DataDimension > &dimensions)
Extract height from image/video dimensions.
static uint64_t get_channel_count(const std::vector< DataDimension > &dimensions)
Extract channel count from dimensions.
static ContainerDataStructure image_interleaved()
Create structure for interleaved image data.
static uint64_t get_total_elements(const std::vector< DataDimension > &dimensions)
Get total elements across all dimensions.
MemoryLayout memory_layout
static uint64_t get_width(const std::vector< DataDimension > &dimensions)
Extract width from image/video dimensions.
static std::vector< DataDimension > create_dimensions(DataModality modality, const std::vector< uint64_t > &shape, MemoryLayout layout=MemoryLayout::ROW_MAJOR)
Create dimension descriptors for a data modality.
std::string name
Descriptive name of the group.
Organizes related signal regions into a categorized collection.
Represents a point or span in N-dimensional space.