Exemplo n.º 1
0
 def __init__(self, pnt):
     if isinstance(pnt, (list, tuple)):
         self._coord = list(pnt)
     elif isinstance(pnt, gp_Pnt):
         self._coord = [pnt.X(), pnt.Y(), pnt.Z()]
     elif isinstance(pnt, TopoDS_Vertex):
         pnt = BRep_Tool.Pnt(pnt)
         self._coord = [pnt.X(), pnt.Y(), pnt.Z()]
     elif isinstance(pnt, TopoDS_Shape):
         pnt = BRep_Tool.Pnt(TopoDS_Vertex(pnt))
         self._coord = [pnt.X(), pnt.Y(), pnt.Z()]
     else:
         raise TypeError
Exemplo n.º 2
0
class LoopWirePairs(object):
    '''
    for looping through consequtive wires
    assures that the returned edge pairs are ordered
    '''
    def __init__(self, wireA, wireB):
        self.wireA = wireA
        self.wireB = wireB
        self.we_A = WireExplorer(self.wireA)
        self.we_B = WireExplorer(self.wireB)
        self.tp_A = Topo(self.wireA)
        self.tp_B = Topo(self.wireB)

        self.bt = BRep_Tool()
        self.vertsA = [v for v in self.we_A.ordered_vertices()]
        self.vertsB = [v for v in self.we_B.ordered_vertices()]

        self.edgesA = [v for v in WireExplorer(wireA).ordered_edges()]
        self.edgesB = [v for v in WireExplorer(wireB).ordered_edges()]

        self.pntsB = [self.bt.Pnt(v) for v in self.vertsB]
        self.number_of_vertices = len(self.vertsA)
        self.index = 0

    def closest_point(self, vertexFromWireA):
        pt = self.bt.Pnt(vertexFromWireA)
        distances = [pt.Distance(i) for i in self.pntsB]
        indx_max_dist = distances.index(min(distances))
        return self.vertsB[indx_max_dist]

    def next(self):
        if self.index == self.number_of_vertices:
            raise StopIteration

        vert = self.vertsA[self.index]
        closest = self.closest_point(vert)
        edges_a = self.tp_A.edges_from_vertex(vert)
        edges_b = self.tp_B.edges_from_vertex(closest)
        a1, a2 = Edge(edges_a.next()), Edge(edges_a.next())
        b1, b2 = Edge(edges_b.next()), Edge(edges_b.next())
        mpA = a1.mid_point()
        self.index += 1

        if mpA.Distance(b1.mid_point()) < mpA.Distance(b2.mid_point()):
            return iter([a1, a2]), iter([b1, b2])
        else:
            return iter([a1, a2]), iter([b2, b1])

    def __iter__(self):
        return self
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
def format_wire_for_roboDK(wire, is_reverse=False):
    vertices = sweeper.get_ordered_vertices_from_wire(wire)
    brt = BRep_Tool()
    wire = []
    last_path_direction = None
    for i in range(len(vertices)):
        index = i
        next_index = index + 1
        if is_reverse:
            index = len(vertices) - 1 - i
            next_index = index - 1
        v = vertices[index]
        pnt = brt.Pnt(topods_Vertex(v))
        normal = get_vertex_normal(v, front_face)
        if not ((index == 0 and is_reverse) or
                (index == len(vertices) - 1 and not is_reverse)):
            pnt_next = brt.Pnt(topods_Vertex(vertices[next_index]))
            mat_pnt = numpy.mat([pnt.X(), pnt.Y(), pnt.Z()])
            mat_pnt_next = numpy.mat(
                [pnt_next.X(), pnt_next.Y(),
                 pnt_next.Z()])
            path_direction = mat_pnt_next - mat_pnt
            path_direction = path_direction / scipy.linalg.norm(path_direction)
            last_path_direction = path_direction
        else:
            path_direction = last_path_direction
        #direction should be away from base_position
        p1 = [pnt.X() + normal.X(), pnt.Y() + normal.Y(), pnt.Z() + normal.Z()]
        p2 = [pnt.X() - normal.X(), pnt.Y() - normal.Y(), pnt.Z() - normal.Z()]
        #normal vector should point towards base_position
        if sweeper.get_distance_points(
                p1, sweeper.base_position) < sweeper.get_distance_points(
                    p2, sweeper.base_position):
            direction = [normal.X(), normal.Y(), normal.Z()]
        else:
            direction = [-normal.X(), -normal.Y(), -normal.Z()]
        wire.append({
            "location": [pnt.X(), pnt.Y(), pnt.Z()],
            "direction":
            direction,
            "path_direction": [
                path_direction.item(0),
                path_direction.item(1),
                path_direction.item(2)
            ]
        })
    return wire
