Skip to content

Commit

Permalink
Merge pull request #642 from FZJ-INM1-BDA/fix_ng_fetching_voi_rounding
Browse files Browse the repository at this point in the history
Rounding scheme for neuroglancer fetching needs revision
  • Loading branch information
AhmetNSimsek authored Mar 7, 2025
2 parents e9e5f0e + dff053b commit 6baec97
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions siibra/volumes/providers/neuroglancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,7 @@ def fetch(self, voi: _boundingbox.BoundingBox = None, **kwargs):
if voi is None:
bbox_ = _boundingbox.BoundingBox((0, 0, 0), self.size, space=None)
else:
bbox_ = voi.transform(np.linalg.inv(self.affine))

for dim in range(3):
if bbox_.shape[dim] < 1:
logger.warning(
f"Bounding box in voxel space will be enlarged to by {self.res_mm[dim]} along axis {dim}."
)
bbox_.maxpoint[dim] = bbox_.maxpoint[dim] + self.res_mm[dim]
bbox_ = voi.transform(np.linalg.inv(self.affine), space=None)

# extract minimum and maximum the chunk indices to be loaded
gx0, gy0, gz0 = self._point_to_lower_chunk_idx(tuple(bbox_.minpoint))
Expand All @@ -559,8 +552,12 @@ def fetch(self, voi: _boundingbox.BoundingBox = None, **kwargs):
# exact bounding box requested, to cut off undesired borders
data_min = np.array([gx0, gy0, gz0]) * self.chunk_sizes
x0, y0, z0 = (np.array(bbox_.minpoint) - data_min).astype("int")
xd, yd, zd = np.ceil((np.array(bbox_.maxpoint))).astype(int) - np.floor((np.array(bbox_.minpoint))).astype(int)
xd, yd, zd = np.ceil(bbox_.maxpoint).astype(int) - np.floor(bbox_.minpoint).astype(int)
offset = tuple(bbox_.minpoint)
if voi is not None:
logger.debug(
f"Input: {voi.minpoint.coordinate}, {voi.maxpoint.coordinate}.\nVoxel space: {bbox_.minpoint.coordinate}, {bbox_.maxpoint.coordinate}"
)

# build the nifti image
trans = np.identity(4)[[2, 1, 0, 3], :] # zyx -> xyz
Expand Down

0 comments on commit 6baec97

Please sign in to comment.