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

◆ from_network()

std::optional< SpatialHashConfig > MayaFlux::Buffers::SpatialHashConfig::from_network ( const std::shared_ptr< NetworkGeometryBuffer > &  buffer,
float  cell_size 
)
static

Build hash grid parameters from a NetworkGeometryBuffer's network and its primary operator.

Parameters
bufferBuffer whose network supplies particle_count, vertex layout and bounds. Reads the layout from the network's own GraphicsOperator (e.g. PhysicsOperator::get_vertex_layout), not from the buffer's cached copy: that copy is written by NetworkGeometryProcessor during upload and unset before the first cycle, whereas the operator's own layout is valid the moment create_operator<PhysicsOperator>() (or equivalent) returns. Callable synchronously right after setup, with no need to wait for a processing cycle.
cell_sizeGrid cell size. Ordinarily PhysicsOperator's own interaction radius when the network is physics-driven; there is no generic source for this, since not every ParticleNetwork operator has an equivalent concept, so the caller supplies it directly.
Returns
Populated config, or nullopt when the buffer's network is neither a ParticleNetwork nor a PointCloudNetwork, its primary operator is not a GraphicsOperator (or none is set), that operator's layout carries no word-aligned position attribute, or cell_size is not positive.

Definition at line 17 of file SpatialHashProcessor.cpp.

19{
20 if (cell_size <= 0.0F) {
22 "SpatialHashConfig::from_network: cell_size {} is not positive", cell_size);
23 return std::nullopt;
24 }
25
26 const auto network = buffer->get_network();
27
28 Kinesis::SamplerBounds bounds;
29 if (auto particle_net = std::dynamic_pointer_cast<Nodes::Network::ParticleNetwork>(network)) {
30 bounds = particle_net->get_bounds();
31 } else if (auto cloud_net = std::dynamic_pointer_cast<Nodes::Network::PointCloudNetwork>(network)) {
32 bounds = cloud_net->get_bounds();
33 } else {
35 "SpatialHashConfig::from_network: buffer's network is neither a ParticleNetwork "
36 "nor a PointCloudNetwork");
37 return std::nullopt;
38 }
39
40 auto* graphics_op = dynamic_cast<Nodes::Network::GraphicsOperator*>(network->get_operator());
41 if (!graphics_op) {
43 "SpatialHashConfig::from_network: network's primary operator is not a "
44 "GraphicsOperator, or none is set. create_operator<PhysicsOperator>() (or "
45 "equivalent) must run before this.");
46 return std::nullopt;
47 }
48
49 const auto layout = graphics_op->get_vertex_layout();
50
51 if (layout.stride_bytes == 0 || layout.stride_bytes % 4 != 0) {
53 "SpatialHashConfig::from_network: stride {} is not a nonzero multiple of 4",
54 layout.stride_bytes);
55 return std::nullopt;
56 }
57
58 const auto position_offset = layout.find_word_offset(Kakshya::DataModality::VERTEX_POSITIONS_3D);
59 if (!position_offset.has_value()) {
61 "SpatialHashConfig::from_network: vertex layout carries no word-aligned "
62 "position attribute");
63 return std::nullopt;
64 }
65
66 const glm::vec3 extent = bounds.max - bounds.min;
67
68 const glm::uvec3 dims {
69 std::max(1U, static_cast<uint32_t>(std::ceil(extent.x / cell_size))),
70 std::max(1U, static_cast<uint32_t>(std::ceil(extent.y / cell_size))),
71 std::max(1U, static_cast<uint32_t>(std::ceil(extent.z / cell_size))),
72 };
73
74 return SpatialHashConfig {
75 .grid_min = bounds.min,
76 .grid_dims = dims,
77 .cell_size = cell_size,
78 .particle_count = static_cast<uint32_t>(graphics_op->get_vertex_count()),
79 .stride_words = layout.stride_bytes / 4,
80 .position_word_offset = *position_offset,
81 };
82}
#define MF_ERROR(comp, ctx,...)
Core::GlobalNetworkConfig network
Definition Config.cpp:39
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, cell_size, grid_min, MayaFlux::Kinesis::SamplerBounds::max, MF_ERROR, MayaFlux::Kinesis::SamplerBounds::min, network, stride_words, and MayaFlux::Kakshya::VERTEX_POSITIONS_3D.

Referenced by MayaFlux::Buffers::NetworkGeometryBuffer::wire_field_operators().

+ Here is the caller graph for this function: