MayaFlux 0.5.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
14std::vector<DataDimension::Role> ContainerDataStructure::get_expected_dimension_roles() const
15{
16 switch (modality) {
19
22
25
28
31
34
37
40
43
46
49 default:
50 return {};
51 }
52}
53
58
63
68
73
74size_t ContainerDataStructure::get_expected_variant_count(const std::vector<DataDimension>& dimensions) const
75{
77 return 1;
78 }
79
80 switch (modality) {
85 // return get_frame_count(dimensions) * get_channel_count(dimensions);
88
89 default:
90 return 1;
91 }
92}
93
94uint64_t ContainerDataStructure::get_variant_size(const std::vector<DataDimension>& dimensions,
95 DataModality modality, OrganizationStrategy organization, size_t /*variant_index*/)
96{
97 switch (organization) {
100
102 switch (modality) {
105
108
112
113 default:
115 }
116
117 default:
119 }
120}
121
122bool ContainerDataStructure::validate_dimensions(const std::vector<DataDimension>& dimensions) const
123{
124 auto expected_roles = get_expected_dimension_roles();
125
126 if (expected_roles.empty()) {
127 return true;
128 }
129
130 if (dimensions.size() != expected_roles.size()) {
131 return false;
132 }
133
134 for (size_t i = 0; i < dimensions.size(); ++i) {
135 if (dimensions[i].role != expected_roles[i]) {
136 return false;
137 }
138 }
139
140 return true;
141}
142
143uint64_t ContainerDataStructure::get_total_elements(const std::vector<DataDimension>& dimensions)
144{
145 uint64_t total = 1;
146 for (const auto& dim : dimensions) {
147 total *= dim.size;
148 }
149 return total;
150}
151
152size_t ContainerDataStructure::get_dimension_index_for_role(const std::vector<DataDimension>& dimensions,
153 DataDimension::Role role) const
154{
155 auto expected_roles = get_expected_dimension_roles();
156
157 auto it = std::ranges::find(expected_roles, role);
158 if (it != expected_roles.end()) {
159 return std::distance(expected_roles.begin(), it);
160 }
161
162 for (size_t i = 0; i < dimensions.size(); ++i) {
163 if (dimensions[i].role == role) {
164 return i;
165 }
166 }
167
168 return SIZE_MAX;
169}
170
171uint64_t ContainerDataStructure::get_channel_count(const std::vector<DataDimension>& dimensions)
172{
173 for (const auto& dim : dimensions) {
174 if (dim.role == DataDimension::Role::CHANNEL) {
175 return dim.size;
176 }
177 }
178 return 1;
179}
180
181size_t ContainerDataStructure::get_frame_count(const std::vector<DataDimension>& dimensions)
182{
183 for (const auto& dim : dimensions) {
184 if (dim.role == DataDimension::Role::TIME) {
185 return dim.size;
186 }
187 }
188 return 1;
189}
190
191uint64_t ContainerDataStructure::get_samples_count(const std::vector<DataDimension>& dimensions)
192{
193 uint64_t time_size = 0;
194 uint64_t channel_size = 1;
195
196 for (const auto& dim : dimensions) {
197 if (dim.role == DataDimension::Role::TIME) {
198 time_size = dim.size;
199 } else if (dim.role == DataDimension::Role::CHANNEL) {
200 channel_size = dim.size;
201 }
202 }
203
204 return time_size * channel_size;
205}
206
207uint64_t ContainerDataStructure::get_component_count(const std::vector<DataDimension>& dimensions)
208{
209 for (const auto& dim : dimensions) {
210 if (dim.role == DataDimension::Role::CHANNEL
211 || dim.role == DataDimension::Role::DEPTH) {
212 return dim.size;
213 }
214 }
215 return 1;
216}
217
218uint64_t ContainerDataStructure::get_samples_count_per_channel(const std::vector<DataDimension>& dimensions)
219{
220 for (const auto& dim : dimensions) {
221 if (dim.role == DataDimension::Role::TIME) {
222 return dim.size;
223 }
224 }
225 return 0;
226}
227
228uint64_t ContainerDataStructure::get_pixels_count(const std::vector<DataDimension>& dimensions)
229{
230 uint64_t pixels = 1;
231 for (const auto& dim : dimensions) {
233 pixels *= dim.size;
234 }
235 }
236 return pixels;
237}
238
239uint64_t ContainerDataStructure::get_height(const std::vector<DataDimension>& dimensions)
240{
241 for (const auto& dim : dimensions) {
242 if (dim.role == DataDimension::Role::SPATIAL_Y) {
243 return dim.size;
244 }
245 }
246 return 0;
247}
248
249uint64_t ContainerDataStructure::get_width(const std::vector<DataDimension>& dimensions)
250{
251 for (const auto& dim : dimensions) {
252 if (dim.role == DataDimension::Role::SPATIAL_X) {
253 return dim.size;
254 }
255 }
256 return 0;
257}
258
259size_t ContainerDataStructure::get_frame_size(const std::vector<DataDimension>& dimensions)
260{
261 size_t frame_size = 1;
262 for (const auto& dim : dimensions) {
263 if (dim.role != DataDimension::Role::TIME) {
264 frame_size *= dim.size;
265 }
266 }
267 return frame_size;
268}
269
270}
const std::vector< float > * pixels
Definition Decoder.cpp:65
DataModality
Data modality types for cross-modal analysis.
Definition NDData.hpp:164
@ DEPTH_MAP
[height, width, components] - range/disparity image
@ AUDIO_MULTICHANNEL
Multi-channel audio.
@ SPECTRAL_2D
2D spectral data (time + frequency)
@ VIDEO_DEPTH
[frames, height, width, components] - streaming range data
@ 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:65
OrganizationStrategy
Data organization strategy for multi-channel/multi-frame data.
Definition NDData.hpp:75
@ 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:236
@ FREQUENCY
Spectral/frequency axis.
@ TIME
Temporal progression (samples, frames, steps)
@ DEPTH
Distance from the observation point (depth, disparity, range)
@ CHANNEL
Parallel streams (audio channels, color channels)
@ SPATIAL_X
Spatial X axis (images, tensors)