Skip to content

Commit

Permalink
If clearing_bbox is given, disallow annotations not entirely within b…
Browse files Browse the repository at this point in the history
…ounds.
  • Loading branch information
JoeStrout committed Jan 29, 2025
1 parent 5b7f81f commit 7d091da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
8 changes: 8 additions & 0 deletions tests/unit/db_annotations/test_precomp_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ def test_single_level():
chunk_path = os.path.join(file_dir, "spatial0", "2_1_1")
assert precomp_annotations.count_lines_in_file(chunk_path) == 2

with pytest.raises(ValueError):
out_of_bounds_lines = [
LineAnnotation(id=1, start=(1640.0, 1308.0, 61.0), end=(1644.0, 1304.0, 57.0)),
LineAnnotation(id=666, start=(-100, 0, 0), end=(50, 50, 50)),
]
roi = BBox3D.from_coords((25, 25, 25), (250, 250, 250), resolution=(10, 10, 40))
sf.write_annotations(out_of_bounds_lines, clearing_bbox=roi)


def test_edge_cases():
with pytest.raises(ValueError):
Expand Down
24 changes: 13 additions & 11 deletions web_api/app/precomputed_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,22 @@ async def add_multiple(
"""
The PUT endpoint replaces all data within the given bounds in the given file
(which may or may not exist yet) with the given new set of lines.
Note that any lines not entirely contained within the bbox are ignored.
"""
lines = []
for entry in annotations:
annotation = AnnotationDBEntry.from_dict(entry["id"], entry)
line = annotation.ng_annotation
lines.append(
precomp_annotations.LineAnnotation(
int(annotation.id),
line.point_a.tolist(),
line.point_b.tolist(),
)
)
resolution_vec = Vec3D(*resolution)
index = VolumetricIndex.from_coords(bbox_start, bbox_end, resolution_vec)
lines = []
for d in annotations:
db_entry = AnnotationDBEntry.from_dict(d["id"], d)
ng_annotation = db_entry.ng_annotation
line_annotation = precomp_annotations.LineAnnotation(
int(db_entry.id),
ng_annotation.point_a.tolist(),
ng_annotation.point_b.tolist(),
)
if line_annotation.in_bounds(index, strict=True):
lines.append(line_annotation)
layer = build_annotation_layer(path, index=index, mode="replace")
layer.write_annotations(lines, annotation_resolution=resolution_vec, clearing_bbox=index.bbox)

Expand Down

0 comments on commit 7d091da

Please sign in to comment.