MayaFlux 0.1.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::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 677 of file ParticleNetwork.cpp.

678{
679 std::unordered_map<size_t, std::vector<size_t>> neighbors;
680
681 for (size_t y = 0; y < height; ++y) {
682 for (size_t x = 0; x < width; ++x) {
683 size_t idx = y * width + x;
684 std::vector<size_t> node_neighbors;
685
686 if (x > 0) {
687 node_neighbors.push_back(idx - 1);
688 }
689 if (x < width - 1) {
690 node_neighbors.push_back(idx + 1);
691 }
692 if (y > 0) {
693 node_neighbors.push_back(idx - width);
694 }
695 if (y < height - 1) {
696 node_neighbors.push_back(idx + width);
697 }
698
699 if (!node_neighbors.empty()) {
700 neighbors[idx] = std::move(node_neighbors);
701 }
702 }
703 }
704
705 return neighbors;
706}

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

+ Here is the caller graph for this function: