def makeEdgeIndicator(edge): "makes an indicator showing which way the edge goes" ew = Wrappers.Edge(edge); fp = ew.firstParameter; lp = ew.lastParameter; if ew.reversed: p = fp + (( lp - fp ) * 1 / 5 ); else: p = fp + ((lp - fp) * 4 /5 ); midPnt = ew.curve.Value(p); return OCCUtil.make_vertex(midPnt);
def makeEdgeIndicator(edge): "makes an indicator showing which way the edge goes" ew = Wrappers.Edge(edge) fp = ew.firstParameter lp = ew.lastParameter if ew.reversed: p = fp + ((lp - fp) * 1 / 5) else: p = fp + ((lp - fp) * 4 / 5) midPnt = ew.curve.Value(p) return OCCUtil.make_vertex(midPnt)
def displayAllEdgesAndVertices(g): i = 0 for en in g.edges_iter(data=True): i += 1 displayEdgeFromGraph(en[2]) print "%d edges total" % i i = 0 for n in g.nodes_iter(): i += 1 p = gp.gp_Pnt(n[0], n[1], 0) display.DisplayShape(OCCUtil.make_vertex(p), update=False) print "%d nodes total" % i
def displayAllEdgesAndVertices(g): i=0; for en in g.edges_iter(data=True): i+=1; displayEdgeFromGraph(en[2]) print "%d edges total" % i i=0 for n in g.nodes_iter(): i+=1; p = gp.gp_Pnt(n[0],n[1],0); display.DisplayShape(OCCUtil.make_vertex(p),update=False); print "%d nodes total" % i
def build(self): topoWire = Topo(self.wire) #compute closest point on the wire brp = BRepExtrema.BRepExtrema_DistShapeShape() brp.LoadS1(OCCUtil.make_vertex(self.startPoint)) brp.LoadS2(self.wire) result = brp.Perform() p1 = brp.PointOnShape2(1) wb = OCCUtil.WireBuilder() closestParam = None if brp.SupportTypeShape2(1) == BRepExtrema.BRepExtrema_IsOnEdge: #closest point is a point along an edge interSectingEdge = OCCUtil.cast(brp.SupportOnShape2(1)) closestParam = brp.ParOnEdgeS2(1) else: #closest point is a point on a vertex, here we'll shorten one edge #in this case closest point is a vertex, so we dont have a param on an edge vertex = OCCUtil.cast(brp.SupportOnShape2(1)) edges = [] for e in topoWire.edges_from_vertex(vertex): edges.append(e) interSectingEdge = edges[0] #compute parameter along one curve #break the edge into two new edges. account for a split distance between them. ej = EdgeJoin(interSectingEdge, self.startPoint, self.trackWidth, closestParam) #add lead-in edges for e in ej.connectingEdges: wb.add(e) #now add all of the other edges in the wire except the original one that we split for e in topoWire.edges(): if not e.IsSame(interSectingEdge): wb.add(e) for e in ej.otherEdges: wb.add(e) return wb.wire()
def build(self): topoWire = Topo(self.wire); #compute closest point on the wire brp = BRepExtrema.BRepExtrema_DistShapeShape(); brp.LoadS1(OCCUtil.make_vertex(self.startPoint)); brp.LoadS2(self.wire); result = brp.Perform(); p1 = brp.PointOnShape2(1); wb = OCCUtil.WireBuilder(); closestParam = None; if brp.SupportTypeShape2(1) == BRepExtrema.BRepExtrema_IsOnEdge: #closest point is a point along an edge interSectingEdge = OCCUtil.cast(brp.SupportOnShape2(1)); closestParam = brp.ParOnEdgeS2(1); else: #closest point is a point on a vertex, here we'll shorten one edge #in this case closest point is a vertex, so we dont have a param on an edge vertex = OCCUtil.cast(brp.SupportOnShape2(1)); edges = []; for e in topoWire.edges_from_vertex(vertex): edges.append(e); interSectingEdge = edges[0]; #compute parameter along one curve #break the edge into two new edges. account for a split distance between them. ej = EdgeJoin(interSectingEdge,self.startPoint,self.trackWidth ,closestParam); #add lead-in edges for e in ej.connectingEdges: wb.add(e); #now add all of the other edges in the wire except the original one that we split for e in topoWire.edges(): if not e.IsSame(interSectingEdge): wb.add(e); for e in ej.otherEdges: wb.add(e); return wb.wire();
def makeExtrusionWire( shellWire, startPoint, trackWidth): topoWire = Topo(shellWire); #compute closest point on the wire brp = BRepExtrema.BRepExtrema_DistShapeShape(); brp.LoadS1(OCCUtil.make_vertex(startPoint)); brp.LoadS2(shellWire); result = brp.Perform(); p1 = brp.PointOnShape2(1); wb = WireBuilder(); #make an edge from start point to located point. #wb.add ( OCCUtil.edgeFromTwoPoints(startPoint, p1 ) ); dist = p1.Distance(p2) if brp.SupportTypeShape2(1) == BRepExtrema.BRepExtrema_IsOnEdge: #closest point is a point along an edge interSectingEdge = OCCUtil.cast(brp.SupportOnShape2(1)); p = brp.ParOnEdgeS2(1); #compute parameter along one curve #break the edge into two new edges. account for a split distance between them. (e1,e2)= OCCUtil.splitEdge(interSectingEdge,p); wb.add(e1); #add second one shortened, on the end near the vertex wb.add ( OCCUtil.shortenEdge(e2,p1,trackWidth)); #hack, must find parameter closest to this end #now add all of the other edges in the wire except the original one that we split for e in topoWire.edges(): if not e.IsSame(interSectingEdge): wb.add(e); else: #closest point is a point on a vertex, here we'll shorten one edge # vertex = OCCUtil.cast(brp.SupportOnShape2(1)); edges = []; for e in topoWire.edges_from_vertex(vertex): edges.append(e); #shorten one, leave other intact #try to handle case where vertex is at end of a wire ( ie a non-closed wire ) e1 = edges[0]; wb.add( edges[0]); e2 = None; if len(edges) > 1: e2 = edges[1]; e3 = OCCUtil.shortenEdge(e2,p1,trackWidth); #hack-- find edges closest to this end #display.DisplayColoredShape(e3,'BLUE') wb.add ( e3); for e in topoWire.edges(): if e.IsSame(e1): continue; if e2 and e.IsSame(e2): continue; wb.add ( e ); return wb.wire();
if e2 and e.IsSame(e2): continue; wb.add ( e ); return wb.wire(); if __name__=='__main__': from OCC.Display.SimpleGui import * display, start_display, add_menu, add_function_to_menu = init_display() heart = TestObjects.makeHeartWire(); #p1 = gp.gp_Pnt(0.0,-0.5,0.0); p1 = gp.gp_Pnt(2.1,1.5,0.0); v1 = OCCUtil.make_vertex ( gp.gp_Pnt(2.0,3.1,0.0)); #t = time.clock(); #for i in range(1000): # p2 = distToPoint(heart,v1 ); #print "dist time %0.3f" % ( time.clock() - t ); #about 1.6ms per call for a simple heart wire . not too shabby #v2 = OCCUtil.make_vertex ( p2 ); #display.DisplayShape([heart,v1,v2]); #test splitting a wire newWire= makeExtrusionWire(heart,p1,0.25); display.DisplayColoredShape(heart, 'WHITE') display.DisplayColoredShape(newWire, 'GREEN'); print "Total Edges %d" % Topo(newWire).number_of_edges()