Exemplo n.º 7
0
def points_frm_solid(occ_solid):
    verts = Topology.Topo(occ_solid).vertices()
    point_list = []
    for vert in verts:
        pt = BRep_Tool.Pnt(vert)
        point_list.append(pt)

    return point_list
Exemplo n.º 8
0
def vertex_clicked(shp, *kwargs):
    """ This function is called whenever a vertex is selected
    """
    for shape in shp:  # this should be a TopoDS_Vertex
        print("Face selected: ", shape)
        v = topods_Vertex(shape)
        pnt = BRep_Tool.Pnt(v)
        print("3d gp_Pnt selected coordinates : X=", pnt.X(), "Y=", pnt.Y(),
              "Z=", pnt.Z())
        # then convert to screen coordinates
        screen_coord = display.View.Convert(pnt.X(), pnt.Y(), pnt.Z())
        print("2d screen coordinates : ", screen_coord)
Exemplo n.º 9
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
Exemplo n.º 10
0
    def project_vertex(self, pnt, tol=TOLERANCE) -> gp_Pnt:
        """projects self with a point, curve, edge, face, solid
        method wraps dealing with the various topologies

        if other is a point:
            returns uv, point

        """
        if isinstance(pnt, TopoDS_Vertex):
            pnt = BRep_Tool.Pnt(pnt)

        proj = GeomAPI_ProjectPointOnSurf(pnt, self.surface_handle, tol)
        # uv = proj.LowerDistanceParameters()
        proj_pnt = proj.NearestPoint()
        return proj_pnt
Exemplo n.º 11
0
def occvertex_2_occpt(occvertex):
    """
    This function constructs an OCC point (gp_pnt) from an OCCvertex.
 
    Parameters
    ----------
    occvertex : OCCvertex
        OCCvertex to be converted to a OCC point (gp_pnt).
        
    Returns
    -------
    point : OCC point (gp_pnt)
        An OCC point constructed from the OCCvertex.
    """
    occ_pnt = BRep_Tool.Pnt(occvertex)
    return occ_pnt
Exemplo n.º 12
0
 def __init__(self, pnt):
     if isinstance(pnt, (list, tuple)):
         gp_Pnt.__init__(self, *pnt)
     elif isinstance(pnt, vec):
         gp_Pnt.__init__(self, *pnt)
     elif isinstance(pnt, gp_Pnt):
         gp_Pnt.__init__(self, pnt)
     elif isinstance(pnt, TopoDS_Vertex):
         # convert to type "gp_Pnt"
         gp_Pnt.__init__(self, BRep_Tool.Pnt(pnt))
     elif isinstance(pnt, TopoDS_Shape):
         self.brt = BRep_Tool()
         self.pnt1 = self.brt.Pnt(topods_Vertex(pnt))
         gp_Pnt.__init__(self, self.pnt1.XYZ())
     else:
         raise TypeError
Exemplo n.º 13
0
def dumpTopology(shape, level=0):
    """
     Print the details of an object from the top down
    """
    brt = BRep_Tool()
    s = shape.ShapeType()
    if s == TopAbs_VERTEX:
        pnt = brt.Pnt(topods_Vertex(shape))
        print(".." * level  + "<Vertex %i: %s %s %s>" % (hash(shape), pnt.X(), pnt.Y(), pnt.Z()))
    else:
        print(".." * level, end="")
        print(shapeTypeString(shape))
    it = TopoDS_Iterator(shape)
    while it.More():
        shp = it.Value()
        it.Next()
        dumpTopology(shp, level + 1)
