def create_algebra_roi(pm, examination, ss, roi): pm.CreateRoi(Name=roi.name, Color=roi.color, Type=roi.type) # Get ROI geometry: roi_geometry = SSF.rg(ss, roi.name) # Make sure that all ROI sources exists: missing = [] sources = list( roi.sourcesA ) # (we need to make sure that we're working on a copy of this list) sources.extend(roi.sourcesB) for source_roi in sources: if not SSF.has_roi(ss, source_roi.name): missing.append(source_roi.name) if len(missing) == 0: roi_geometry.OfRoi.CreateAlgebraGeometry( Examination=examination, ExpressionA=roi.expressionA(), ExpressionB=roi.expressionB(), ResultOperation=roi.operator, ResultMarginSettings=roi.result_margin_settings()) roi_geometry.OfRoi.SetAlgebraExpression( ExpressionA=roi.expressionA(), ExpressionB=roi.expressionB(), ResultOperation=roi.operator, ResultMarginSettings=roi.result_margin_settings()) roi_geometry.OfRoi.UpdateDerivedGeometry(Examination=examination) else: GUIF.handle_missing_roi_for_derived_rois(roi.name, missing)
def create_cornea(pm, examination, ss, source_roi, box_roi, roi, subtraction_roi): if SSF.has_named_roi_with_contours(ss, source_roi.name): center_x = SSF.roi_center_x(ss, source_roi.name) center_z = SSF.roi_center_z(ss, source_roi.name) source_roi_box = ss.RoiGeometries[source_roi.name].GetBoundingBox() y_min = source_roi_box[1].y if y_min > 0: y_min = -source_roi_box[1].y delete_roi(pm, box_roi.name) box = pm.CreateRoi(Name=box_roi.name, Color=box_roi.color, Type=box_roi.type) pm.RegionsOfInterest[box_roi.name].CreateBoxGeometry( Size={ 'x': 5, 'y': 5, 'z': 4 }, Examination=examination, Center={ 'x': center_x, 'y': y_min + 2.5, 'z': center_z }) exclude_roi_from_export(pm, box_roi.name) if source_roi.name == ROIS.lens_l.name: wall_roi = ROIS.z_eye_l elif source_roi.name == ROIS.lens_r.name: wall_roi = ROIS.z_eye_r delete_roi(pm, wall_roi.name) create_wall_roi(pm, examination, ss, wall_roi) exclude_roi_from_export(pm, wall_roi.name) if not SSF.is_approved_roi_structure(ss, roi.name): if is_approved_roi_structure_in_one_of_all_structure_sets( pm, roi.name): intersection = ROI.ROIAlgebra(roi.name + "1", roi.type, roi.color, sourcesA=[source_roi], sourcesB=[box_roi], operator='Intersection') # In the rare case that this ROI already exists, delete it (to avoid a crash): delete_roi(pm, intersection.name) create_algebra_roi(pm, examination, ss, intersection) GUIF.handle_creation_of_new_roi_because_of_approved_structure_set( intersection.name) else: subtraction = ROI.ROIAlgebra(subtraction_roi.name, subtraction_roi.type, subtraction_roi.color, sourcesA=[wall_roi], sourcesB=[box_roi], operator='Subtraction') # In the rare case that this ROI already exists, delete it (to avoid a crash): delete_roi(pm, subtraction.name) create_algebra_roi(pm, examination, ss, subtraction) else: GUIF.handle_missing_roi_for_derived_rois(subtraction_roi.name, source_roi.name)
def create_bottom_part_x_cm(pm, examination, ss, source_roi, roi, distance): if SSF.has_named_roi_with_contours(ss, source_roi.name): center_x = SSF.roi_center_x(ss, source_roi.name) center_y = SSF.roi_center_y(ss, source_roi.name) center_z = SSF.roi_center_z(ss, source_roi.name) source_roi_box = ss.RoiGeometries[source_roi.name].GetBoundingBox() x_min = source_roi_box[0].x x_max = source_roi_box[1].x x = source_roi_box[1].x - source_roi_box[0].x y_min = source_roi_box[0].y y_max = source_roi_box[1].y y = source_roi_box[1].y - source_roi_box[0].y z_min = source_roi_box[0].z z = source_roi_box[1].z - source_roi_box[0].z z_cutoff = z_min + distance / 2 delete_roi(pm, ROIS.box.name) box = pm.CreateRoi(Name=ROIS.box.name, Color=ROIS.box.color, Type=ROIS.box.type) pm.RegionsOfInterest[ROIS.box.name].CreateBoxGeometry( Size={ 'x': x, 'y': y, 'z': distance }, Examination=examination, Center={ 'x': center_x, 'y': center_y, 'z': z_cutoff }) if not SSF.is_approved_roi_structure(ss, roi.name): if is_approved_roi_structure_in_one_of_all_structure_sets( pm, roi.name): intersection = ROI.ROIAlgebra(roi.name + "1", roi.type, roi.color, sourcesA=[source_roi], sourcesB=[ROIS.box], operator='Intersection') # In the rare case that this ROI already exists, delete it (to avoid a crash): delete_roi(pm, intersection.name) create_algebra_roi(pm, examination, ss, intersection) GUIF.handle_creation_of_new_roi_because_of_approved_structure_set( intersection.name) else: intersection = ROI.ROIAlgebra(roi.name, roi.type, roi.color, sourcesA=[source_roi], sourcesB=[ROIS.box], operator='Intersection') # In the rare case that this ROI already exists, delete it (to avoid a crash): delete_roi(pm, intersection.name) create_algebra_roi(pm, examination, ss, intersection) delete_roi(pm, ROIS.box.name) else: GUIF.handle_missing_roi_for_derived_rois(roi.name, source_roi.name)
def create_posterior_half(pm, examination, ss, source_roi, roi): if SSF.has_named_roi_with_contours(ss, source_roi.name): center_x = SSF.roi_center_x(ss, source_roi.name) center_y = SSF.roi_center_y(ss, source_roi.name) center_z = SSF.roi_center_z(ss, source_roi.name) source_roi_box = ss.RoiGeometries[source_roi.name].GetBoundingBox() x_min = source_roi_box[0].x x_max = source_roi_box[1].x x = source_roi_box[1].x - source_roi_box[0].x boxes = [] boxes2 = [] for [contour_index, contour] in enumerate( ss.RoiGeometries[source_roi.name].PrimaryShape.Contours): y_min = 9999 y_max = -9999 for coordinate in contour: if coordinate.y > y_max: y_max = coordinate.y elif coordinate.y < y_min: y_min = coordinate.y length = round((abs(y_max - y_min)), 1) center_y = y_max delete_roi(pm, ROIS.box.name + str(contour_index)) box = pm.CreateRoi(Name=ROIS.box.name + str(contour_index), Color=ROIS.box.color, Type=ROIS.box.type) pm.RegionsOfInterest[ROIS.box.name + str(contour_index)].CreateBoxGeometry( Size={ 'x': x, 'y': length, 'z': 0.3 }, Examination=examination, Center={ 'x': center_x, 'y': center_y, 'z': coordinate.z }) boxes.append(box) boxes2.append( ROI.ROI(ROIS.box.name + str(contour_index), ROIS.box.type, ROIS.box.color)) subtraction = ROI.ROIAlgebra(roi.name, roi.type, roi.color, sourcesA=[source_roi], sourcesB=boxes2, operator='Intersection') # In the rare case that this ROI already exists, delete it (to avoid a crash): delete_roi(pm, subtraction.name) create_algebra_roi(pm, examination, ss, subtraction) for i in range(0, len(boxes)): delete_roi(pm, boxes[i].Name) else: GUIF.handle_missing_roi_for_derived_rois(roi.name, source_roi.name)
def create_wall_roi(pm, examination, ss, roi): pm.CreateRoi(Name=roi.name, Color=roi.color, Type=roi.type) roi_geometry = SSF.rg(ss, roi.name) # Make sure that the source ROI exists: if SSF.has_roi(ss, roi.source.name): roi_geometry.OfRoi.SetWallExpression(SourceRoiName=roi.source.name, OutwardDistance=roi.outward_dist, InwardDistance=roi.inward_dist) roi_geometry.OfRoi.UpdateDerivedGeometry(Examination=examination, Algorithm="Auto") else: GUIF.handle_missing_roi_for_derived_rois(roi.name, [roi.source.name])
def create_expanded_roi(pm, examination, ss, roi): pm.CreateRoi(Name=roi.name, Color=roi.color, Type=roi.type) # Get ROI geometry: roi_geometry = SSF.rg(ss, roi.name) # Make sure that the source ROI exists: if SSF.has_roi(ss, roi.source.name): roi_geometry.OfRoi.CreateMarginGeometry( Examination=examination, SourceRoiName=roi.source.name, MarginSettings=roi.margin_settings) roi_geometry.OfRoi.SetMarginExpression( SourceRoiName=roi.source.name, MarginSettings=roi.margin_settings) roi_geometry.OfRoi.UpdateDerivedGeometry(Examination=examination) else: GUIF.handle_missing_roi_for_derived_rois(roi.name, [roi.source.name])
def create_roi_subtraction(pm, examination, ss, roi1, roi2, subtraction_name, threshold): overlap = False if has_named_roi_with_contours( ss, roi1.name) and has_named_roi_with_contours(ss, roi2.name): subtraction = ROI.ROIAlgebra(subtraction_name, 'Undefined', 'Black', sourcesA=[roi1], sourcesB=[roi2], operator='Subtraction') # In the rare case that this ROI already exists, delete it (to avoid a crash): PMF.delete_roi(pm, subtraction.name) PMF.create_algebra_roi(pm, examination, ss, subtraction) # Is overlapping volume less than threshold? if has_named_roi_with_contours(ss, subtraction.name): if ss.RoiGeometries[roi1.name].GetRoiVolume() - ss.RoiGeometries[ subtraction.name].GetRoiVolume() > threshold: overlap = True else: GUIF.handle_missing_roi_for_derived_rois(subtraction_name, roi2.name) return overlap