MayaFlux 0.5.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 734 of file VDBArchive.cpp.

741{
742 if (!m_state->read_file_open || index >= m_state->read_file.num_grids) {
743 m_last_error = "read_dense_scalar: grid index out of range";
744 return false;
745 }
746 if (resolution.x == 0 || resolution.y == 0 || resolution.z == 0) {
747 m_last_error = "read_dense_scalar: zero resolution";
748 return false;
749 }
750
751 const tvdb_grid_t& grid = m_state->read_file.grids[index];
752 const tvdb_value_type_t vt = leaf_value_type(grid);
753
754 if (is_vector_type(vt)) {
755 const char* name = tvdb_grid_name(&m_state->read_file, index);
756 m_last_error = "read_dense_scalar: grid '" + std::string(name ? name : "") + "' is vector-typed";
757 return false;
758 }
759 const size_t elem_size = tvdb_value_type_size(vt);
760 if (elem_size == 0) {
761 m_last_error = "read_dense_scalar: grid has an unsupported leaf value type";
762 return false;
763 }
764
765 if (precision_lost) {
766 *precision_lost = false;
767 }
768
769 out.assign(static_cast<size_t>(resolution.x) * resolution.y * resolution.z, background);
770
771 DenseScalarCtx ctx {};
772 ctx.region_min = region_min;
773 ctx.region_max = region_min + glm::ivec3(resolution);
774 ctx.vt = vt;
775 ctx.elem_size = elem_size;
776 ctx.precision_lost = precision_lost;
777 ctx.out = &out;
778
779 tvdb_grid_visit_leaves(&grid, dense_scalar_visit, &ctx);
780 return true;
781}
std::vector< float > * out
bool * precision_lost
glm::ivec3 region_min
tvdb_value_type_t vt
size_t elem_size
std::string name
Definition VKDevice.cpp:143
uint32_t index
Definition VKDevice.cpp:142
std::string m_last_error
Set from the const read-path accessors too.
std::unique_ptr< State > m_state

References elem_size, index, m_last_error, m_state, name, out, precision_lost, region_min, and vt.