Skip to content

Commit

Permalink
feat: bbxo from ng bbox constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
supersergiy committed Jan 20, 2025
1 parent 54d185f commit df48fc6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/unit/geometry/test_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,7 @@ def test_transpose_global():
transposed = bbox.transposed(0, 1, local=False)
expected = BBox3D(bounds=((3, 5), (0, 1), (7, 25)))
assert transposed == expected


def test_from_ng_bbox():
...
14 changes: 14 additions & 0 deletions zetta_utils/geometry/bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Literal, Optional, Sequence, Union, cast

import attrs
from neuroglancer.viewer_state import AxisAlignedBoundingBoxAnnotation
from typeguard import typechecked

from zetta_utils import builder
Expand Down Expand Up @@ -689,6 +690,19 @@ def line_intersects(

return True

@staticmethod
def from_ng_bbox(
ng_bbox: AxisAlignedBoundingBoxAnnotation, base_resolution: Sequence[float]
) -> BBox3D:
point_a_nm = Vec3D(*ng_bbox.pointA).int() * Vec3D(*base_resolution)
point_b_nm = Vec3D(*ng_bbox.pointB).int() * Vec3D(*base_resolution)
start_coord = [min(point_a_nm[i], point_b_nm[i]) for i in range(3)]
end_coord = [max(point_a_nm[i], point_b_nm[i]) for i in range(3)]
bbox = BBox3D.from_coords(
start_coord=start_coord, end_coord=end_coord, resolution=[1, 1, 1]
)
return bbox


builder.register("BBox3D.from_slices")(BBox3D.from_slices)
builder.register("BBox3D.from_coords")(BBox3D.from_coords)
Expand Down

0 comments on commit df48fc6

Please sign in to comment.