Exemple #1
0
def wire_frm_loose_edges(occedge_list):
    '''
    the edges need to be able to form a close face. IT does not work with a group of open edges
    need to change name to face from loose edges
    '''
    edges = TopTools_HSequenceOfShape()
    edges_handle = Handle_TopTools_HSequenceOfShape(edges)

    wires = TopTools_HSequenceOfShape()
    wires_handle = Handle_TopTools_HSequenceOfShape(wires)

    # The edges are copied to the sequence
    for edge in occedge_list:
        edges.Append(edge)

    # A wire is formed by connecting the edges
    ShapeAnalysis_FreeBounds.ConnectEdgesToWires(edges_handle, 1e-20, True,
                                                 wires_handle)
    wires = wires_handle.GetObject()

    # From each wire a face is created
    face_list = []
    for i in range(wires.Length()):
        wire_shape = wires.Value(i + 1)
        wire = fetch.shape2shapetype(wire_shape)
        face = BRepBuilderAPI_MakeFace(wire).Face()
        if not face.IsNull():
            face_list.append(face)

    return face_list
Exemple #2
0
def extrude_edge(occedge, pydirection, height):
    edge_midpt = calculate.edge_midpt(occedge)
    location_pt = modify.move_pt(edge_midpt, pydirection, height)
    edge2 = fetch.shape2shapetype(modify.move(edge_midpt, location_pt,
                                              occedge))
    edge_wire = make_wire_frm_edges([occedge])
    edge_wire2 = make_wire_frm_edges([edge2])
    edgeface = make_loft_with_wires([edge_wire, edge_wire2])
    facelist = fetch.geom_explorer(edgeface, "face")
    return facelist[0]
Exemple #3
0
def make_shell_frm_faces(occ_face_list, tolerance=1e-06):
    #make shell
    sewing = BRepBuilderAPI_Sewing()
    sewing.SetTolerance(tolerance)
    for f in occ_face_list:
        sewing.Add(f)

    sewing.Perform()
    sewing_shape = fetch.shape2shapetype(sewing.SewedShape())
    #topo_dict = fetch.topos_frm_compound(sewing_shape)
    #shell_list = topo_dict["shell"]
    shell_list = fetch.geom_explorer(sewing_shape, "shell")
    return shell_list
Exemple #4
0
def grid_face(occ_face, udim, vdim):
    #returns a series of polygons
    pt_list = []
    face_list = []
    fc = face.Face(occ_face)
    umin, umax, vmin, vmax = fc.domain()
    u_div = int(math.ceil((umax - umin) / udim))
    v_div = int(math.ceil((vmax - vmin) / vdim))
    for ucnt in range(u_div + 1):
        for vcnt in range(v_div + 1):
            u = umin + (ucnt * udim)
            v = vmin + (vcnt * vdim)
            occpt = fc.parameter_to_point(u, v)
            pt = [occpt.X(), occpt.Y(), occpt.Z()]
            pt_list.append(pt)

    for pucnt in range(u_div):
        for pvcnt in range(v_div):
            pcnt = pucnt * (v_div + 1) + pvcnt
            #print pcnt
            pt1 = pt_list[pcnt]
            pt2 = pt_list[pcnt + v_div + 1]
            pt3 = pt_list[pcnt + v_div + 2]
            pt4 = pt_list[pcnt + 1]
            occface = make_polygon([pt1, pt2, pt3, pt4])
            face_list.append(occface)

    #intersect the grids and the face so that those grids that are not in the face will be erase
    intersection_list = []
    for f in face_list:
        intersection = BRepAlgoAPI_Common(f, occ_face).Shape()
        compound = fetch.shape2shapetype(intersection)
        inter_face_list = fetch.topos_frm_compound(compound)["face"]
        if inter_face_list:
            for inter_face in inter_face_list:
                intersection_list.append(inter_face)
    return intersection_list
