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_fast(pm, examination, ss, source_roi, roi): 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) i = 0 for i in range(0, contour_index): if i % 3 == 0: 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)
def translate_couch_long(pm, ss, examination, target): isocenter_z = SSF.find_isocenter_z(ss, target) new_couch_z = isocenter_z couch_center_z = SSF.roi_center_z(ss, ROIS.couch.name) img_box = ss.OnExamination.Series[0].ImageStack.GetBoundingBox() img_upper = img_box[1].z img_lower = img_box[0].z couch_length = 36.4 if abs(new_couch_z - img_lower) < couch_length / 2: new_couch_z = img_lower + couch_length / 2 elif abs(new_couch_z - img_upper) < couch_length / 2: new_couch_z = img_upper - couch_length / 2 z_translation = new_couch_z - couch_center_z transMat = { 'M11': 1.0, 'M12': 0.0, 'M13': 0.0, 'M14': 0.0, 'M21': 0.0, 'M22': 1.0, 'M23': 0.0, 'M24': 0.0, 'M31': 0.0, 'M32': 0.0, 'M33': 1.0, 'M34': z_translation, 'M41': 0.0, 'M42': 0.0, 'M43': 0.0, 'M44': 1.0 } # Only move couch if the translation is above threshold: if z_translation > 1 and SSF.is_approved_roi_structure( ss, ROIS.couch.name) == False: pm.RegionsOfInterest[ROIS.couch.name].TransformROI3D( Examination=examination, TransformationMatrix=transMat)