def load_file_and_build_dict(p_cell, d_cells): file_error = False try: poly_in = read_vtp_file(p_cell) parentid = get_unique_values(poly_in, 'parentIndexCanonical')[0] poly_in = scale_poly(poly_in, 1.e6) #trimesh fails in micron f_stl = str(output_folder / (p_cell.stem + ".stl")) write_stl_file(poly_in, f_stl) trimesh_in = trimesh.load(f_stl, file_type="stl") if trimesh_in.is_volume: print("volume of input mesh {1} = {0}".format( trimesh_in.volume, p_cell.stem)) d_cells[p_cell.stem] = { 'poly': poly_in, 'parentid': parentid, 'trimesh': trimesh_in, 'contacts': {} } #d_contacts except: print('Error reading input file ({}), continuing with next cell-pair'. format(p_cell)) file_error = True return file_error
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
key=lambda t: t[1]): #sorted on file number ascending vtp_i, nb_vtp = t_vtp if input_file_nb: if int(input_file_nb) == int(nb_vtp): input_file_vtp = vtp_i break input_file_vtp = vtp_i #part1 : enrich embryo vtp with contactID # - contact index is the index of the contacting triangle (from the other cell) # - contactID is the parent index of the contacting cell print('vtp file {0} will be used for enriching of contactinformation'.format( input_file_vtp)) if input_file_vtp else print( 'no vtp file found ! at {0}'.format(input_file_vtp)) poly_in = read_vtp_file(input_file_vtp) poly_out = enrich_embryo_with_contactID(poly_in) path_file = str(output_folder / (input_file_vtp.stem + "_enriched.vtp")) write_vtp_file(poly_out, path_file) if verbose: print("output written : {0}".format(path_file)) #part2 : make contactarea network graph #-step1) build datastructure containing all contact pair data dd_cell1_cell2_contactinfo class DictOfDicts(dict): """Implementation of perl's autovivification feature.""" def __getitem__(self, item): try: return dict.__getitem__(self, item) except KeyError:
return counter_most_common[0][0] if counter_most_common[0][1] > 1 else [] #MAIN l_selection_cells = ['cell_parent2'] #'all' will process all cells l_selection_cells = ['all'] #'all' will process all cells input_folder, output_folder = read_parms() (output_folder / "STL_converted").mkdir(parents=True, exist_ok=True) #Part1: find out contact pairs via Trimesh collision manager/ #trimesh cannot work with vtp directly, so convert to stl first # print(trimesh.exchange.load.available_formats()) d_cellname_poly = {} for ix, vtp_path_i in enumerate(sorted(input_folder.glob('*.vtp'))): poly = read_vtp_file(vtp_path_i) d_cellname_poly[vtp_path_i.stem] = poly write_stl_file(poly, (output_folder / "STL_converted" / (vtp_path_i.stem + ".stl"))) cm = CollisionManager() d_cellname_trimeshStl = {} for ix, stl_i in enumerate( sorted((output_folder / "STL_converted").glob('cell*.stl'))): print('Adding stl -> {0}'.format(stl_i.name)) f = open(str(stl_i), 'r') trimesh_stl = trimesh.load(f, file_type="stl") d_cellname_trimeshStl[stl_i.stem] = trimesh_stl cm.add_object(stl_i.stem, trimesh_stl) is_collision, s_t_colliding_pairs = cm.in_collision_internal(return_names=True,
add_array_with_mapper(poly_embryo, 'contactid', 'contactidCanonical', d_parentid_canonical) return if __name__ == '__main__': matplotlib.use('Agg') try: prm = read_parms() prm['output_folder'].mkdir(parents=True, exist_ok=True) input_file_vtp = _select_input_file(prm) poly_embryo = read_vtp_file(input_file_vtp) d_parentid_cellname, df_canonical_parentid = _map_parentIndex(prm) _add_parentid(poly_embryo, d_parentid_cellname) d_parentid_canonical = _add_canonical_parentid( poly_embryo, df_canonical_parentid) _add_contactid(poly_embryo) _add_canonical_contactid(poly_embryo, d_parentid_canonical) _add_lineageid(poly_embryo, prm['input_file_lineageId']) p_out = str(prm['output_folder'] / (input_file_vtp.stem + "_enriched.vtp")) write_vtp_file(poly_embryo, p_out) if prm['verbose']: print("output written : {0}".format(p_out))
log_chronology_txt("After phaseIII") # additional short simulation to get contact information after the last remesh if add_contact_model: engage_cd_counter(mysim, cells, h_eff, CD_cell_cell) # Must be after last remesh mysim.run_until(mysim.get_time() + dtg) vtkWriter.VTKSerialWriter(data=cells('triangles'), filename=str(output_folder / "Seeding"), select_all=True, start_index=get_latest_file()[1] + 1).execute() log_chronology_txt("After final runtime : engaging contactdetection") # read in clean VTP to fix indices poly_embryo = read_vtp_file(output_folder / get_latest_file()[0]) d_oldix_newix, _ = get_map_oldix_newix(type='triangles') add_array_with_mapper(poly_embryo, name_array_source='contact_index', name_array_dest='contact_index', mapper=d_oldix_newix, field_type="CELL") d_oldix_newix, _ = get_map_oldix_newix(type='nodes') add_array_with_mapper(poly_embryo, name_array_source='vertexIndices', name_array_dest='vertexIndices', mapper=d_oldix_newix, field_type="CELL") write_vtp_file(poly_embryo, output_folder / get_latest_file()[0]) log_chronology_txt( "After final runtime : fixing indices due to remeshing => end of simulation"