def bounding_boxes(self): """ Compute bounding boxes and construct BIH tree for a given surface :param surf: :return: """ tree = bih.BIH() n_patch = self.u_basis.n_intervals * self.v_basis.n_intervals patch_poles = np.zeros([9, 3, n_patch]) i_patch = 0 for iu in range(self.u_basis.n_intervals): for iv in range(self.v_basis.n_intervals): n_points = 0 for i in range(0, 3): for j in range(0, 3): patch_poles[n_points, :, i_patch] = self.poles[iu + i, iv + j, :] n_points += 1 assert i_patch == self.patch_pos2id(iu, iv) i_patch += 1 boxes = [bih.AABB(patch_poles[:, :, p].tolist()) for p in range(n_patch)] tree.add_boxes(boxes) tree.construct() self._tree = tree self._boxes = boxes
def make_bihs(self): import bih shift = np.array([self.epsilon, self.epsilon, 0]) for line in self.lines: pt0, pt1 = self.points[line[0]], self.points[line[1]] b0 = [(pt0 - shift).tolist(), (pt0 + shift).tolist()] b1 = [(pt1 - shift).tolist(), (pt1 + shift).tolist()] box_pt0 = bih.AABB(b0) box_pt1 = bih.AABB(b1) line_box = bih.AABB(b0 + b1) self.pt_boxes.extend([box_pt0, box_pt1]) self.line_boxes.append(line_box) self.pt_bih = bih.BIH() self.pt_bih.add_boxes(self.pt_boxes) self.line_bih = bih.BIH() self.line_bih.add_boxes(self.line_boxes) self.pt_bih.construct() self.line_bih.construct()
def bounding_boxes(self): """ Compute bounding boxes and construct BIH tree for a given curve :param self: :return: """ tree = bih.BIH() boxes = [bih.AABB(self.poles[it:it + 3, :].tolist()) for it in range(self.basis.n_intervals)] tree.add_boxes(boxes) tree.construct() self._tree = tree self._boxes = boxes
def test_bih(): tree = bih.BIH() coords = [0, 0.5, 1, 1.5, 2] boxes = [bih.AABB([[p, 0, 0], [p + 1, 1, 1]]) for p in coords] tree.add_boxes(boxes) tree.construct() intersect_box_ids = tree.find_point([0.7, 0.5, 0.5]) intersect_box_ids.sort() assert intersect_box_ids == [0, 1] box = bih.AABB([[0.7, 0.5, 0.5], [1.3, 0.5, 0.5]]) intersect_box_ids = tree.find_box(box) intersect_box_ids.sort() assert intersect_box_ids == [ 0, 1, 2 ], "intersect_box_ids: {}".format(intersect_box_ids)
def main(inv_par, project_conf, max_dist=1.0, final=False): if inv_par.meshFrom == MeshFrom.GALLERY_CLOUD: mesh_file = "gallery_mesh.msh" offset = np.array([ project_conf.point_cloud_origin_x, project_conf.point_cloud_origin_y, project_conf.point_cloud_origin_z ]) elif inv_par.meshFrom == MeshFrom.SURFACE_CLOUD: mesh_file = "inv_mesh_tmp.msh2" offset = np.array([0.0, 0.0, 0.0]) else: mesh_file = "../../gallery_mesh.msh" offset = np.array([ project_conf.gallery_mesh_origin_x, project_conf.gallery_mesh_origin_y, project_conf.gallery_mesh_origin_z ]) if final: mesh_file = "inv_mesh_tmp.msh2" offset = np.array([0.0, 0.0, 0.0]) mesh = GmshIO(mesh_file) #mesh.elements = {id: data for id, data in mesh.elements.items() if id not in [714, 2095]} tree = bih.BIH() boxes = [] mesh.elements2 = {} i = 0 for data in mesh.elements.values(): type_, tags, nodeIDs = data if type_ != 2: continue # a = np.array(mesh.nodes[nodeIDs[0]]) + np.array([-622000.0, -1128000.0, 0.0]) # b = np.array(mesh.nodes[nodeIDs[1]]) + np.array([-622000.0, -1128000.0, 0.0]) # c = np.array(mesh.nodes[nodeIDs[2]]) + np.array([-622000.0, -1128000.0, 0.0]) # a = np.array(mesh.nodes[nodeIDs[0]]) # b = np.array(mesh.nodes[nodeIDs[1]]) # c = np.array(mesh.nodes[nodeIDs[2]]) a = np.array(mesh.nodes[nodeIDs[0]]) + offset b = np.array(mesh.nodes[nodeIDs[1]]) + offset c = np.array(mesh.nodes[nodeIDs[2]]) + offset boxes.append(bih.AABB([a, b, c])) mesh.elements2[i] = data i += 1 tree.add_boxes(boxes) tree.construct() # electrodes = [] # with open("electrodes_small.xyz") as fd: # for i, line in enumerate(fd): # s = line.split() # if len(s) >= 3: # el = np.array([float(s[0]), float(s[1]), float(s[2])]) # electrodes.append(el) # # t = time.time() # snapped_electrodes = [snap_electrode(el, mesh, tree) for el in electrodes] # print("elapsed time = {:.3f} s".format(time.time() - t)) # # with open("electrodes_small_snapped2.xyz", "w") as fd: # for el in snapped_electrodes: # fd.write("{} {} {}\n".format(el[0], el[1], el[2])) if project_conf.method == GenieMethod.ERT: data = pg.DataContainerERT("input.dat", removeInvalid=False) else: data = pg.DataContainer("input.dat", sensorTokens='s g', removeInvalid=False) for i in range(len(data.sensorPositions())): pos = data.sensorPosition(i) pos = np.array([pos[0], pos[1], pos[2]]) new_pos = snap_electrode(pos, mesh, tree, max_dist, offset) data.setSensorPosition(i, new_pos) data.save("input_snapped.dat")