Exemplo n.º 14
0
def dump_topology_to_string(shape, level=0, buffer=""):
    """
    Reutnrs the details of an object from the top down
    """
    brt = BRep_Tool()
    s = shape.ShapeType()
    if s == TopAbs_VERTEX:
        pnt = brt.Pnt(topods_Vertex(shape))
        print(".." * level + "<Vertex %i: %s %s %s>\n" %
              (hash(shape), pnt.X(), pnt.Y(), pnt.Z()))
    else:
        print(".." * level, end="")
        print(shape_type_string(shape))
    it = TopoDS_Iterator(shape)
    while it.More() and level < 5:  # LEVEL MAX
        shp = it.Value()
        it.Next()
        print(dump_topology_to_string(shp, level + 1, buffer))
Exemplo n.º 15
0
def occvertex_list_2_occpt_list(occvertex_list):
    """
    This function constructs a list of OCC points (gp_pnt) from a list of OCCvertices.
 
    Parameters
    ----------
    occvertex_list : list of OCCvertices
        List of OCCvertices to be converted to a list of OCC points (gp_pnt).
        
    Returns
    -------
    list of points : list of OCC points (gp_pnt)
        A list of OCC points (gp_pnt) constructed from the list of OCCvertices.
    """
    point_list = []
    for vert in occvertex_list:
        point_list.append(BRep_Tool.Pnt(vert))
    return point_list
Exemplo n.º 16
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
Exemplo n.º 17
0
 def DumpTop(self, shape, level=0):
     """
     Print the details of an object from the top down
     """
     brt = BRep_Tool()
     s = shape.ShapeType()
     if s == TopAbs_VERTEX:
         pnt = brt.Pnt(topods_Vertex(shape))
         dmp = " " * level
         dmp += "%s - " % shapeTypeString(shape)
         dmp += "%.5e %.5e %.5e" % (pnt.X(), pnt.Y(), pnt.Z())
         print(dmp)
     else:
         dmp = " " * level
         dmp += shapeTypeString(shape)
         print(dmp)
     it = TopoDS_Iterator(shape)
     while it.More():
         shp = it.Value()
         it.Next()
         self.DumpTop(shp, level + 1)
Exemplo n.º 18
0
    def project_vertex( self, other ):
        '''projects self with a point, curve, edge, face, solid
        method wraps dealing with the various topologies

        if other is a point:
            returns uv, point

        '''
        if isinstance(other, TopoDS_Face):
            raise AssertionError, 'Cannot project a face on another face'

        elif isinstance(other, TopoDS_Vertex):
            pt = BRep_Tool.Pnt(other)
            proj = GeomAPI_ProjectPointOnSurf(pt, self.surface_handle)
            # SHOULD USE THIS!!!
            #proj.LowerDistanceParameters()
            ext = proj.Extrema()
            for i in range(ext.NbExt()):
                if proj.Point().Coord() == ext.Point(i).Value().Coord():
                    result = ext.Point(i)
            uv = result.Parameter()
            pt = result.Value()
            return uv, pt
Exemplo n.º 19
0
def vertex_to_np(vertex):
    """returns a gp_Pnt from a TopoDS_Vertex"""
    return pnt_to_np(BRep_Tool.Pnt(vertex))
Exemplo n.º 20
0
def vertex2pnt(vertex):
    '''returns a gp_Pnt from a TopoDS_Vertex
    '''
    from OCC.BRep import BRep_Tool
    return BRep_Tool.Pnt(vertex)
    for face in tp.faces():
        ifcopenshell.geom.utils.display_shape(face)
        for edge in list(Topo(face).edges()):

            curve_handle, first, last = BRep_Tool.CurveOnSurface(
                edge, section_face)

            plane = Geom_Plane(section_plane)
            e = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(), first,
                                        last).Edge()
            #            handle_adaptor = Geom2dAdaptor_Curve(curve_handle)
            curve_adapt = BRepAdaptor_Curve(e)

            if curve_adapt.GetType() == GeomAbs_Line:
                v = list(Topo(e).vertices())
                y1, z1 = BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(v[0]).Z()
                y2, z2 = BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(v[-1]).Z()

                plt.plot([y1, y2], [z1, z2], color="red", alpha=0.2)
                ifcopenshell.geom.utils.display_shape(e, clr=RED)

