File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -1325,7 +1325,20 @@ def make_slice_selection(selection: Any) -> list[slice]:
13251325
13261326
13271327def decode_morton (z : int , chunk_shape : ChunkCoords ) -> ChunkCoords :
1328- out = [int (i ) for i in np .unravel_index (z , chunk_shape )]
1328+ # Inspired by compressed morton code as implemented in Neuroglancer
1329+ # https://github.com/google/neuroglancer/blob/master/src/neuroglancer/datasource/precomputed/volume.md#compressed-morton-code
1330+ bits = tuple (math .ceil (math .log2 (c )) for c in chunk_shape )
1331+ max_coords_bits = max (bits )
1332+ input_bit = 0
1333+ input_value = z
1334+ out = [0 ] * len (chunk_shape )
1335+
1336+ for coord_bit in range (max_coords_bits ):
1337+ for dim in range (len (chunk_shape )):
1338+ if coord_bit < bits [dim ]:
1339+ bit = (input_value >> input_bit ) & 1
1340+ out [dim ] |= bit << coord_bit
1341+ input_bit += 1
13291342 return tuple (out )
13301343
13311344
You can’t perform that action at this time.
0 commit comments