Exemple #5
0
def flatten_shell_z_value(occshell, z=0):
    #face_list = fetch.faces_frm_solid(occshell)
    xmin, ymin, zmin, xmax, ymax, zmax = calculate.get_bounding_box(occshell)
    boundary_pyptlist = [[xmin, ymin, zmin], [xmax, ymin, zmin],
                         [xmax, ymax, zmin], [xmin, ymax, zmin]]
    boundary_face = construct.make_polygon(boundary_pyptlist)
    b_mid_pt = calculate.face_midpt(boundary_face)
    flatten_shell = fetch.shape2shapetype(
        uniform_scale(occshell, 1, 1, 0, b_mid_pt))
    face_list = construct.simple_mesh(flatten_shell)
    #face_list = fetch.geom_explorer(flatten_shell,"face")
    nfaces = len(face_list)
    merged_faces = construct.merge_faces(face_list)
    dest_pt = [b_mid_pt[0], b_mid_pt[1], z]
    #depending on how complicated is the shell we decide which is the best way to flatten it
    #1.) if it is an open shell and when everything is flatten it fits nicely as a flat surface
    if len(merged_faces) == 1:
        flatten_face = fetch.shape2shapetype(
            move(b_mid_pt, dest_pt, merged_faces[0]))
        return flatten_face

    #2.) if it is a complex shell with less than 500 faces we fused and create a single surface
    if nfaces < 50:
        try:
            fused_shape = None
            fcnt = 0
            for face in face_list:
                face_area = calculate.face_area(face)
                if not face_area < 0.001:
                    if fcnt == 0:
                        fused_shape = face
                    else:
                        #construct.visualise([[fused_shape], [face]], ['WHITE', 'RED'])
                        fused_shape = construct.boolean_fuse(fused_shape, face)
                    fcnt += 1

            if fused_shape != None:
                fused_face_list = fetch.geom_explorer(fused_shape, "face")
                merged_faces = construct.merge_faces(fused_face_list)
                if len(merged_faces) == 1:
                    flatten_face = fetch.shape2shapetype(
                        move(b_mid_pt, dest_pt, merged_faces[0]))
                    return flatten_face
                else:
                    flatten_vertex = fetch.geom_explorer(
                        flatten_shell, "vertex")
                    flatten_pts = fetch.vertex_list_2_point_list(
                        flatten_vertex)
                    flatten_pypts = fetch.occptlist2pyptlist(flatten_pts)
                    dface_list = construct.delaunay3d(flatten_pypts)
                    merged_faces = construct.merge_faces(dface_list)
                    if len(merged_faces) == 1:
                        flatten_face = fetch.shape2shapetype(
                            move(b_mid_pt, dest_pt, merged_faces[0]))
                        return flatten_face
                    else:
                        #construct.visualise([[occshell]],["WHITE"])
                        return None
        except RuntimeError:
            flatten_vertex = fetch.geom_explorer(flatten_shell, "vertex")
            flatten_pts = fetch.vertex_list_2_point_list(flatten_vertex)
            flatten_pypts = fetch.occptlist2pyptlist(flatten_pts)
            dface_list = construct.delaunay3d(flatten_pypts)
            merged_faces = construct.merge_faces(dface_list)
            if len(merged_faces) == 1:
                flatten_face = fetch.shape2shapetype(
                    move(b_mid_pt, dest_pt, merged_faces[0]))
                return flatten_face
            else:
                #construct.visualise([[occshell]],["WHITE"])
                return None

    #3.) if it is a complex shell with more than 500 faces we get the vertexes and create a triangulated srf with delaunay
    #and merge all the faces to make a single surface
    if nfaces >= 50:
        flatten_vertex = fetch.geom_explorer(flatten_shell, "vertex")
        flatten_pts = fetch.vertex_list_2_point_list(flatten_vertex)
        flatten_pypts = fetch.occptlist2pyptlist(flatten_pts)
        #flatten_pypts = rmv_duplicated_pts_by_distance(flatten_pypts, tolerance = 1e-04)
        dface_list = construct.delaunay3d(flatten_pypts)
        merged_faces = construct.merge_faces(dface_list)
        if len(merged_faces) == 1:
            flatten_face = fetch.shape2shapetype(
                move(b_mid_pt, dest_pt, merged_faces[0]))
            return flatten_face
        else:
            #construct.visualise([[occshell]],["WHITE"])
            return None
Exemple #6
0
def reverse_face(occ_face):
    #reverse the face
    occ_face_r = fetch.shape2shapetype(occ_face.Reversed())
    return occ_face_r
Exemple #7
0
def boolean_difference(occshape2cutfrm, occ_cuttingshape):
    difference = Construct.boolean_cut(occshape2cutfrm, occ_cuttingshape)
    compound = fetch.shape2shapetype(difference)
    return compound
Exemple #8
0
def boolean_fuse(occshape1, occshape2):
    fused = Construct.boolean_fuse(occshape1, occshape2)
    compound = fetch.shape2shapetype(fused)
    return compound
Exemple #9
0
def boolean_common(occ_shape1, occ_shape2):
    intersection = BRepAlgoAPI_Common(occ_shape1, occ_shape2).Shape()
    compound = fetch.shape2shapetype(intersection)
    return compound
Exemple #10
0
def make_offset_face2wire(occ_face, offset_value):
    o_wire = Construct.make_offset(occ_face, offset_value)
    return fetch.shape2shapetype(o_wire)
Exemple #11
0
def make_box(length, width, height):
    box = fetch.shape2shapetype(
        BRepPrimAPI_MakeBox(length, width, height).Shape())
    return box