14 print(f
"Reading {input_file}...")
16 sdf_3d, origin, spacing = pnm.SDFReader.read_vti(input_file)
20 print(f
"Grid Shape (Nz, Ny, Nx): {shape}")
22 print(
"Running Segmentation...")
24 segmentation_flat = pnm.segment_volume(sdf_3d, spacing)
27 seg_3d = np.array(segmentation_flat, dtype=np.int32).reshape(shape)
30 unique_labels = np.unique(seg_3d)
31 pores = unique_labels[unique_labels > 0]
32 solids = unique_labels[unique_labels < 0]
34 print(f
"Total Labels: {len(unique_labels)}")
35 print(f
"Pore IDs: {len(pores)}")
36 print(f
"Solid IDs: {len(solids)}")
39 print(f
"Saving segmented volume to {output_file}...")
41 fields={
"Labels": seg_3d,
"SDF": sdf_3d},
45 print(
"Extracting Topology...")
48 connections = pnm.extract_topology_gpu(segmentation_flat, shape[::-1])
49 print(f
"Found {len(connections)} connections.")
51 with open(edge_file,
"w")
as f:
52 for u, v
in connections:
54 print(f
"Saved {edge_file}")