build_adjacency_graph

Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

build_adjacency_graph(node_result: HabitatNodeExtractionResult, labels: Tuple[int, ...], graph_kind: str, adjacency_connectivity: str = 'corner', adjacency_min_voxels: int = 10, edge_weight: Literal['none', 'distance', 'inverse_distance', 'contact_voxels'] = 'none', include_intra_edges: bool = False) → HabitatGraph[source]

Build a graph by connecting spatially adjacent habitat-region nodes.

Two nodes are connected when they share at least adjacency_min_voxels neighboring voxel pairs under the requested connectivity rule.

Handles both single-habitat (intra) and pairwise (inter) graphs, and supports face, edge, and corner connectivity.

Parameters:
  • node_result – Output from connected-region node extraction.

  • labels – One label for a single-habitat graph or two labels for a pairwise graph.

  • graph_kind – "single" or "pairwise".

  • adjacency_connectivity – Neighbor definition. Default "corner" is 8-conn in 2D / 26-conn in 3D. "face" is 4/6-conn; "edge" is 8/18-conn.

  • adjacency_min_voxels – Minimum adjacent voxel pair count required to create an edge. Must be >= 1. Default 10: an edge exists only when two regions are adjacent and share at least 10 contact voxels.

  • edge_weight – "contact_voxels" stores the voxel-pair count as the edge weight; "none" keeps an unweighted binary graph.

  • include_intra_edges – For pairwise graphs, also connect same-label node pairs that are spatially adjacent. Ignored for single-label graphs.

Returns:

Graph with adjacency-derived edges.

Return type:

HabitatGraph

Raises:

ValueError – If adjacency_min_voxels < 1 or labels is empty.