def write_vtp_files(): for cell_1_i, d_cell2_contactinfo in dd_cell1_cell2_contactinfo.items(): for cell_2_i, contactinfo in d_cell2_contactinfo.items(): poly_collision = extract_selection_vtp( poly_in=d_cellname_poly[cell_1_i], l_cell_idx=[*contactinfo.d_idx_l_idx_triangles] + contactinfo.l_triangles_popped) write_vtp_file(poly_collision, str(output_folder / "{0}_contact_{1}.vtp".format( cell_1_i, cell_2_i))) #with holes poly_holes_filled = extract_selection_vtp( poly_in=d_cellname_poly[cell_1_i], l_cell_idx=[*contactinfo.d_idx_l_idx_triangles] + contactinfo.l_triangles_idx_hole + contactinfo.l_triangles_popped) write_vtp_file(poly_holes_filled, str(output_folder / "{0}_contact_filled{1}.vtp".format( cell_1_i, cell_2_i))) #without holes write_vtp_file( d_cellname_poly[cell_1_i], str(output_folder / "{0}_enriched.vtp".format(cell_1_i))) return
def __init__(self, cell, area, area_eq, area_flat, contact_area, d_idx_l_idx_triangles, l_intersection_point): self.cell = cell self.area = area self.area_eq = area_eq self.area_flat = area_flat self.contact_area = contact_area self.d_idx_l_idx_triangles = d_idx_l_idx_triangles #dict of lists : key = idx of triangle of cell 1 ; value = list of indices of contacting triangles of cell 2 self.l_intersection_point = l_intersection_point self.poly_collision = extract_selection_vtp( poly_in=d_cellname_poly[cell], l_cell_idx=[*d_idx_l_idx_triangles] ) #the poly that comes out trimesh collision manager (still contains gaps) self.s_points = None self.l_triangles_idx_hole = [] self.l_triangles_popped = []
def extract_parentID_selection_from_VTP(input_file_vtp, verbose=False): ''' temporary => copy paste from VTK_Utils ''' d_parentID_VTP = {} poly_in = read_vtp_file(input_file_vtp) a_parent_id = np.unique( dsa.WrapDataObject(poly_in).CellData['parentIndex'].__array__()) for parent_id in a_parent_id: if verbose: print('--processing cell with parentID {0}'.format(parent_id)) poly_out = extract_selection_vtp( poly_in, query="parentIndex == {0}".format(parent_id), field_type="CELL") d_parentID_VTP[parent_id] = poly_out return d_parentID_VTP
def remove_shared_triangles_between_contactareas(cell): if verbose: print( 'remove_shared_triangles_between_contactareas ({0})'.format(cell)) #build up datastructure d_idx_triangle_l_contactarea wdo_1 = dsa.WrapDataObject(d_cellname_poly[cell]) d_idx_triangle_l_contactarea = {} for cell2_i, contactinfo_i in dd_cell1_cell2_contactinfo[cell].items(): for idx_triangle_1_i in contactinfo_i.d_idx_l_idx_triangles.keys(): d_idx_triangle_l_contactarea.setdefault(idx_triangle_1_i, []).append(cell2_i) #remove shared triangles from contactareas l_triangles_popped = [] for idx_triangle_i, l_contactarea_i in d_idx_triangle_l_contactarea.items( ): if len(l_contactarea_i) > 1: l_triangles_popped.append(idx_triangle_i) for contactarea_i in l_contactarea_i: dd_cell1_cell2_contactinfo[cell][ contactarea_i].d_idx_l_idx_triangles.pop(idx_triangle_i) dd_cell1_cell2_contactinfo[cell][ contactarea_i].l_triangles_popped.append(idx_triangle_i) if verbose: print( 'triangle {0} has been removed from contactarea {2} of cell {1} because it was shared with another contactarea from the same cell' .format(idx_triangle_i, cell, contactarea_i)) if verbose: poly_popped = extract_selection_vtp(poly_in=d_cellname_poly[cell], l_cell_idx=l_triangles_popped) write_vtp_file(poly_popped, str(output_folder / "popped_{0}.vtp".format(cell))) return
#part 3 remove shared triangles between contactareas for cell_i in d_cellname_poly.keys(): remove_shared_triangles_between_contactareas(cell_i) #part 4 : fill in holes of contactareas (all indices used in this step, refer to indices at cell-level) for cell_i in dd_cell1_cell2_contactinfo.keys(): if l_selection_cells[0] != 'all' and cell_i not in l_selection_cells: print('skipping cell {0}'.format(cell_i)) continue d_vi_arealabel = { } #key vertex index (=pointID); value = the label of the contactarea (=name of contacting cell) #step 1 : get all contactpoints based on contactarea vtp poly_totalcontactarea = extract_selection_vtp( poly_in=d_cellname_poly[cell_i], query="contact_area > 0", field_type="CELL", inverse_selection=False, verbose=False) wdo_total_contactarea = dsa.WrapDataObject(poly_totalcontactarea) a_contactIndex = np.copy( dsa.WrapDataObject( d_cellname_poly[cell_i]).CellData['parentIndex'].__array__() ) #a_contactIndex = the array that will be used to enrich the cellVTP with contacting cellids, initialize with parentID s_idx_triangles_unassigned = set( wdo_total_contactarea.CellData['SelectionCellIds'].__array__( )) #SelectionCellIds are the indices of 1 level up (cell level) write_vtp_file(poly_totalcontactarea, str(output_folder /
file_error = load_file_and_build_dict(input_folder / input_vtp_2, d_cells) if file_error: continue # get borderpoints (from both contactareas) a_border_points_total = np.empty((0, 3)) flag_no_overlap = False l_iter = [(cell1, d_cells[cell2]['parentid']), (cell2, d_cells[cell1]['parentid'])] for cell, parentid_contact in l_iter: d_cells[cell]['contacts'][parentid_contact] = {} #d_contact d_cells[cell]['contacts'][parentid_contact]['pair_ctr'] = int(ix_cell / 2) poly_contact_area = extract_selection_vtp( d_cells[cell]['poly'], query="contactidCanonical == {0}".format(parentid_contact), field_type="CELL") if not poly_contact_area: print('no overlap between cells detected. Indent volume = 0') flag_no_overlap = True continue a_border_points, poly_border = get_outside_points(poly_contact_area) d_cells[cell]['contacts'][parentid_contact][ 'border_points'] = poly_border d_cells[cell]['contacts'][parentid_contact][ 'contact_area'] = poly_contact_area a_border_points_total = np.append(a_border_points_total, a_border_points,