Пример #1
0
def simplify_shell(occshell, tolerance=1e-06):
    """
    This function simplifies the OCCshell by merging all the coincidental OCCfaces in the shell into a single OCCface. 
 
    Parameters
    ----------        
    occshell : OCCshell
        The OCCshell to be simplified.
        
    tolerance : float, optional
        The precision of the simplification, Default = 1e-06.

    Returns
    -------
    simplified shell : OCCshell
        The simplified OCCshell.
    """
    #this will merge any coincidental faces into a single surfaces to simplify the geometry
    fshell = fix_shell_orientation(occshell)
    #get all the faces from the shell and arrange them according to their normals
    sfaces = fetch.topo_explorer(fshell, "face")
    nf_dict = calculate.grp_faces_acc2normals(sfaces)
    merged_fullfacelist = []
    #merge all the faces thats share edges into 1 face
    for snfaces in nf_dict.values():
        connected_face_shell_list = construct.sew_faces(snfaces,
                                                        tolerance=tolerance)
        if connected_face_shell_list:
            for shell in connected_face_shell_list:
                shell_faces = fetch.topo_explorer(shell, "face")
                merged_facelist = construct.merge_faces(shell_faces,
                                                        tolerance=tolerance)
                if merged_facelist:
                    merged_fullfacelist.extend(merged_facelist)
                else:
                    merged_fullfacelist.extend(shell_faces)
        else:
            merged_fullfacelist.extend(snfaces)

    nmerged_face = len(merged_fullfacelist)

    if len(merged_fullfacelist) > 1:
        fshell2 = construct.sew_faces(merged_fullfacelist, tolerance=tolerance)
        fshell2 = fix_shell_orientation(fshell2[0])
        nfshell2_face = len(fetch.topo_explorer(fshell2, "face"))
        if nfshell2_face != nmerged_face:
            return occshell
    else:
        #if there is only one face it means its an open shell
        fshell2 = construct.make_shell(merged_fullfacelist)

    return fshell2
Пример #2
0
def simplify_shell(occshell, tolerance = 1e-06):
    """
    This function simplifies the OCCshell by merging all the coincidental OCCfaces in the shell into a single OCCface. 
 
    Parameters
    ----------        
    occshell : OCCshell
        The OCCshell to be simplified.
        
    tolerance : float, optional
        The precision of the simplification, Default = 1e-06.

    Returns
    -------
    simplified shell : OCCshell
        The simplified OCCshell.
    """
    #this will merge any coincidental faces into a single surfaces to simplify the geometry
    fshell = fix_shell_orientation(occshell)
    #get all the faces from the shell and arrange them according to their normals
    sfaces = fetch.topo_explorer(fshell,"face")
    nf_dict = calculate.grp_faces_acc2normals(sfaces)
    merged_fullfacelist = []
    #merge all the faces thats share edges into 1 face     
    for snfaces in nf_dict.values():
        connected_face_shell_list = construct.sew_faces(snfaces, tolerance=tolerance)
        if connected_face_shell_list:
            for shell in connected_face_shell_list:
                shell_faces = fetch.topo_explorer(shell, "face")    
                merged_facelist = construct.merge_faces(shell_faces,tolerance=tolerance)
                if merged_facelist:
                    merged_fullfacelist.extend(merged_facelist)
                else:
                    merged_fullfacelist.extend(shell_faces)
        else:
            merged_fullfacelist.extend(snfaces)
            
    nmerged_face = len(merged_fullfacelist)

    if len(merged_fullfacelist) >1:
        fshell2 = construct.sew_faces(merged_fullfacelist, tolerance=tolerance)
        fshell2 = fix_shell_orientation(fshell2[0])
        nfshell2_face = len(fetch.topo_explorer(fshell2, "face"))
        if nfshell2_face!= nmerged_face:
            return occshell        
    else:
        #if there is only one face it means its an open shell
        fshell2 = construct.make_shell(merged_fullfacelist)

    return fshell2
