Skip to content

Commit

Permalink
0️⃣ Allow empty ROIs to be inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
asim-shrestha committed Oct 1, 2022
1 parent 779fda6 commit 52b6f15
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rt_utils/rtstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def validate_mask(self, mask: np.ndarray) -> bool:
)

if np.sum(mask) == 0:
raise RTStruct.ROIException("Mask cannot be empty")
print("[INFO]: ROI mask is empty")

return True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

VERSION = "1.2.4"
VERSION = "1.2.5"
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
with open("requirements.txt") as f:
Expand Down
14 changes: 8 additions & 6 deletions tests/test_rtstruct_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,25 @@ def test_valid_filemeta(new_rtstruct: RTStruct):

def test_add_non_binary_roi(new_rtstruct: RTStruct):
mask = get_empty_mask(new_rtstruct)
mask.astype(float)
mask = mask.astype(float)
with pytest.raises(RTStruct.ROIException):
new_rtstruct.add_roi(mask)


def test_add_empty_roi(new_rtstruct: RTStruct):
mask = get_empty_mask(new_rtstruct)
mask = mask[:, :, 1:] # One less slice than expected
with pytest.raises(RTStruct.ROIException):
new_rtstruct.add_roi(mask)
new_rtstruct.add_roi(mask)
assert len(new_rtstruct.ds.ROIContourSequence) == 1
assert len(new_rtstruct.ds.ROIContourSequence[0].ContourSequence) == 0 # No slices added
assert len(new_rtstruct.ds.StructureSetROISequence) == 1
assert len(new_rtstruct.ds.RTROIObservationsSequence) == 1


def test_add_invalid_sized_roi(new_rtstruct: RTStruct):
mask = get_empty_mask(new_rtstruct)
mask = mask[:, :, 1:] # One less slice than expected
with pytest.raises(RTStruct.ROIException):
new_rtstruct.add_roi(mask)
# Create ROI


def test_add_valid_roi(new_rtstruct: RTStruct):
Expand All @@ -65,7 +67,7 @@ def test_add_valid_roi(new_rtstruct: RTStruct):
assert len(new_rtstruct.ds.ROIContourSequence) == 1
assert (
len(new_rtstruct.ds.ROIContourSequence[0].ContourSequence) == 1
) # Only 1 slice was added to
) # Only 1 slice was added
assert len(new_rtstruct.ds.StructureSetROISequence) == 1
assert len(new_rtstruct.ds.RTROIObservationsSequence) == 1
assert new_rtstruct.ds.ROIContourSequence[0].ROIDisplayColor == COLOR
Expand Down

0 comments on commit 52b6f15

Please sign in to comment.