Reconstruct DataVariant from double data and structure info.
interleave_channels (called before this function) produces sample-major layout: [x0,y0,z0, x1,y1,z1, ...]. Eigen default storage is column-major. With rows=components and cols=elements, Eigen::Map reads column 0 as [x0,y0,z0], column 1 as [x1,y1,z1], which matches the interleaved order.
134{
135 if (double_data.empty()) {
137 }
138
140 structure_info.modality, structure_info.original_type);
141
143 if (structure_info.original_type == std::type_index(typeid(std::vector<float>))) {
144 std::vector<float> float_data;
145 float_data.reserve(double_data.size());
146 std::ranges::transform(double_data, std::back_inserter(float_data),
147 [](double v) { return static_cast<float>(v); });
149 }
150
151 if (structure_info.original_type == std::type_index(typeid(std::vector<uint8_t>))) {
152 std::vector<uint8_t> u8_data;
153 u8_data.reserve(double_data.size());
154 std::ranges::transform(double_data, std::back_inserter(u8_data),
155 [](double v) { return static_cast<uint8_t>(std::clamp(v, 0.0, 255.0)); });
157 }
158
159 if (structure_info.original_type == std::type_index(typeid(std::vector<uint16_t>))) {
160 std::vector<uint16_t> u16_data;
161 u16_data.reserve(double_data.size());
162 std::ranges::transform(double_data, std::back_inserter(u16_data),
163 [](double v) { return static_cast<uint16_t>(std::clamp(v, 0.0, 65535.0)); });
165 }
166
167 if (structure_info.original_type == std::type_index(typeid(std::vector<uint32_t>))) {
168 std::vector<uint32_t> u32_data;
169 u32_data.reserve(double_data.size());
170 std::ranges::transform(double_data, std::back_inserter(u32_data),
171 [](double v) { return static_cast<uint32_t>(std::max(v, 0.0)); });
173 }
174
176 }
177
179
180 if (double_data.size() % rows != 0) {
182 }
183
184
185
186
187
188
189
190
191 auto r = static_cast<Eigen::Index>(rows);
192 auto c = static_cast<Eigen::Index>(double_data.size() / rows);
193
194 Eigen::Map<const Eigen::MatrixXd> mapped(double_data.data(), r, c);
195
197}
Kakshya::DataVariant from_eigen_matrix(const Eigen::MatrixXd &matrix, MatrixInterpretation interpretation=MatrixInterpretation::AUTO)
Convenience function for direct conversion.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
@ SCALAR
Single row → scalar values.
size_t interpretation_row_count(Kakshya::MatrixInterpretation interp)
Kakshya::MatrixInterpretation modality_to_interpretation(Kakshya::DataModality modality, std::type_index original_type)