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

◆ build_grid_3d_neighbors()

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

Build neighbor map for GRID_3D topology.

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

Definition at line 709 of file ParticleNetwork.cpp.

710{
711 std::unordered_map<size_t, std::vector<size_t>> neighbors;
712
713 for (size_t z = 0; z < depth; ++z) {
714 for (size_t y = 0; y < height; ++y) {
715 for (size_t x = 0; x < width; ++x) {
716 size_t idx = z * (width * height) + y * width + x;
717 std::vector<size_t> node_neighbors;
718
719 if (x > 0) {
720 node_neighbors.push_back(idx - 1);
721 }
722 if (x < width - 1) {
723 node_neighbors.push_back(idx + 1);
724 }
725
726 if (y > 0) {
727 node_neighbors.push_back(idx - width);
728 }
729 if (y < height - 1) {
730 node_neighbors.push_back(idx + width);
731 }
732
733 if (z > 0) {
734 node_neighbors.push_back(idx - (width * height));
735 }
736 if (z < depth - 1) {
737 node_neighbors.push_back(idx + (width * height));
738 }
739
740 if (!node_neighbors.empty()) {
741 neighbors[idx] = std::move(node_neighbors);
742 }
743 }
744 }
745 }
746
747 return neighbors;
748}