Example #1
0
def points_frm_wire(occ_wire):
    '''
    vertex_list = geom_explorer(occ_wire, TopAbs_VERTEX)
    point_list = vertex_list_2_point_list(vertex_list)
    
    n_pt_list = []
    for pt in point_list:
        if n_pt_list:
            p_vert = (n_pt_list[-1].X(), n_pt_list[-1].Y(), n_pt_list[-1].Z())
            c_vert = (pt.X(), pt.Y(), pt.Z())
            if c_vert != p_vert:
                n_pt_list.append(pt)
        else:
            n_pt_list.append(pt)
    
    return n_pt_list
    '''
    #TODO: WHEN DEALING WITH OPEN WIRE IT WILL NOT RETURN THE LAST VERTEX
    verts = Topology.WireExplorer(occ_wire).ordered_vertices()
    point_list = []
    for vert in verts:
        pt = BRep_Tool.Pnt(vert)
        point_list.append(pt)

    #this always returns points in order that is opposite of the input
    #e.g. if the inputs are clockwise it will ouput anticlockwise
    #e.g. if the inputs are anticlockwise it will ouput clockwise
    #thus the point list needs to be reversed to reflect the true order
    #point_list = list(reversed(point_list))

    return point_list
Example #2
0
def project_face_on_faceplane(occface2projon, occface2proj):
    """
    This function projects the OCCface onto another OCCface plane. The plane stretches through infinity.
 
    Parameters
    ----------
    occface2projon : OCCface
        The OCCface to be projected on.
        
    occface2proj : OCCface
        The OCCface to be projected.
        
    Returns
    -------
    list of points : pyptlist
        The list of projected points.
    """

    wire_list = list(Topology.Topo(occface2proj).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)
    proj_ptlist = []
    for occpt in occpt_list:
        occ_pnt = BRep_Tool.Pnt(occpt)
        pypt = (occ_pnt.X(), occ_pnt.Y(), occ_pnt.Z())
        projected_pt = project_point_on_faceplane(pypt, occface2projon)
        proj_ptlist.append(projected_pt)

    return proj_ptlist
Example #3
0
def srf_nrml_facing_solid_inward(occ_face, occ_solid):
    #move the face in the direction of the normal
    #first offset the face so that vert will be within the solid
    o_wire = Construct.make_offset(occ_face, 0.0001)
    o_face = BRepBuilderAPI_MakeFace(o_wire).Face()

    wire_list = list(Topology.Topo(o_face).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)

    pt = BRep_Tool.Pnt(occpt_list[0])  #a point that is on the edge of the face
    normal = face_normal(occ_face)

    gp_direction2move = gp_Vec(normal[0], normal[1], normal[2])
    gp_moved_pt = pt.Translated(gp_direction2move.Multiplied(0.001))
    mv_pt = (gp_moved_pt.X(), gp_moved_pt.Y(), gp_moved_pt.Z())

    in_solid = point_in_solid(occ_solid, mv_pt)

    if in_solid:
        return True
    else:
        return False
Example #4
0
def project_face_on_faceplane(occface2projon, occface2proj):
    wire_list = list(Topology.Topo(occface2proj).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)
    proj_ptlist = []
    for occpt in occpt_list:
        occ_pnt = BRep_Tool.Pnt(occpt)
        pypt = (occ_pnt.X(), occ_pnt.Y(), occ_pnt.Z())
        projected_pt = project_point_on_faceplane(occface2projon, pypt)
        proj_ptlist.append(projected_pt)

    return proj_ptlist
Example #5
0
def edges_frm_wire(occwire):
    """
    This function fetches a list of OCCedges from the OCCwire. The wire is constructed based on the list of edges.
 
    Parameters
    ----------
    occwire : OCCwire
        The OCCwire to be examined.
        
    Returns
    -------
    list of edges : list of OCCedges
        The list of OCCedges extracted from the OCCwire.
    """
    edge_list = Topology.WireExplorer(occwire).ordered_edges()
    return list(edge_list)
Example #6
0
def getPolygonesFromShape(shape):
    from Geometry.Geom3D import Pnt3D,Poly3D

    exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_WIRE)  # .TopAbs_FACE)
    polygons = []
    while exp.More():
        wire = TopoDS.topods.Wire(TopoDS.topods.Wire(exp.Current()))
        exp.Next()
        points = []
        from OCCUtils import Topology
        explorer = Topology.WireExplorer(wire)
        vertices = explorer.ordered_vertices()
        for vertex in vertices:
            pnt = BRep.BRep_Tool_Pnt(vertex)
            points.append(Pnt3D(pnt.X(),pnt.Y(),pnt.Z()))
        polygons.append(Poly3D(points))

    return polygons
Example #7
0
def points_frm_wire(occwire):
    """
    This function fetches a list of points from the OCCwire. The wire is constructed based on the list of points.
    TODO: WHEN DEALING WITH OPEN WIRE IT WILL NOT RETURN THE LAST VERTEX
 
    Parameters
    ----------
    occwire : OCCwire
        The OCCwire to be examined.
        
    Returns
    -------
    list of points : pyptlist
        The list of points extracted from the OCCwire.
    """
    verts = list(Topology.WireExplorer(occwire).ordered_vertices())
    point_list = modify.occvertex_list_2_occpt_list(verts)
    pyptlist = modify.occpt_list_2_pyptlist(point_list)
    return pyptlist
Example #8
0
def srf_nrml_facing_solid_inward(occface, occsolid):
    """
    This function checks if the OCCface is facing the inside of the OCCsolid.
 
    Parameters
    ----------
    occface : OCCface
        The OCCface to be checked.
        
    occsolid : OCCsolid
        The OCCsolid.
        
    Returns
    -------
    True or False : bool
        If True the face is facing the inside of the solid, if False the face is not facing inwards.
    """
    #move the face in the direction of the normal
    #first offset the face so that vert will be within the solid
    o_wire = Construct.make_offset(occface, 0.0001)
    o_face = BRepBuilderAPI_MakeFace(o_wire).Face()

    wire_list = list(Topology.Topo(o_face).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)

    pt = BRep_Tool.Pnt(occpt_list[0])  #a point that is on the edge of the face
    normal = face_normal(occface)

    gp_direction2move = gp_Vec(normal[0], normal[1], normal[2])
    gp_moved_pt = pt.Translated(gp_direction2move.Multiplied(0.001))
    mv_pt = (gp_moved_pt.X(), gp_moved_pt.Y(), gp_moved_pt.Z())

    in_solid = point_in_solid(occsolid, mv_pt)

    if in_solid:
        return True
    else:
        return False
Example #9
0
def edges_frm_wire(occ_wire):
    edge_list = Topology.WireExplorer(occ_wire).ordered_edges()
    return list(edge_list)