@@ -137,7 +137,12 @@ def create_nx_graph_from_tri_coords(coords_rad: np.ndarray, node_ordering: np.nd
137137 return graph
138138
139139
140- def add_edges_hop_1 (nodes_coords_rad , resolutions : list [int ], node_ordering : list [int ]) -> np .ndarray :
140+ def add_edges_hop_1 (
141+ nodes_coords_rad ,
142+ resolutions : list [int ],
143+ node_ordering : list [int ],
144+ area_mask_builder : KNNAreaMaskBuilder | None = None ,
145+ ) -> np .ndarray :
141146 """Adds edges for x_hops = 1 relying on trimesh only."""
142147
143148 hop_1_edges = []
@@ -154,9 +159,16 @@ def add_edges_hop_1(nodes_coords_rad, resolutions: list[int], node_ordering: lis
154159 multiscale_edges = np .transpose (np .concatenate (hop_1_edges , axis = 0 ), (1 , 0 ))
155160
156161 # Map the edges to the node ordering
157- inverse_ordering = np .empty_like (node_ordering )
158- inverse_ordering [node_ordering ] = np .arange (len (node_ordering ))
159- multiscale_edges = inverse_ordering [multiscale_edges ]
162+ if area_mask_builder is not None :
163+ inverse_ordering = np .full (coords_rad .shape [0 ], - 1 , dtype = int )
164+ inverse_ordering [node_ordering ] = np .arange (len (node_ordering ))
165+ updated_edges = inverse_ordering [multiscale_edges ]
166+ valid_edges_mask = np .all (updated_edges >= 0 , axis = 0 )
167+ multiscale_edges = updated_edges [:, valid_edges_mask ]
168+ else :
169+ inverse_ordering = np .empty_like (node_ordering )
170+ inverse_ordering [node_ordering ] = np .arange (len (node_ordering ))
171+ multiscale_edges = inverse_ordering [multiscale_edges ]
160172
161173 LOGGER .debug ("multiscale_edges_shape: %s" , multiscale_edges .shape )
162174 return multiscale_edges
0 commit comments