Ejemplo n.º 1
0
def assign_material(outer_coord_file, outer_ele_file, inner_coord_file,
                    inner_ele_file):
    outer_content = read_tetgen.ReadTetGen(outer_ele_file, outer_coord_file)
    outer__coords = outer_content.read_coordinates()
    outer_elems = outer_content.read_elements()
    inner_content = read_tetgen.ReadTetGen(inner_ele_file, inner_coord_file)
    inner_coords = inner_content.read_coordinates()
    inner_elems = inner_content.read_elements()
    grid = Grid(outer_elems, outer__coords)
    grid.build_grid()
    inner_elem_index = []
    inner_elem_centers = []
    for elem in inner_elems:
        center = (inner_coords[elem[0]] + inner_coords[elem[1]] +
                  inner_coords[elem[2]] + inner_coords[elem[3]]) / 4
        inner_elem_centers.append(center)

    for index, inner_coord in enumerate(inner_elem_centers):
        elem_index = grid.search_tet(inner_coord)
        if elem_index != -1:
            inner_elem_index.append(elem_index)
        print(index)
    inner_elem_index = np.unique(inner_elem_index)
    inner_elem = []
    for elem in inner_elem_index:
        inner_elem.append(outer_elems[elem])
    return inner_elem
Ejemplo n.º 2
0
 def read_face_indices(self, surface_file):
     surface_points = []
     surface_points_indices = []
     content = read_tetgen.ReadTetGen('', '')
     surface = content.read_surface(surface_file)
     surface = np.unique(surface)
     return surface
def find_tet(tet_elefile, tet_coordfile, triangle_stlfile):
    tet_content = read_tetgen.ReadTetGen(tet_elefile, tet_coordfile) 
    tet_coords = tet_content.read_coordinates()
    tet_elems = tet_content.read_elements()
    tri_coords, tri_faces = change_stl.parse(triangle_stlfile)
    element_inside = []
    
    for ele_num, tet_elem in enumerate(tet_elems):
        center = (tet_coords[tet_elem[0]] + tet_coords[tet_elem[1]] +
                  tet_coords[tet_elem[2]] + tet_coords[tet_elem[3]]) / 4
       
        ray = np.array([center,[100000000, 0, 0]])
        num = 0
        for tri_face in tri_faces:
            if ray_intersect_triangle(np.array(
                    [tri_coords[tri_face[0]], tri_coords[tri_face[1]], 
                     tri_coords[tri_face[2]]]), ray):
                num += 1
        if num%2 == 1:
            print('true')
            element_inside.append(tet_elem)
       #     temp1 = np.array([[-113.3,46.2,138.1], [-77.1,46.2,138.1], [-89.9,70.2,138.1]])
       #     temp2 = np.array([[-88.01642,61.29,133.04],[-88.01642,60.93483,127.87]])
       #     if ray_intersect_triangle(temp1, temp2):
       #         pdb.set_trace()
        print(ele_num)
    
    write_element(element_inside, 'F:\Research\Breast Model\BM_Fatty_001\Left\Fat_1_Fgt_1\SolidModel\FGT_fromskin.ele')
    pdb.set_trace()
Ejemplo n.º 4
0
 def __init__(self, tet_file, triangle_file, node_file):
     content = read_tetgen.ReadTetGen(tet_file, node_file)
     self.triangles = content.read_surface(triangle_file)
     self.nodes = content.read_coordinates()
     self.tetrahedrons = content.read_elements()
     self.graph = self.Graph()
     self.point_to_tet = dict(
     )  # the point index to all tetrahedrons that contain it
Ejemplo n.º 5
0
def element_to_index(elementfile, nodefile):
    elem_to_index = {}
    content = read_tetgen.ReadTetGen(elementfile, nodefile)
    elems = content.read_elements()
    for i in range(elems.shape[0]):
        content = str(elems[i][0] + 1) + ',' + str(elems[i][1] + 1) + ',' \
                  + str(elems[i][2] + 1) + ',' + str(elems[i][3] + 1)
        elem_to_index[content] = i + 1
    return elem_to_index
Ejemplo n.º 6
0
def add_element_set(output_file, all_layer_elemfile, all_layer_nodefile):
    assigned_elem = {''}
    outmost_elefile = all_layer_elemfile[-1]
    outmost_nodefile = all_layer_nodefile[-1]
    elem_to_index = element_to_index(outmost_elefile, outmost_nodefile)

    for (elem_file, node_file) in zip(all_layer_elemfile, all_layer_nodefile):
        content = read_tetgen.ReadTetGen(elem_file, node_file)
        elems = content.read_elements()
        write_file = open(output_file_name, 'a+')
        pdb.set_trace()
        write_file.write('*Elset, elset=' + os.path.splitext(elem_file)[0] +
                         ', instance=PART-1-1\n')
        write_file.close()
        current_layer_elem = []
        for i in range(elems.shape[0]):
            content = str(elems[i][0] + 1) + ',' + str(elems[i][1] + 1) + ',' \
                      + str(elems[i][2] + 1) + ',' + str(elems[i][3] + 1)
            if content in assigned_elem:
                continue
            current_layer_elem.append(elem_to_index[content])
            assigned_elem.add(content)
        write_sixteen_num_perline(current_layer_elem, output_file)
Ejemplo n.º 7
0
# filename: the output file you want to write to
# points: a list of 3D points or 1D points
# write_flag: whether to rewrite ('w') or append('a')
def write_to_file(filename, points, write_flag):
    if write_flag == 'write':
        output_file = open(filename, 'w')
    elif write_flag == 'append':
        output_file = open(filename, 'a+')
    else:
        return
    for index, point in enumerate(points):
        if len(point) == 3:
            output_file.write(
                str(point[0]) + ' ' + str(point[1]) + ' ' + str(point[2]) +
                '\n')
        if len(point) == 1:
            output_file.write(str(point[0]) + '\n')
    output_file.close()


if __name__ == "__main__":
    elefile = ''
    nodefile = 'Skin_Layer.node'
    surfacefile = 'Skin_Layer.face'
    triangles_unity = 'Skin_Layer_unity.face'
    nodefile_unity = 'Skin_Layer_unity.node'
    tet_gen = read_tetgen.ReadTetGen(elefile, nodefile)
    triangles = tet_gen.read_surface(surfacefile)
    coords = tet_gen.read_coordinates()
    write_to_file(triangles_unity, triangles, 'write')
    write_to_file(nodefile_unity, coords, 'write')
Ejemplo n.º 8
0
 def read_coordinates(self, ele_file, coord_file):
     content = read_tetgen.ReadTetGen(ele_file, coord_file)
     coordinates = content.read_coordinates()
     return coordinates