Пример #3
0
def simplify_shell(occshell, tolerance=1e-06):
    #this will merge any coincidental faces into a single surfaces to simplify the geometry
    fshell = fix_shell_orientation(occshell)
    #get all the faces from the shell and arrange them according to their normals
    sfaces = fetch.geom_explorer(fshell, "face")
    nf_dict = calculate.grp_faces_acc2normals(sfaces)
    merged_fullfacelist = []
    #merge all the faces thats share edges into 1 face
    for snfaces in nf_dict.values():
        connected_face_shell_list = construct.make_shell_frm_faces(
            snfaces, tolerance=tolerance)
        if connected_face_shell_list:
            for shell in connected_face_shell_list:
                shell_faces = fetch.geom_explorer(shell, "face")
                merged_facelist = construct.merge_faces(shell_faces,
                                                        tolerance=tolerance)
                if merged_facelist:
                    merged_fullfacelist.extend(merged_facelist)
                else:
                    merged_fullfacelist.extend(shell_faces)
        else:
            merged_fullfacelist.extend(snfaces)

    nmerged_face = len(merged_fullfacelist)

    if len(merged_fullfacelist) > 1:
        fshell2 = construct.make_shell_frm_faces(merged_fullfacelist,
                                                 tolerance=tolerance)
        fshell2 = fix_shell_orientation(fshell2[0])
        nfshell2_face = len(fetch.geom_explorer(fshell2, "face"))
        if nfshell2_face != nmerged_face:
            return occshell
    else:
        #if there is only one face it means its an open shell
        fshell2 = construct.make_shell(merged_fullfacelist)

    return fshell2
Пример #4
0
def generate_falsecolour_bar(minval, maxval, unit_str, bar_length, 
                             description_str = None, bar_pos = (0,0,0),
                             inverse = False):
    """
    This function constructs a falsecolour diagram.
 
    Parameters
    ----------
    minval : float
        The minimum value of the falsecolour bar.
        
    maxval : float
        The maximum value of the falsecolour bar.
        
    unit_str : str
        The string of the unit to be displayed on the bar.
        
    bar_length : float
        The length of the falsecolour bar.
        
    description_str : str, optional
        Description for the falsecolour bar, Default = None.
        
    bar_pos : tuple of floats, optional
        The position of the bar, Default = (0,0,0).
    
    inverse : bool
        False for red being max, True for blue being maximum.
        
    Returns
    -------
    falsecolour bar : list of OCCfaces
        The falsecolor bar which is a list of OCCfaces. 
        
    bar colour : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the bar.
        
    geometries of text: OCCcompound
        The geometries of the text.
        
    str_colour_list : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the string.
        
    value of each falsecolour : list of floats
        The value of each falsecolour.
    """
    import numpy
    interval = 10.0
    xdim = bar_length/interval
    ydim = bar_length
    rectangle = construct.make_rectangle(xdim, ydim)
    rec_mid_pt = calculate.face_midpt(rectangle)
    moved_rectangle = fetch.topo2topotype(modify.move(rec_mid_pt, bar_pos, rectangle))
    
    grid_srfs = construct.grid_face(moved_rectangle, xdim, xdim)

    #generate uniform results between max and min
    inc1 = (maxval-minval)/(interval)
    value_range = list(numpy.arange(minval, maxval+0.1, inc1))
    inc2 = inc1/2.0
    value_range_midpts = list(numpy.arange(minval+inc2, maxval, inc1))
    bar_colour = falsecolour(value_range_midpts, minval, maxval, inverse=inverse)
    grid_srfs2 = []
    moved_str_face_list = []
    srf_cnt = 0
    for srf in grid_srfs:
        reversed_srf = modify.reverse_face(srf)
        grid_srfs2.append(reversed_srf)
        res_label = round(value_range[srf_cnt],2)
        brep_str = fetch.topo2topotype(construct.make_brep_text(str(res_label), xdim/2))
        orig_pt = calculate.get_centre_bbox(brep_str)
        loc_pt = calculate.face_midpt(srf)
        loc_pt = modify.move_pt(loc_pt, (1,-0.3,0), xdim*1.2)
        moved_str = modify.move(orig_pt, loc_pt, brep_str)
        moved_str_face_list.append(moved_str)
        
        if srf_cnt == len(grid_srfs)-1:
            res_label = round(value_range[srf_cnt+1],2)
            brep_str = fetch.topo2topotype(construct.make_brep_text(str(res_label), xdim/2))
            orig_pt = calculate.get_centre_bbox(brep_str)
            loc_pt3 = modify.move_pt(loc_pt, (0,1,0), xdim)
            moved_str = modify.move(orig_pt, loc_pt3, brep_str)
            moved_str_face_list.append(moved_str)
        
            brep_str_unit = construct.make_brep_text(str(unit_str), xdim)
            orig_pt2 = calculate.get_centre_bbox(brep_str_unit)
            loc_pt2 = modify.move_pt(loc_pt, (0,1,0), xdim*2)
            moved_str = modify.move(orig_pt2, loc_pt2, brep_str_unit)
            moved_str_face_list.append(moved_str)
            
        if description_str !=None:    
            if srf_cnt == 0:
                d_str = fetch.topo2topotype(construct.make_brep_text(description_str, xdim/2))
                orig_pt2 = calculate.get_centre_bbox(d_str)
                loc_pt2 = modify.move_pt(loc_pt, (0,-1,0), xdim*5)
                moved_str = modify.move(orig_pt2, loc_pt2, d_str)
                moved_str_face_list.append(moved_str)
            

        srf_cnt+=1
        
    cmpd = construct.make_compound(moved_str_face_list)
    face_list = fetch.topo_explorer(cmpd, "face")
    meshed_list = []
    for face in face_list:    
        meshed_face_list = construct.simple_mesh(face)
        mface = construct.make_shell(meshed_face_list)
        face_mid_pt =  calculate.face_midpt(face)
        str_mid_pt = calculate.get_centre_bbox(mface)
        moved_mface = modify.move(str_mid_pt,face_mid_pt,mface)
        meshed_list.append(moved_mface)
        
    meshed_str_cmpd =construct.make_compound(meshed_list)
    str_colour_list = [(0,0,0)]
    return grid_srfs2, bar_colour, meshed_str_cmpd, str_colour_list, value_range_midpts
