@@ -118,22 +118,35 @@ def fetch(
118
118
119
119
return result
120
120
121
- @property
122
- def boundingbox (self ):
121
+ def get_boundingbox (self , clip = False , background = 0 ) -> "_boundingbox.BoundingBox" :
123
122
"""
124
123
Return the bounding box in physical coordinates
125
124
of the union of fragments in this neuroglancer volume.
126
125
"""
127
126
bbox = None
128
127
for frag in self ._fragments .values ():
129
- next_bbox = _boundingbox .BoundingBox ((0 , 0 , 0 ), frag .shape , space = None ) \
130
- .transform (frag .affine )
128
+ if len (frag .shape ) > 3 :
129
+ logger .warning (
130
+ f"N-D Neuroglancer volume has shape { frag .shape } , but "
131
+ f"bounding box considers only { frag .shape [:3 ]} "
132
+ )
133
+ if clip :
134
+ img = frag .fetch ()
135
+ bounds = _boundingbox .BoundingBox ._determine_bounds (np .asanyarray (img .dataobj ), background )
136
+ next_bbox = _boundingbox .BoundingBox (
137
+ bounds [:3 , 0 ], bounds [:3 , 1 ], space = None
138
+ )
139
+ else :
140
+ shape = frag .shape [:3 ]
141
+ next_bbox = _boundingbox .BoundingBox (
142
+ (0 , 0 , 0 ), shape , space = None
143
+ ).transform (frag .affine )
131
144
bbox = next_bbox if bbox is None else bbox .union (next_bbox )
132
145
return bbox
133
146
134
147
def _merge_fragments (self ) -> nib .Nifti1Image :
135
148
# TODO this only performs nearest neighbor interpolation, optimized for float types.
136
- bbox = self .boundingbox
149
+ bbox = self .get_boundingbox ( clip = False , background = 0.0 )
137
150
num_conflicts = 0
138
151
result = None
139
152
@@ -486,10 +499,9 @@ def __init__(self, resource: Union[str, dict], volume=None):
486
499
def _url (self ) -> Union [str , Dict [str , str ]]:
487
500
return self ._init_url
488
501
489
- @property
490
- def boundingbox (self ) -> _boundingbox .BoundingBox :
502
+ def get_boundingbox (self , clip = False , background = 0.0 ) -> '_boundingbox.BoundingBox' :
491
503
raise NotImplementedError (
492
- f"Fast bounding box access to { self .__class__ .__name__ } objects not yet implemented."
504
+ f"Bounding box access to { self .__class__ .__name__ } objects not yet implemented."
493
505
)
494
506
495
507
def _get_fragment_info (self , meshindex : int ) -> Dict [str , Tuple [str , ]]:
0 commit comments