MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NDimensionalContainer.cpp
Go to the documentation of this file.
2
3namespace MayaFlux::Kakshya {
4
7 MemoryLayout layout)
8 : modality(mod)
9 , memory_layout(layout)
10 , organization(org)
11{
12}
13
47
52
57
62
67
68size_t ContainerDataStructure::get_expected_variant_count(const std::vector<DataDimension>& dimensions) const
69{
71 return 1;
72 }
73
74 switch (modality) {
79 // return get_frame_count(dimensions) * get_channel_count(dimensions);
80
81 default:
82 return 1;
83 }
84}
85
86uint64_t ContainerDataStructure::get_variant_size(const std::vector<DataDimension>& dimensions,
87 DataModality modality, OrganizationStrategy organization, size_t /*variant_index*/)
88{
89 switch (organization) {
92
94 switch (modality) {
97
100
103
104 default:
106 }
107
108 default:
110 }
111}
112
113bool ContainerDataStructure::validate_dimensions(const std::vector<DataDimension>& dimensions) const
114{
115 auto expected_roles = get_expected_dimension_roles();
116
117 if (expected_roles.empty()) {
118 return true;
119 }
120
121 if (dimensions.size() != expected_roles.size()) {
122 return false;
123 }
124
125 for (size_t i = 0; i < dimensions.size(); ++i) {
126 if (dimensions[i].role != expected_roles[i]) {
127 return false;
128 }
129 }
130
131 return true;
132}
133
134uint64_t ContainerDataStructure::get_total_elements(const std::vector<DataDimension>& dimensions)
135{
136 uint64_t total = 1;
137 for (const auto& dim : dimensions) {
138 total *= dim.size;
139 }
140 return total;
141}
142
143size_t ContainerDataStructure::get_dimension_index_for_role(const std::vector<DataDimension>& dimensions,
144 DataDimension::Role role) const
145{
146 auto expected_roles = get_expected_dimension_roles();
147
148 auto it = std::ranges::find(expected_roles, role);
149 if (it != expected_roles.end()) {
150 return std::distance(expected_roles.begin(), it);
151 }
152
153 for (size_t i = 0; i < dimensions.size(); ++i) {
154 if (dimensions[i].role == role) {
155 return i;
156 }
157 }
158
159 return SIZE_MAX;
160}
161
162uint64_t ContainerDataStructure::get_channel_count(const std::vector<DataDimension>& dimensions)
163{
164 for (const auto& dim : dimensions) {
165 if (dim.role == DataDimension::Role::CHANNEL) {
166 return dim.size;
167 }
168 }
169 return 1;
170}
171
172size_t ContainerDataStructure::get_frame_count(const std::vector<DataDimension>& dimensions)
173{
174 for (const auto& dim : dimensions) {
175 if (dim.role == DataDimension::Role::TIME) {
176 return dim.size;
177 }
178 }
179 return 1;
180}
181
182uint64_t ContainerDataStructure::get_samples_count(const std::vector<DataDimension>& dimensions)
183{
184 uint64_t time_size = 0;
185 uint64_t channel_size = 1;
186
187 for (const auto& dim : dimensions) {
188 if (dim.role == DataDimension::Role::TIME) {
189 time_size = dim.size;
190 } else if (dim.role == DataDimension::Role::CHANNEL) {
191 channel_size = dim.size;
192 }
193 }
194
195 return time_size * channel_size;
196}
197
198uint64_t ContainerDataStructure::get_samples_count_per_channel(const std::vector<DataDimension>& dimensions)
199{
200 for (const auto& dim : dimensions) {
201 if (dim.role == DataDimension::Role::TIME) {
202 return dim.size;
203 }
204 }
205 return 0;
206}
207
208uint64_t ContainerDataStructure::get_pixels_count(const std::vector<DataDimension>& dimensions)
209{
210 uint64_t pixels = 1;
211 for (const auto& dim : dimensions) {
213 pixels *= dim.size;
214 }
215 }
216 return pixels;
217}
218
219uint64_t ContainerDataStructure::get_height(const std::vector<DataDimension>& dimensions)
220{
221 for (const auto& dim : dimensions) {
222 if (dim.role == DataDimension::Role::SPATIAL_Y) {
223 return dim.size;
224 }
225 }
226 return 0;
227}
228
229uint64_t ContainerDataStructure::get_width(const std::vector<DataDimension>& dimensions)
230{
231 for (const auto& dim : dimensions) {
232 if (dim.role == DataDimension::Role::SPATIAL_X) {
233 return dim.size;
234 }
235 }
236 return 0;
237}
238
239size_t ContainerDataStructure::get_frame_size(const std::vector<DataDimension>& dimensions)
240{
241 size_t frame_size = 1;
242 for (const auto& dim : dimensions) {
243 if (dim.role != DataDimension::Role::TIME) {
244 frame_size *= dim.size;
245 }
246 }
247 return frame_size;
248}
249
250}
DataModality
Data modality types for cross-modal analysis.
Definition NDData.hpp:78
@ AUDIO_MULTICHANNEL
Multi-channel audio.
@ SPECTRAL_2D
2D spectral data (time + frequency)
@ UNKNOWN
Unknown or undefined modality.
@ VOLUMETRIC_3D
3D volumetric data
@ VIDEO_GRAYSCALE
3D video (time + 2D grayscale)
@ VIDEO_COLOR
4D video (time + 2D + color)
@ TENSOR_ND
N-dimensional tensor.
@ IMAGE_COLOR
2D RGB/RGBA image
@ IMAGE_2D
2D image (grayscale or single channel)
MemoryLayout
Memory layout for multi-dimensional data.
Definition NDData.hpp:36
OrganizationStrategy
Data organization strategy for multi-channel/multi-frame data.
Definition NDData.hpp:46
@ PLANAR
Separate DataVariant per logical unit (LLL...RRR for stereo)
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)
static ContainerDataStructure audio_planar()
Create structure for planar audio data.
static ContainerDataStructure image_planar()
Create structure for planar image data.
static ContainerDataStructure image_interleaved()
Create structure for interleaved image data.
std::vector< DataDimension::Role > get_expected_dimension_roles() const
Get the expected dimension roles for this structure's modality.
size_t get_expected_variant_count(const std::vector< DataDimension > &dimensions) const
Calculate expected number of data variants for given dimensions.
bool validate_dimensions(const std::vector< DataDimension > &dimensions) const
Validate that dimensions match this structure's expectations.
static ContainerDataStructure audio_interleaved()
Create structure for interleaved audio data.
size_t get_dimension_index_for_role(const std::vector< DataDimension > &dimensions, DataDimension::Role role) const
Find the index of a dimension with the specified role.
Container structure for consistent dimension ordering.
Role
Semantic role of the dimension.
Definition NDData.hpp:145
@ FREQUENCY
Spectral/frequency axis.
@ TIME
Temporal progression (samples, frames, steps)
@ CHANNEL
Parallel streams (audio channels, color channels)
@ SPATIAL_X
Spatial X axis (images, tensors)