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

◆ relaxation_grid_positions()

bool MayaFlux::IO::relaxation_grid_positions ( const std::shared_ptr< Buffers::RelaxationGridBuffer > &  grid,
float  extent,
std::vector< glm::vec3 > &  positions,
std::vector< uint64_t > &  ids 
)

Generate the fixed grid positions and cell ids a RelaxationGridBuffer's cells occupy, for feeding SpatialCache::write() with PrimitiveTopology::POINT_LIST.

Matches exactly the row-major, cell-center-sampled layout its own emit shaders use (data/shaders/relax_vertex_emit.comp, relax_scalar_emit.comp): cell (col, row) at linear index row*width+col samples at ((col+0.5)/width, (row+0.5)/height), remapped to [-extent, extent] on both axes, z always 0.

Positions and ids are fixed for a given width/height/extent: a RelaxationGridBuffer's topology never changes generation to generation, only its cell state does (obtained separately via RelaxationGridBuffer::request_snapshot()/snapshot_source(), whose raw bytes only the caller can correctly reinterpret, since state format varies by rule: a single float, a uint32 automaton state, a vec2 reaction-diffusion pair, or anything else a rule shader defines). Call once and reuse the result across every sample of a capture rather than regenerating it per frame.

ids are the cell's own linear index, so a consumer can track one cell's identity across samples even though every other field about it changes generation to generation.

Parameters
gridSource buffer, for width/height.
extentNDC half-span. Match whatever was set via RelaxationEmitProcessor::set_extent(); default 1.0 matches RelaxationEmitProcessor::EmitParams's own default.
positionsOutput, resized to grid->get_cell_count().
idsOutput, resized to grid->get_cell_count().
Returns
False if grid is null; positions/ids are left untouched in that case.

Definition at line 123 of file SpatialExport.cpp.

128{
129 if (!grid) {
130 MF_ERROR(Journal::Component::IO, Journal::Context::FileIO,
131 "relaxation_grid_positions: null grid");
132 return false;
133 }
134
135 const uint32_t width = grid->get_grid_width();
136 const uint32_t height = grid->get_grid_height();
137 const uint32_t cell_count = grid->get_cell_count();
138
139 positions.resize(cell_count);
140 ids.resize(cell_count);
141
142 for (uint32_t i = 0; i < cell_count; ++i) {
143 const uint32_t ix = i % width;
144 const uint32_t iy = i / width;
145
146 const float fx = (static_cast<float>(ix) + 0.5F) / static_cast<float>(width);
147 const float fy = (static_cast<float>(iy) + 0.5F) / static_cast<float>(height);
148
149 positions[i] = glm::vec3((fx * 2.0F - 1.0F) * extent, (fy * 2.0F - 1.0F) * extent, 0.0F);
150 ids[i] = i;
151 }
152
153 return true;
154}
#define MF_ERROR(comp, ctx,...)
uint32_t width
uint32_t height

References MayaFlux::Journal::FileIO, height, MayaFlux::Journal::IO, MF_ERROR, and width.

Referenced by MayaFlux::IO::RelaxationGridCapture::RelaxationGridCapture().

+ Here is the caller graph for this function: