@@ -546,7 +546,7 @@ def cpu_fusion(
546546
547547 total = time .perf_counter () - t_total0
548548 # print(f"[cpu_fusion] pid={os.getpid()} DONE blend={t_blend:.3f}s write={t_write:.3f}s total={total:.3f}s", flush=True)
549-
549+
550550class FusionVolumeSampler (cq .VolumeSampler ):
551551 def __init__ (
552552 self ,
@@ -622,8 +622,8 @@ def __init__(
622622 for t_id , o_ids in tile_to_overlap_ids .items ():
623623 # This is the base nullspace
624624 t_aabb = list (self .tile_aabbs [t_id ])
625- # t_aabb[0] = 0
626- # t_aabb[1] = output_volume_size[0]
625+ t_aabb [0 ] = 0
626+ t_aabb [1 ] = output_volume_size [0 ]
627627
628628 for o_id in o_ids :
629629 o_aabb = modified_overlaps [o_id ]
@@ -696,36 +696,34 @@ def __init__(
696696
697697 def _check_true_collision (
698698 self ,
699- cell_box : geometry .AABB ,
700- transform_list : list [geometry .Transform ],
699+ cell_box : " geometry.AABB" ,
700+ transform_list : list [" geometry.Transform" ],
701701 src_vol_shape_zyx : tuple [int , int , int ],
702702 ) -> bool :
703- # Build the 8 corners (zyx) with +/-0.5 offsets
704703 z_min , z_max , y_min , y_max , x_min , x_max = cell_box
704+
705+ # sample at voxel centers: (min+0.5, max-0.5) on each axis
705706 zs = np .array ([z_min + 0.5 , z_max - 0.5 ], dtype = np .float32 )
706707 ys = np .array ([y_min + 0.5 , y_max - 0.5 ], dtype = np .float32 )
707708 xs = np .array ([x_min + 0.5 , x_max - 0.5 ], dtype = np .float32 )
708709
709- cell_box_pts = np .array (
710- [[z , y , x ] for z in zs for y in ys for x in xs ],
711- dtype = np .float32
712- ) # (8, 3)
710+ # 2x2x2 grid of corners, shape (2,2,2,3) in ZYX order
711+ z_grid , y_grid , x_grid = np .meshgrid (zs , ys , xs , indexing = "ij" )
712+ cell_box_pts = np .stack ([z_grid , y_grid , x_grid ], axis = - 1 ).astype (np .float32 )
713713
714- # Apply origin
715- cell_box_pts += np .asarray (self .output_volume_origin , dtype = np .float32 ). reshape ( 1 , 3 )
714+ # move into output/global space
715+ cell_box_pts = cell_box_pts + np .asarray (self .output_volume_origin , dtype = np .float32 )
716716
717- # Apply inverse transforms (NumPy)
717+ # apply inverse transforms in reverse order
718718 for tfm in reversed (transform_list ):
719+ # assumes tfm.backward can accept numpy arrays; if not, see note below
719720 cell_box_pts = tfm .backward_np (cell_box_pts )
720721
721- # AABB of transformed points (zyx)
722- z0 , z1 = float (cell_box_pts [:, 0 ].min ()), float (cell_box_pts [:, 0 ].max ())
723- y0 , y1 = float (cell_box_pts [:, 1 ].min ()), float (cell_box_pts [:, 1 ].max ())
724- x0 , x1 = float (cell_box_pts [:, 2 ].min ()), float (cell_box_pts [:, 2 ].max ())
725- cell_box_src : geometry .AABB = (z0 , z1 , y0 , y1 , x0 , x1 )
722+ # compute AABB in source space
723+ cell_box_src : "geometry.AABB" = geometry .aabb_3d_np (cell_box_pts )
726724
727725 sv_z , sv_y , sv_x = src_vol_shape_zyx
728- aabb_src : geometry .AABB = (0 , sv_z , 0 , sv_y , 0 , sv_x )
726+ aabb_src : " geometry.AABB" = (0 , sv_z , 0 , sv_y , 0 , sv_x )
729727
730728 return utils .check_collision (cell_box_src , aabb_src )
731729
@@ -788,4 +786,4 @@ def __iter__(self):
788786 stride_condition = (cell_num % self .stride == self .start )
789787
790788 if true_overlap_condition and stride_condition :
791- yield curr_cell , src_ids
789+ yield curr_cell , src_ids
0 commit comments