def find_closest_nhood( self, nkey_origin, nkeys_search, n_results=3, length_domain=None, include_start_node=True, **kwargs ): closest_nkey = self.find_closest_node( nkey_origin, nkeys_search, length_domain=length_domain, **kwargs ) nbors = [] if include_start_node: nbors.append(closest_nkey) rings = 1 nhood = [] while nhood < n_results: nhood = self.neighborhood(closest_nkey, rings=rings) rings += 1 nhood = nhood[:n_results] for nkey in nhood: if is_in_domain(self.dist_dict[nkey_origin][nkey], length_domain): nbors.append(nkey) return nbors
def find_closest_node( self, nkey_origin, nkeys_search, length_domain=None, prefer_distant=False, **kwargs ): self.ensure_dist_dict() dists = copy(self.dist_dict[nkey_origin]) for nkey in self.dist_dict.keys(): if nkey == nkey_origin: continue if nkey not in nkeys_search: # print("Not in search") dists.pop(nkey) continue if nkey in self.neighbors(nkey_origin): # print("in nbors") dists.pop(nkey) continue if not is_in_domain(dists[nkey], length_domain): # print("not in domain") dists.pop(nkey) continue if len(dists) < 1: # No matches return None dists = dists.items() dists.sort(key=lambda x: x[1], reverse=prefer_distant) keys, _ = zip(*dists) return keys[0]
def find_closest_faces(meshes, face_keys, n_face_connections=2, dist_domain=(None, None)): mesh_a, mesh_b = meshes face_keys_a, face_keys_b = face_keys pt_cloud_dict = {} pt_cloud_list = [] for fkey in face_keys_b: x, y, z = mesh_b.face_center(fkey) pt = rg.Point3d(x, y, z) pt_cloud_dict[pt] = fkey pt_cloud_list.append(pt) partners = [] for fkey_a in face_keys_a: partner_pts = [] x, y, z = mesh_a.face_center(fkey_a) pt = rg.Point3d(x, y, z) closest_pts, _, dist = ghcomp.ClosestPoints(pt, pt_cloud_list, n_face_connections) if n_face_connections < 2: closest_pts = [closest_pts] for cp in closest_pts: if is_in_domain(pt.DistanceTo(cp), dist_domain): partner_pts.append(pt_cloud_dict[cp]) if len(partner_pts) > 0: partners.append((fkey_a, partner_pts)) return partners
def find_closest_face_same_mesh(mesh, fkeys, n_face_connections=2, dist_domain=(None, None), prefer_long=False): fkeys = list(fkeys) pt_cloud_dict = {} for fkey in fkeys: x, y, z = mesh.face_center(fkey) pt = rg.Point3d(x, y, z) pt_cloud_dict[pt] = fkey partners = [] for fkey in fkeys: dists = [] x, y, z = mesh.face_center(fkey) pt1 = rg.Point3d(x, y, z) for pt2, key in pt_cloud_dict.iteritems(): if key == fkey or key in mesh.face_neighbors(fkey): continue dist = pt1.DistanceTo(pt2) if is_in_domain(dist, dist_domain): dists.append((key, dist)) if len(dists) < 1: # No matches continue dists.sort(key=lambda x: x[1], reverse=prefer_long) keys, _ = zip(*dists) partners.append((fkey, keys[:n_face_connections])) return partners
def ok_edge_length(self, ekeys, length_domain): for u, v in ekeys: if not is_in_domain(self.edge_length(u, v), length_domain): return False return True
def ok_edge_length(self, u, v, length_domain): if not length_domain: return True return is_in_domain(self.edge_length(u, v), length_domain)
def ok_degree(self, key, degree_domain): if not degree_domain: return True return is_in_domain(self.nv_degree(key), degree_domain)