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

◆ read_dense_scalar()

bool MayaFlux::IO::Detail::VDBArchive::read_dense_scalar ( size_t index,
const glm::ivec3 & region_min,
const glm::uvec3 & resolution,
float background,
std::vector< float > & out,
bool * precision_lost = nullptr ) const

Materialize a scalar grid's cells over an explicit region.

region_min and resolution are expressed in the grid's own voxel-index space — the same space active_min/active_max in grid_summary() use. A cell not covered by any active leaf, and a cell whose index falls outside the region entirely, both take background. Output is resized to resolution.x*y*z elements and written x-fastest, z-slowest, matching Lattice3D and VolumeField's convention.

A grid whose leaf value type is not float is converted per-element via MayaFlux::try_convert; check grid_summary().narrowed beforehand to know whether that happened at all, or pass precision_lost to learn whether it happened losslessly. Every element that round-trips through float and back to the source type unchanged leaves it false; a single element that doesn't sets it true for the whole call. half is the one source type never marked lossy — float has strictly more precision in both exponent and mantissa, so widening it is always exact.

Parameters
precision_lostSet to whether any narrowed element lost precision. Cleared to false at the start of the call if non-null; left untouched by a null pointer.
Returns
False if index is out of range, the grid is vector-typed, or resolution has a zero axis. Call last_error() for detail.

Definition at line 700 of file VDBArchive.cpp.

707{
708 if (!m_state->read_file_open || index >= m_state->read_file.num_grids) {
709 m_last_error = "read_dense_scalar: grid index out of range";
710 return false;
711 }
712 if (resolution.x == 0 || resolution.y == 0 || resolution.z == 0) {
713 m_last_error = "read_dense_scalar: zero resolution";
714 return false;
715 }
716
717 const tvdb_grid_t& grid = m_state->read_file.grids[index];
718 const tvdb_value_type_t vt = leaf_value_type(grid);
719
720 if (is_vector_type(vt)) {
721 const char* name = tvdb_grid_name(&m_state->read_file, index);
722 m_last_error = "read_dense_scalar: grid '" + std::string(name ? name : "") + "' is vector-typed";
723 return false;
724 }
725 const size_t elem_size = tvdb_value_type_size(vt);
726 if (elem_size == 0) {
727 m_last_error = "read_dense_scalar: grid has an unsupported leaf value type";
728 return false;
729 }
730
731 if (precision_lost) {
732 *precision_lost = false;
733 }
734
735 out.assign(static_cast<size_t>(resolution.x) * resolution.y * resolution.z, background);
736
737 DenseScalarCtx ctx {};
738 ctx.region_min = region_min;
739 ctx.region_max = region_min + glm::ivec3(resolution);
740 ctx.vt = vt;
741 ctx.elem_size = elem_size;
742 ctx.precision_lost = precision_lost;
743 ctx.out = &out;
744
745 tvdb_grid_visit_leaves(&grid, dense_scalar_visit, &ctx);
746 return true;
747}
std::string m_last_error
Set from the const read-path accessors too.
std::unique_ptr< State > m_state

References m_last_error, and m_state.