Detect data dimensions from a DataVariant.
This function analyzes the structure of the provided DataVariant and extracts dimension information, including size, stride, and semantic roles.
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
205
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}