Пример #5
0
def generate_falsecolour_bar(minval,
                             maxval,
                             unit_str,
                             bar_length,
                             description_str=None,
                             bar_pos=(0, 0, 0),
                             inverse=False):
    """
    This function constructs a falsecolour diagram.
 
    Parameters
    ----------
    minval : float
        The minimum value of the falsecolour bar.
        
    maxval : float
        The maximum value of the falsecolour bar.
        
    unit_str : str
        The string of the unit to be displayed on the bar.
        
    bar_length : float
        The length of the falsecolour bar.
        
    description_str : str, optional
        Description for the falsecolour bar, Default = None.
        
    bar_pos : tuple of floats, optional
        The position of the bar, Default = (0,0,0).
    
    inverse : bool
        False for red being max, True for blue being maximum.
        
    Returns
    -------
    falsecolour bar : list of OCCfaces
        The falsecolor bar which is a list of OCCfaces. 
        
    bar colour : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the bar.
        
    geometries of text: OCCcompound
        The geometries of the text.
        
    str_colour_list : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the string.
        
    value of each falsecolour : list of floats
        The value of each falsecolour.
    """
    import numpy
    interval = 10.0
    xdim = bar_length / interval
    ydim = bar_length
    rectangle = construct.make_rectangle(xdim, ydim)
    rec_mid_pt = calculate.face_midpt(rectangle)
    moved_rectangle = fetch.topo2topotype(
        modify.move(rec_mid_pt, bar_pos, rectangle))

    grid_srfs = construct.grid_face(moved_rectangle, xdim, xdim)

    #generate uniform results between max and min
    inc1 = (maxval - minval) / (interval)
    value_range = list(numpy.arange(minval, maxval + 0.1, inc1))
    inc2 = inc1 / 2.0
    value_range_midpts = list(numpy.arange(minval + inc2, maxval, inc1))
    bar_colour = falsecolour(value_range_midpts,
                             minval,
                             maxval,
                             inverse=inverse)
    grid_srfs2 = []
    moved_str_face_list = []
    srf_cnt = 0
    for srf in grid_srfs:
        reversed_srf = modify.reverse_face(srf)
        grid_srfs2.append(reversed_srf)
        res_label = round(value_range[srf_cnt], 2)
        brep_str = fetch.topo2topotype(
            construct.make_brep_text(str(res_label), xdim / 2))
        orig_pt = calculate.get_centre_bbox(brep_str)
        loc_pt = calculate.face_midpt(srf)
        loc_pt = modify.move_pt(loc_pt, (1, -0.3, 0), xdim * 1.2)
        moved_str = modify.move(orig_pt, loc_pt, brep_str)
        moved_str_face_list.append(moved_str)

        if srf_cnt == len(grid_srfs) - 1:
            res_label = round(value_range[srf_cnt + 1], 2)
            brep_str = fetch.topo2topotype(
                construct.make_brep_text(str(res_label), xdim / 2))
            orig_pt = calculate.get_centre_bbox(brep_str)
            loc_pt3 = modify.move_pt(loc_pt, (0, 1, 0), xdim)
            moved_str = modify.move(orig_pt, loc_pt3, brep_str)
            moved_str_face_list.append(moved_str)

            brep_str_unit = construct.make_brep_text(str(unit_str), xdim)
            orig_pt2 = calculate.get_centre_bbox(brep_str_unit)
            loc_pt2 = modify.move_pt(loc_pt, (0, 1, 0), xdim * 2)
            moved_str = modify.move(orig_pt2, loc_pt2, brep_str_unit)
            moved_str_face_list.append(moved_str)

        if description_str != None:
            if srf_cnt == 0:
                d_str = fetch.topo2topotype(
                    construct.make_brep_text(description_str, xdim / 2))
                orig_pt2 = calculate.get_centre_bbox(d_str)
                loc_pt2 = modify.move_pt(loc_pt, (0, -1, 0), xdim * 5)
                moved_str = modify.move(orig_pt2, loc_pt2, d_str)
                moved_str_face_list.append(moved_str)

        srf_cnt += 1

    cmpd = construct.make_compound(moved_str_face_list)
    face_list = fetch.topo_explorer(cmpd, "face")
    meshed_list = []
    for face in face_list:
        meshed_face_list = construct.simple_mesh(face)
        mface = construct.make_shell(meshed_face_list)
        face_mid_pt = calculate.face_midpt(face)
        str_mid_pt = calculate.get_centre_bbox(mface)
        moved_mface = modify.move(str_mid_pt, face_mid_pt, mface)
        meshed_list.append(moved_mface)

    meshed_str_cmpd = construct.make_compound(meshed_list)
    str_colour_list = [(0, 0, 0)]
    return grid_srfs2, bar_colour, meshed_str_cmpd, str_colour_list, value_range_midpts
