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

◆ build_grid_2d_neighbors()

std::unordered_map< size_t, std::vector< size_t > > MayaFlux::Nodes::Network::NodeNetwork::build_grid_2d_neighbors ( size_t  width,
size_t  height 
)
staticprotected

Build neighbor map for GRID_2D topology.

Parameters
widthGrid width
heightGrid height
Returns
Map of node index to neighbor indices (4-connectivity)

Definition at line 694 of file ParticleNetwork.cpp.

695{
696 std::unordered_map<size_t, std::vector<size_t>> neighbors;
697
698 for (size_t y = 0; y < height; ++y) {
699 for (size_t x = 0; x < width; ++x) {
700 size_t idx = y * width + x;
701 std::vector<size_t> node_neighbors;
702
703 if (x > 0) {
704 node_neighbors.push_back(idx - 1);
705 }
706 if (x < width - 1) {
707 node_neighbors.push_back(idx + 1);
708 }
709 if (y > 0) {
710 node_neighbors.push_back(idx - width);
711 }
712 if (y < height - 1) {
713 node_neighbors.push_back(idx + width);
714 }
715
716 if (!node_neighbors.empty()) {
717 neighbors[idx] = std::move(node_neighbors);
718 }
719 }
720 }
721
722 return neighbors;
723}

Referenced by MayaFlux::Nodes::Network::ParticleNetwork::initialize().

+ Here is the caller graph for this function: