MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ detect_data_dimensions() [1/3]

std::vector< Kakshya::DataDimension > MayaFlux::Kakshya::detect_data_dimensions ( const DataVariant data)

Detect data dimensions from a DataVariant.

Parameters
dataDataVariant to analyze
Returns
Vector of DataDimension descriptors

This function analyzes the structure of the provided DataVariant and extracts dimension information, including size, stride, and semantic roles.

Definition at line 184 of file DataUtils.cpp.

185{
186 std::cerr << "Inferring structure from single DataVariant...\n"
187 << "This is not advisable as the method makes naive assumptions that can lead to massive computational errors\n"
188 << "If the variant is part of a container, region, or segment, please use the appropriate method instead.\n"
189 << "If the variant is part of a vector, please use infer_from_data_variant_vector instead.\n"
190 << "If you are sure you want to proceed, please ignore this warning.\n";
191
192 return std::visit([](const auto& vec) -> std::vector<DataDimension> {
193 using ValueType = typename std::decay_t<decltype(vec)>::value_type;
194
195 std::vector<DataDimension> dims;
196
197 if constexpr (DecimalData<ValueType>) {
198 dims.emplace_back(DataDimension::time(vec.size()));
199
200 } else if constexpr (ComplexData<ValueType>) {
201 dims.emplace_back(DataDimension::frequency(vec.size()));
202
203 } else if constexpr (IntegerData<ValueType>) {
204 // uint8_t, uint16_t, uint32_t -> flattened 2D (images typically)
205 // Need to guess reasonable 2D dimensions from 1D size
206 uint64_t total_size = vec.size();
207
208 if (total_size == 0) {
209 dims.emplace_back(DataDimension::spatial(0, 'x'));
210 dims.emplace_back(DataDimension::spatial(0, 'y'));
211 } else {
212 auto sqrt_size = static_cast<uint64_t>(std::sqrt(total_size));
213 if (sqrt_size * sqrt_size == total_size) {
214 dims.emplace_back(DataDimension::spatial(sqrt_size, 'x'));
215 dims.emplace_back(DataDimension::spatial(sqrt_size, 'y'));
216 } else {
217 uint64_t width = sqrt_size;
218 uint64_t height = total_size / width;
219 while (width * height != total_size && width > 1) {
220 width--;
221 height = total_size / width;
222 }
223 dims.emplace_back(DataDimension::spatial(height, 'y'));
224 dims.emplace_back(DataDimension::spatial(width, 'x'));
225 }
226 }
227 } else if constexpr (GlmData<ValueType>) {
228 constexpr size_t components = glm_component_count<ValueType>();
229 DataDimension::Role role = DataDimension::Role::CUSTOM;
230
231 if constexpr (GlmVec2Type<ValueType>) {
232 role = DataDimension::Role::UV;
233 } else if constexpr (GlmVec3Type<ValueType>) {
234 role = DataDimension::Role::POSITION;
235 } else if constexpr (GlmVec4Type<ValueType>) {
236 role = DataDimension::Role::COLOR;
237 } else if constexpr (GlmMatrixType<ValueType>) {
238 role = DataDimension::Role::CUSTOM;
239 }
240
241 dims.push_back(DataDimension::grouped(
242 "glm_structured_data",
243 static_cast<uint64_t>(vec.size()),
244 static_cast<uint8_t>(components),
245 role));
246 } else {
247 dims.emplace_back(DataDimension::time(vec.size()));
248 }
249
250 return dims;
251 },
252 data);
253}

References MayaFlux::Kakshya::DataDimension::COLOR, MayaFlux::Kakshya::DataDimension::CUSTOM, MayaFlux::Kakshya::DataDimension::frequency(), MayaFlux::Kakshya::DataDimension::grouped(), MayaFlux::Kakshya::DataDimension::POSITION, MayaFlux::Kakshya::DataDimension::spatial(), MayaFlux::Kakshya::DataDimension::time(), and MayaFlux::Kakshya::DataDimension::UV.

Referenced by MayaFlux::Yantra::infer_from_data_variant(), and MayaFlux::Yantra::infer_from_data_variant_vector().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: