Build neighbor map for GRID_3D topology.
727{
728 std::unordered_map<size_t, std::vector<size_t>> neighbors;
729
730 for (size_t z = 0; z < depth; ++z) {
731 for (size_t y = 0; y < height; ++y) {
732 for (size_t x = 0; x < width; ++x) {
733 size_t idx = z * (width * height) + y * width + x;
734 std::vector<size_t> node_neighbors;
735
736 if (x > 0) {
737 node_neighbors.push_back(idx - 1);
738 }
739 if (x < width - 1) {
740 node_neighbors.push_back(idx + 1);
741 }
742
743 if (y > 0) {
744 node_neighbors.push_back(idx - width);
745 }
746 if (y < height - 1) {
747 node_neighbors.push_back(idx + width);
748 }
749
750 if (z > 0) {
751 node_neighbors.push_back(idx - (width * height));
752 }
753 if (z < depth - 1) {
754 node_neighbors.push_back(idx + (width * height));
755 }
756
757 if (!node_neighbors.empty()) {
758 neighbors[idx] = std::move(node_neighbors);
759 }
760 }
761 }
762 }
763
764 return neighbors;
765}