Skip to content

Commit

Permalink
Be sure to have at least more than 2 points to be able to have a contour
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaudier committed Sep 14, 2023
1 parent a334d71 commit 38bc083
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions gatetools/roi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,21 @@ def __init__(self,ds=None,roi_id=None,verbose=False, contours_list = None):
for contour in roi.ContourSequence:
ref = contour.ContourImageSequence[0].ReferencedSOPInstanceUID
npoints = int(contour.NumberOfContourPoints)
# check assumption on number of contour coordinates
assert(len(contour.ContourData)==3*npoints)
points = np.array([float(coord) for coord in contour.ContourData]).reshape(npoints,3)
zvalues = set(points[:,2])
# check assumption that all points are in the same xy plane (constant z)
assert(len(zvalues)==1)
zvalue = zvalues.pop()
if zvalue in self.zlist:
ic = self.zlist.index(zvalue)
self.contour_layers[ic].add_contour(points,ref)
else:
self.contour_layers.append(contour_layer(points,ref))
self.zlist.append(zvalue)
self.bb.should_contain_all(points)
if npoints > 2:
# check assumption on number of contour coordinates
assert(len(contour.ContourData)==3*npoints)
points = np.array([float(coord) for coord in contour.ContourData]).reshape(npoints,3)
zvalues = set(points[:,2])
# check assumption that all points are in the same xy plane (constant z)
assert(len(zvalues)==1)
zvalue = zvalues.pop()
if zvalue in self.zlist:
ic = self.zlist.index(zvalue)
self.contour_layers[ic].add_contour(points,ref)
else:
self.contour_layers.append(contour_layer(points,ref))
self.zlist.append(zvalue)
self.bb.should_contain_all(points)
if verbose:
logger.info("roi {}={} has {} points on {} contours with z range [{},{}]".format(
self.roinr,self.roiname,self.npoints_total,self.ncontours,self.bb.zmin,self.bb.zmax))
Expand Down

0 comments on commit 38bc083

Please sign in to comment.