Build VolumeData from selected grids over an explicit region.
236{
237 constexpr float k_transform_epsilon = 1e-5F;
238
239 const auto reference =
m_archive->grid_summary(indices.front());
240 for (size_t idx : indices) {
241 if (idx == indices.front()) {
242 continue;
243 }
244 const auto summary =
m_archive->grid_summary(idx);
245 const bool mismatched = glm::any(glm::greaterThan(
246 glm::abs(summary.voxel_size - reference.voxel_size), glm::vec3(k_transform_epsilon)))
247 || glm::any(glm::greaterThan(
248 glm::abs(summary.translation - reference.translation), glm::vec3(k_transform_epsilon)));
249 if (mismatched) {
251 "VolumeReader: grid '{}' has a different voxel size or translation than '{}', "
252 "its voxel indices are read directly against the shared region and will not be aligned",
253 summary.name, reference.name);
254 }
255 }
256
257 Kakshya::VolumeData result;
258 result.lattice = lattice;
259 result.fields.reserve(indices.size());
260
261 for (size_t idx : indices) {
262 const auto summary =
m_archive->grid_summary(idx);
263
264 Kakshya::VolumeField field;
265 field.name = summary.name;
266 field.semantics.value_class = class_from_token(
m_archive->grid_metadata(idx,
"class"));
267
269
270 if (summary.is_vector) {
271 field.semantics.variance = variance_from_token(
m_archive->grid_metadata(idx,
"vector_type"));
272
273 std::vector<glm::vec3>
values;
277 return std::nullopt;
278 }
279 field.values = std::move(
values);
280 } else {
281 std::vector<float>
values;
285 return std::nullopt;
286 }
287 field.values = std::move(
values);
288 }
289
292 "VolumeReader: grid '{}' is not float/vec3f, narrowing to {} lost precision in at least one value",
293 summary.name, summary.is_vector ? "vec3" : "float");
294 } else if (summary.narrowed) {
296 "VolumeReader: grid '{}' is not float/vec3f, narrowing to {} losslessly",
297 summary.name, summary.is_vector ? "vec3" : "float");
298 }
299
301 "VolumeReader: materialized '{}', {} cells", field.name, field.element_count());
302
303 result.fields.push_back(std::move(field));
304 }
305
306 if (result.fields.empty()) {
308 return std::nullopt;
309 }
310
311 if (!result.is_consistent()) {
312 set_error(
"Resulting VolumeData failed is_consistent()");
313 return std::nullopt;
314 }
315
316 return result;
317}
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::vector< std::byte > values
void set_error(std::string msg) const
std::unique_ptr< Detail::VDBArchive > m_archive
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.