def buildGraph(self): g = self.graph; #add fill edge nodes first for e in self.fillEdges: g.add_edge(e[0], e[1], {"type":'FILL', "edgeList":e[2]}); #add boundary nodes. for (edge, pointList ) in self.boundaryEdges.iteritems(): #sort the points by parameter sortedPoints = sorted(pointList,key = lambda p: p.param ); for (poe1,poe2) in Util.pairwise(sortedPoints): #dont add if there is already an edge if not g.has_edge(poe1.node,poe2.node): #here we need to trim each edge to limit it to the desired parameters g.add_edge(poe1.node,poe2.node,{"type":"BOUND", "edge": OCCUtil.trimmedEdge(edge,poe1.param,poe2.param)});
def splitWire(wire,ipoints): """ ipoints is a list of intersection points. returns a list of wires inside the intersection point this method must also work for a 'wire' consisting of a single edge. more than one intersection point can be on each edge, but all of the ipoints are expected to be on edges in the provided wire. BASELINE PERFORMANCE: 11 ms per call for splitwiretest returns a list of lists. each element in the top list is a chain of connected edges. each element in that list is an edge ( or part of an edge ) so, for example, suppose you compute a wire that has 100 edges, and there are 4 intersection points. in this case, there will be two elements returned, and each element would contain a list of edges between the two segments. ---E1---+---E2---+-X-E3---+---E4--X--+---E5--- will return [ [E1,E2], [ E3,E4 ] ] """ topexp = TopExp.TopExp_Explorer(); topexp.Init(wire,TopAbs.TopAbs_EDGE); #sort intersection points by ascending X location ix = sorted(ipoints,key = lambda p: p.point.X() ); edgeList = []; assert (len(ipoints) % 2) == 0; for i in range(0,len(ipoints),2): #process intersection points in pairs #TODO: this could be done more cleanly with a pairwise iterator currentIntersection = ix[i]; nextIntersection = ix[i+1]; #if they are on the same edge, simply add a trimmed edge. #in this case, if currentIntersection.hash == nextIntersection.hash: edgeList.append ( [ OCCUtil.trimmedEdge(currentIntersection.edge, currentIntersection.param, nextIntersection.param ) ] ); else: #intersections are not on the same edge. #add the fraction of the first edge (bp,ep) = brepTool.Range(currentIntersection.edge); edges = []; #print "adding piece of start edge." edges.append( OCCUtil.trimmedEdge(currentIntersection.edge,currentIntersection.param, ep)); #pick up whole edges between the first intersection and the next one #loop till current edge is same as current intersection while topexp.Current().__hash__() != currentIntersection.hash: topexp.Next(); #advance to next edge topexp.Next(); #add edges till current edge is same as next intersection #most of the performance suckage is happening here, with gc associated with these #edge objects. If that gets fixed, we'll get a huge speed boost. about 33% of total time is saved. while topexp.Current().__hash__() != nextIntersection.hash: edge = OCCUtil.cast(topexp.Current() ); edges.append(edge); #print "adding middle edge" topexp.Next(); #add the last edge (bp,ep) = brepTool.Range(nextIntersection.edge); edges.append( OCCUtil.trimmedEdge(nextIntersection.edge,bp,nextIntersection.param)); #print "adding last piece of edge" edgeList.append(edges); return edgeList;