#                line = curve_adapt.Line()
##                r = GCPnts_AbscissaPoint(handle_adaptor)
##                length = r.Parameter()
#                curve_adapt = BRepAdaptor_Curve(e)
#                length = GCPnts_AbscissaPoint().Length(curve_adapt, curve_adapt.FirstParameter(),
#                                              curve_adapt.LastParameter(), 1e-6)
#
#                y1, z1 = line.Location().X(), line.Location().Y()
#                y2, z2 = line.Location().X() + length*line.Direction().X(), line.Location().Y() + length*line.Direction().Y()
#
Exemplo n.º 22
0
class gp_Pnt_(gp_Pnt):
    """This is an extension of the gp_Pnt class.

    It provides a constructor that accepts lists and other types
    and allows accessing coordinate values through indices and slices
    as well as comparisons for equality
    >>> gp_Pnt_([4, 5, 42])
    gp_Pnt_([4.0, 5.0, 42.0])
    """

    def __init__(self, pnt):
        if isinstance(pnt, (list, tuple)):
            gp_Pnt.__init__(self, *pnt)
        elif isinstance(pnt, vec):
            gp_Pnt.__init__(self, *pnt)
        elif isinstance(pnt, gp_Pnt):
            gp_Pnt.__init__(self, pnt)
        elif isinstance(pnt, TopoDS_Vertex):
            # convert to type "gp_Pnt"
            gp_Pnt.__init__(self, BRep_Tool.Pnt(pnt))
        elif isinstance(pnt, TopoDS_Shape):
            self.brt = BRep_Tool()
            self.pnt1 = self.brt.Pnt(topods_Vertex(pnt))
            gp_Pnt.__init__(self, self.pnt1.XYZ())
        else:
            raise TypeError

    def __eq__(self, other):
        if type(self) == type(other):
            return self.IsEqual(other, 0)
        else:
            return False

    def __ne__(self, other):
        return not(self == other)

    def __sub__(self, other):
        return vec(self[i] - other[i] for i in range(3))

    def __getitem__(self, index):
        if index in [0, -3]:
            return self.X()
        elif index in [1, -2]:
            return self.Y()
        elif index in [2, -1]:
            return self.Z()
        elif isinstance(index, slice):
            return [self[i] for i in range(index.start or 0, index.stop or 3)]
        else:
            # this is needed for unpacking
            raise IndexError

    def __setitem__(self, index, value):
        if index == 0:
            self.SetX(value)
        elif index == 1:
            self.SetY(value)
        elif index == 2:
            self.SetZ(value)
        elif isinstance(index, slice):
            stop = index.stop or 3
            start = index.start or 0
            if start <= 0 < stop:
                self.SetX(value[0 - start])
            if start <= 1 < stop:
                self.SetY(value[1 - start])
            if start <= 2 < stop:
                self.SetZ(value[2 - start])
Exemplo n.º 23
0
def vertex2pnt(vertex) -> gp_Pnt:
    """returns a gp_Pnt from a TopoDS_Vertex"""
    return BRep_Tool.Pnt(vertex)
Exemplo n.º 24
0
    def toTuple(self):

        geom_point = BRep_Tool.Pnt(self.wrapped)
        return (geom_point.X(), geom_point.Y(), geom_point.Z())
Exemplo n.º 25
0
def vertex_list_2_point_list(occ_vertex_list):
    point_list = []
    for vert in occ_vertex_list:
        point_list.append(BRep_Tool.Pnt(vert))
    return point_list
Exemplo n.º 26
0
def vertex2point(occ_vertex):
    occ_pnt = BRep_Tool.Pnt(occ_vertex)
    return occ_pnt
Exemplo n.º 27
0
def vertex_to_tuple(vertex, rnd=3) -> Tuple:
    pnt = BRep_Tool.Pnt(vertex)
    return tuple(map(lambda x: round(x, rnd), [pnt.X(), pnt.Y(), pnt.Z()]))
