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

◆ accumulate() [1/2]

void MayaFlux::Buffers::VolumeGridBuffer::accumulate ( const std::string &  name,
const Kinesis::SpatialField field 
)

Add sampled values into a scalar field.

Parameters
nameField name. Must have stride sizeof(float).
fieldSampled at each cell centre in world space and added to whatever the field already holds.

Blocking. Reads the current read slot to host memory, adds, and writes back, so it costs a full round trip at the lattice's byte size. Intended for authored injection on a coarse clock, not as a chain stage.

Definition at line 539 of file VolumeGridBuffer.cpp.

540{
541 const auto* decl = find_field(name, "accumulate");
542 if (!decl) {
543 return;
544 }
545
546 if (decl->stride_bytes != sizeof(float)) {
548 "VolumeGridBuffer::accumulate: field '{}' has stride {}, SpatialField requires {}",
549 name, decl->stride_bytes, sizeof(float));
550 return;
551 }
552
553 const glm::uvec3 res = m_lattice.resolution;
554 std::vector<float> values(m_lattice.cell_count());
555
556 read_field(name, values.data(), values.size() * sizeof(float));
557
558 size_t i = 0;
559 for (uint32_t z = 0; z < res.z; ++z) {
560 for (uint32_t y = 0; y < res.y; ++y) {
561 for (uint32_t x = 0; x < res.x; ++x) {
562 values[i++] += field(m_lattice.cell_center({ x, y, z }));
563 }
564 }
565 }
566
567 seed_raw(name, values.data(), values.size() * sizeof(float));
568}
#define MF_ERROR(comp, ctx,...)
const Field * find_field(const std::string &name, const char *context) const
Resolve a field by name.
void read_field(const std::string &name, void *data, size_t size)
Copy the current read slot of a field to host memory.
void seed_raw(const std::string &name, const void *data, size_t size)
Write initial values into a field from raw host memory.
@ BufferManagement
Buffer Management (Buffers::BufferManager, creating buffers)
@ Buffers
Buffers, Managers, processors and processing chains.
size_t cell_count() const noexcept
Total cell count.
Definition Lattice.hpp:36
glm::uvec3 resolution
Cell count per axis. Zero on any axis is invalid.
Definition Lattice.hpp:26
glm::vec3 cell_center(const glm::uvec3 &c) const noexcept
World position of a cell's centre.
Definition Lattice.hpp:70

References MayaFlux::Journal::BufferManagement, MayaFlux::Journal::Buffers, MayaFlux::Kinesis::Lattice3D::cell_center(), MayaFlux::Kinesis::Lattice3D::cell_count(), find_field(), m_lattice, MF_ERROR, read_field(), MayaFlux::Kinesis::Lattice3D::resolution, and seed_raw().

+ Here is the call graph for this function: