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.
128{
129 if (double_data.empty()) {
131 }
132
134 structure_info.modality, structure_info.original_type);
135
137 if (structure_info.original_type == std::type_index(typeid(std::vector<float>))) {
138 std::vector<float> float_data;
139 float_data.reserve(double_data.size());
140 std::ranges::transform(double_data, std::back_inserter(float_data),
141 [](double v) { return static_cast<float>(v); });
143 }
144
145 if (structure_info.original_type == std::type_index(typeid(std::vector<uint8_t>))) {
146 std::vector<uint8_t> u8_data;
147 u8_data.reserve(double_data.size());
148 std::ranges::transform(double_data, std::back_inserter(u8_data),
149 [](double v) { return static_cast<uint8_t>(std::clamp(v, 0.0, 255.0)); });
151 }
152
153 if (structure_info.original_type == std::type_index(typeid(std::vector<uint16_t>))) {
154 std::vector<uint16_t> u16_data;
155 u16_data.reserve(double_data.size());
156 std::ranges::transform(double_data, std::back_inserter(u16_data),
157 [](double v) { return static_cast<uint16_t>(std::clamp(v, 0.0, 65535.0)); });
159 }
160
161 if (structure_info.original_type == std::type_index(typeid(std::vector<uint32_t>))) {
162 std::vector<uint32_t> u32_data;
163 u32_data.reserve(double_data.size());
164 std::ranges::transform(double_data, std::back_inserter(u32_data),
165 [](double v) { return static_cast<uint32_t>(std::max(v, 0.0)); });
167 }
168
170 }
171
173
174 if (double_data.size() % rows != 0) {
176 }
177
178
179
180
181
182
183
184
185 auto r = static_cast<Eigen::Index>(rows);
186 auto c = static_cast<Eigen::Index>(double_data.size() / rows);
187
188 Eigen::Map<const Eigen::MatrixXd> mapped(double_data.data(), r, c);
189
191}
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)