Exemplo n.º 28
0
    def write_face(self, points_face, list_points_edge, topo_face, toledge):
        """
        Method to recreate a Face associated to a geometric surface
        after the modification of Face points. It returns a TopoDS_Face.

        :param points_face: the new face points array.
        :param list_points_edge: new edge points
        :param topo_face: the face to be modified
        :param toledge: tolerance on the surface creation after modification
        :return: TopoDS_Face (Shape)

        :rtype: TopoDS_Shape

        """

        # convert Face to Geom B-spline Surface
        nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_face)
        nurbs_converter.Perform(topo_face)
        nurbs_face = nurbs_converter.Shape()
        topo_nurbsface = topods.Face(nurbs_face)
        h_geomsurface = BRep_Tool.Surface(topo_nurbsface)
        h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface)
        bsurface = h_bsurface.GetObject()

        nb_u = bsurface.NbUPoles()
        nb_v = bsurface.NbVPoles()
        # check consistency
        if points_face.shape[0] != nb_u * nb_v:
            raise ValueError("Input control points do not have not have the "
                             "same number as the geometric face!")

        # cycle on the face points
        indice_cpt = 0
        for iu in range(1, nb_u + 1):
            for iv in range(1, nb_v + 1):
                cpt = points_face[indice_cpt]
                bsurface.SetPole(iu, iv, gp_Pnt(cpt[0], cpt[1], cpt[2]))
                indice_cpt += 1

        # create modified new face
        new_bspline_tface = BRepBuilderAPI_MakeFace()
        toler = precision_Confusion()
        new_bspline_tface.Init(bsurface.GetHandle(), False, toler)

        # cycle on the wires
        face_wires_explorer = TopExp_Explorer(
            topo_nurbsface.Oriented(TopAbs_FORWARD), TopAbs_WIRE)
        ind_edge_total = 0

        while face_wires_explorer.More():
            # get old wire
            twire = topods_Wire(face_wires_explorer.Current())

            # cycle on the edges
            ind_edge = 0
            wire_explorer_edge = TopExp_Explorer(
                twire.Oriented(TopAbs_FORWARD), TopAbs_EDGE)
            # check edges order on the wire
            mode3d = True
            tolerance_edges = toledge

            wire_order = ShapeAnalysis_WireOrder(mode3d, tolerance_edges)
            # an edge list
            deformed_edges = []
            # cycle on the edges
            while wire_explorer_edge.More():
                tedge = topods_Edge(wire_explorer_edge.Current())
                new_bspline_tedge = self.write_edge(
                    list_points_edge[ind_edge_total], tedge)

                deformed_edges.append(new_bspline_tedge)
                analyzer = topexp()
                vfirst = analyzer.FirstVertex(new_bspline_tedge)
                vlast = analyzer.LastVertex(new_bspline_tedge)
                pt1 = BRep_Tool.Pnt(vfirst)
                pt2 = BRep_Tool.Pnt(vlast)

                wire_order.Add(pt1.XYZ(), pt2.XYZ())

                ind_edge += 1
                ind_edge_total += 1
                wire_explorer_edge.Next()

            # grouping the edges in a wire, then in the face
            # check edges order and connectivity within the wire
            wire_order.Perform()
            # new wire to be created
            stol = ShapeFix_ShapeTolerance()
            new_bspline_twire = BRepBuilderAPI_MakeWire()
            for order_i in range(1, wire_order.NbEdges() + 1):
                deformed_edge_i = wire_order.Ordered(order_i)
                if deformed_edge_i > 0:
                    # insert the deformed edge to the new wire
                    new_edge_toadd = deformed_edges[deformed_edge_i - 1]
                    stol.SetTolerance(new_edge_toadd, toledge)
                    new_bspline_twire.Add(new_edge_toadd)
                    if new_bspline_twire.Error() != 0:
                        stol.SetTolerance(new_edge_toadd, toledge * 10.0)
                        new_bspline_twire.Add(new_edge_toadd)
                else:
                    deformed_edge_revers = deformed_edges[
                        np.abs(deformed_edge_i) - 1]
                    stol.SetTolerance(deformed_edge_revers, toledge)
                    new_bspline_twire.Add(deformed_edge_revers)
                    if new_bspline_twire.Error() != 0:
                        stol.SetTolerance(deformed_edge_revers, toledge * 10.0)
                        new_bspline_twire.Add(deformed_edge_revers)
            # add new wire to the Face
            new_bspline_tface.Add(new_bspline_twire.Wire())
            face_wires_explorer.Next()

        return topods.Face(new_bspline_tface.Face())
    for face in tp.faces():
        ifcopenshell.geom.utils.display_shape(face)
        for edge in list(Topo(face).edges()):

            curve_handle, first, last = BRep_Tool.CurveOnSurface(
                edge, section_face)

            plane = Geom_Plane(section_plane)

            e = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(), first,
                                        last).Edge()

            handle_adaptor = Geom2dAdaptor_Curve(curve_handle)
            if handle_adaptor.GetType() == GeomAbs_Line:
                v = list(Topo(e).vertices())
                x1, z1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Z()
                x2, z2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Z()
                plt.plot([x1, x2], [z1, z2], color="red", alpha=0.2)

                ifcopenshell.geom.utils.display_shape(e, clr=RED)

            elif handle_adaptor.GetType() == GeomAbs_Circle:
                v = list(Topo(e).vertices())
                start = (BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Z())
                end = (BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Z())

                circle = handle_adaptor.Circle()
                center = (circle.Location().X(), circle.Location().Z())
                radius = circle.Radius()

                vec_start = (start[0] - center[0], start[1] - center[1])