Пример #6
0
def write_2_collada(dae_filepath,
                    occface_list=None,
                    face_rgb_colour_list=None,
                    occedge_list=None,
                    text_string=None):
    """
    This function writes a 3D model into a Collada file.
 
    Parameters
    ----------
    dae_filepath : str
        The file path of the DAE (Collada) file.
        
    occface_list : list of OCCfaces, optional
        The geometries to be visualised with the results. The list of geometries must correspond to the list of results. Other OCCtopologies
        are also accepted, but the OCCtopology must contain OCCfaces. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, 
        OCCsolid, OCCshell, OCCface. 
        
    face_rgb_colour_list : list of tuple of floats, optional
        Each tuple is a r,g,b that is specifying the colour of the face,Default = None. 
        The number of colours must correspond to the number of OCCfaces.
        
    occedge_list : list of OCCedges, optional
        OCCedges to be visualised together, Default = None.
        
    text_string : str, optional
        Description for the 3D model, Default = None.
        
    Returns
    -------
    None : None
        The geometries are written to a DAE file.
    """
    if text_string != None:
        if occface_list != None:
            overall_cmpd = construct.make_compound(occface_list)
        else:
            overall_cmpd = construct.make_compound(occedge_list)
            occface_list = []

        xmin, ymin, zmin, xmax, ymax, zmax = calculate.get_bounding_box(
            overall_cmpd)
        xdim = xmax - xmin
        d_str = fetch.topo2topotype(
            construct.make_brep_text(text_string, xdim / 10))
        xmin1, ymin1, zmin1, xmax1, ymax1, zmax1 = calculate.get_bounding_box(
            d_str)
        corner_pt = (xmin1, ymax1, zmin1)
        corner_pt2 = (xmin, ymin, zmin)
        moved_str = modify.move(corner_pt, corner_pt2, d_str)
        face_list = fetch.topo_explorer(moved_str, "face")
        meshed_list = []
        for face in face_list:
            meshed_face_list = construct.simple_mesh(face)
            mface = construct.make_shell(meshed_face_list)
            face_mid_pt = calculate.face_midpt(face)
            str_mid_pt = calculate.get_centre_bbox(mface)
            moved_mface = modify.move(str_mid_pt, face_mid_pt, mface)
            meshed_list.append(moved_mface)

        meshed_str_cmpd = construct.make_compound(meshed_list)
        occface_list.append(meshed_str_cmpd)

        if face_rgb_colour_list != None:
            face_rgb_colour_list.append((0, 0, 0))

    mesh = occtopo_2_collada(dae_filepath,
                             occface_list=occface_list,
                             face_rgb_colour_list=face_rgb_colour_list,
                             occedge_list=occedge_list)

    mesh.write(dae_filepath)