コード例 #1
0
ファイル: Iteration.py プロジェクト: zebrajack/pythonocc
class EdgePairsFromWire(object):
    '''
    helper class to loop through a wire and return ordered pairs of edges
    '''
    def __init__(self, wire):
        self.wire = wire
        self.edge_pairs = []
        self.prev_edge = None
        self.we = WireExplorer(self.wire).ordered_edges()
        self.number_of_edges = self.we.__length_hint__()
        self.index = 0

    def next(self):
        if self.index == 0:
            # first edge, need to set self.previous_edge
            self.previous_edge = self.we.next()
            self.current_edge = self.we.next()
            self.first_edge = self.previous_edge  # for the last iteration
            self.index += 1
            return [self.previous_edge, self.current_edge]

        elif self.index == self.number_of_edges - 1:
            # no next edge
            self.index += 1
            return [self.current_edge, self.first_edge]

        else:
            self.previous_edge = self.current_edge
            self.current_edge = self.we.next()
            self.index += 1
            return [self.previous_edge, self.current_edge]

    def __iter__(self):
        return self
コード例 #2
0
ファイル: Iteration.py プロジェクト: ashoka2015/pythonocc
class EdgePairsFromWire(object):
    '''
    helper class to loop through a wire and return ordered pairs of edges
    '''
    def __init__(self, wire):
        self.wire = wire
        self.edge_pairs = []
        self.prev_edge = None
        self.we = WireExplorer(self.wire).ordered_edges()
        self.number_of_edges = self.we.__length_hint__()
        self.index = 0

    def next(self):
        if self.index == 0:
            # first edge, need to set self.previous_edge
            self.previous_edge = self.we.next()
            self.current_edge = self.we.next()
            self.first_edge = self.previous_edge   # for the last iteration
            self.index += 1
            return [self.previous_edge, self.current_edge]
        elif self.index == self.number_of_edges-1:
            # no next edge
            self.index += 1
            return [self.current_edge, self.first_edge]
        else:
            self.previous_edge = self.current_edge
            self.current_edge = self.we.next()
            self.index += 1
            return [self.previous_edge, self.current_edge]

    def __iter__(self):
        return self
コード例 #3
0
ファイル: Iteration.py プロジェクト: zebrajack/pythonocc
 def __init__(self, wire):
     self.wire = wire
     self.edge_pairs = []
     self.prev_edge = None
     self.we = WireExplorer(self.wire).ordered_edges()
     self.number_of_edges = self.we.__length_hint__()
     self.index = 0
コード例 #4
0
ファイル: Iteration.py プロジェクト: gideonmay/pythonocc-core
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
コード例 #5
0
ファイル: Iteration.py プロジェクト: zebrajack/pythonocc
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
コード例 #6
0
 def test_wires_out_of_scope(self):
     face = self.topo.wires().next()
     _edges = []
     for edg in WireExplorer(face).ordered_edges():
         _edges.append(edg)
     for edg in _edges:
         self.assert_(edg.IsNull() == False)
コード例 #7
0
def build_plate(polygon, points):
    ''' 
    build a surface from a constraining polygon(s) and point(s)
    @param polygon:     list of polygons (TopoDS_Shape)
    @param points:      list of points (gp_Pnt) 
    '''
    # plate surface
    bpSrf = GeomPlate_BuildPlateSurface(3, 15, 2)

    # add curve constraints
    for poly in polygon:
        for edg in WireExplorer(poly.Wire()).ordered_edges():
            c = BRepAdaptor_HCurve()
            c.ChangeCurve().Initialize(edg)
            constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
            bpSrf.Add(constraint.GetHandle())

    # add point constraint
    for pt in points:
        bpSrf.Add(GeomPlate_PointConstraint(pt, 0).GetHandle())
        bpSrf.Perform()

    maxSeg, maxDeg, critOrder = 9, 8, 0
    tol = 1e-4
    dmax = max([tol, 10 * bpSrf.G0Error()])

    srf = bpSrf.Surface()
    plate = GeomPlate_MakeApprox(srf, tol, maxSeg, maxDeg, dmax, critOrder)

    uMin, uMax, vMin, vMax = srf.GetObject().Bounds()

    face = BRepBuilderAPI_MakeFace(plate.Surface(), uMin, uMax, vMin, vMax)
    face.Build()
    return face
コード例 #8
0
ファイル: Iteration.py プロジェクト: ashoka2015/pythonocc
 def __init__(self, wire):
     self.wire = wire
     self.edge_pairs = []
     self.prev_edge = None
     self.we = WireExplorer(self.wire).ordered_edges()
     self.number_of_edges = self.we.__length_hint__()
     self.index = 0
コード例 #9
0
ファイル: Iteration.py プロジェクト: ashoka2015/pythonocc
    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
コード例 #10
0
ファイル: Iteration.py プロジェクト: zebrajack/pythonocc
    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
コード例 #11
0
ファイル: face.py プロジェクト: zebrajack/pythonocc
 def Edges(self):
     return [
         Edge(i)
         for i in WireExplorer(self.topo.wires().next()).ordered_edges()
     ]