Exemplo n.º 30
0
def EdgeOnSurface(edge, section_plane, lim_coord1, lim_coord2, XYZ):

    section_face = BRepBuilderAPI_MakeFace(section_plane, lim_coord1[0],
                                           lim_coord1[1], lim_coord2[0],
                                           lim_coord2[1]).Face()
    curve_handle, first, last = BRep_Tool.CurveOnSurface(edge, section_face)

    plane = Geom_Plane(section_plane)
    edge_on_surface = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(),
                                              first, last).Edge()
    curve_adaptor = BRepAdaptor_Curve(edge_on_surface)

    if curve_adaptor.GetType() == GeomAbs_Line:

        v = list(Topo(edge_on_surface).vertices())
        v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(
            v[0]).Z()
        v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(
            v[-1]).Z()

        obj = Line3D(v1, v2)

    elif curve_adaptor.GetType() == GeomAbs_Circle:
        v = list(Topo(edge_on_surface).vertices())
        v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(
            v[0]).Z()
        v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(
            v[-1]).Z()

        start = [v1[i] for i in range(len(XYZ)) if XYZ[i]]
        end = [v2[i] for i in range(len(XYZ)) if XYZ[i]]

        circle = curve_adaptor.Circle()
        center = []
        for i in range(len(XYZ)):
            if XYZ[i] and i == 0:
                center.append(circle.Location().X())
            elif XYZ[i] and i == 1:
                center.append(circle.Location().Y())
            elif XYZ[i] and i == 2:
                center.append(circle.Location().Z())
            else:
                center.append(0.5 * (v1[i] + v2[i]))
        radius = circle.Radius()

        vec_start = (start[0] - center[0], start[1] - center[1])
        vec_end = (end[0] - center[0], end[1] - center[1])

        t1 = angle360(vec_start)
        t2 = angle360(vec_end)

        if not XYZ[0]:
            axis = circle.Axis().Direction().X()
        elif not XYZ[1]:
            axis = circle.Axis().Direction().Y()
        elif not XYZ[2]:
            axis = circle.Axis().Direction().Z()

        if axis < 0:
            t1, t2 = t2, t1

        obj = Arc3D(v1, v2, t1, t2, center, radius)

    elif curve_adaptor.GetType() == GeomAbs_BSplineCurve:

        bspline = curve_adaptor.BSpline().GetObject()
        degree = bspline.Degree()
        knots = [
            bspline.Knot(index) for index in range(1,
                                                   bspline.NbKnots() + 1)
        ]
        mults = [
            bspline.Multiplicity(index)
            for index in range(1,
                               bspline.NbKnots() + 1)
        ]
        poles = [(bspline.Pole(index).X(), bspline.Pole(index).Y(),
                  bspline.Pole(index).Z())
                 for index in range(1,
                                    bspline.NbPoles() + 1)]
        periodic = bspline.IsPeriodic()
        obj = BSpline3D(poles, mults, knots, degree, periodic)

    else:

        print(curve_adaptor.GetType())
        warnings.warn("Not recognized curve!")

    return obj