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();
def compute(self): tw = Topo(self.request.wire) eL = list(tw.edges_from_vertex(self.vertex)) if len(eL) > 2: raise Exception("Cannot trim wire at vertex with more than two edges") if len(eL) == 0: raise Exception("Vertex has no edges, cannot trim") allVertices = list(tw.vertices()) # only one edge accessible from this vertex if len(eL) == 1: edgeWrapper = Wrappers.Edge(eL[0]) pointObj = edgeWrapper.getPointAtVertex(self.vertex) self.solution = JointSolution(self.request, pointObj) self.solution.trimDistance = self.request.trackWidth # for a single edge, simply trim the path width return self.solution # else len(eL) == 2. this is the most common case. (edge1, edge2) = eL[:2] edgeWrapper1 = Wrappers.Edge(eL[0]) edgeWrapper2 = Wrappers.Edge(eL[1]) # compute solutions using both edges pointOnEdge1 = edgeWrapper1.getPointAtVertex(self.vertex) pointOnEdge2 = edgeWrapper2.getPointAtVertex(self.vertex) solution1 = JointSolution(self.request, pointOnEdge1) solution2 = JointSolution(self.request, pointOnEdge2) # choose the solution that is best. ideally, we want wide angles, # remember, these are direction vectors, so small angles means 'same direction' which is good, # while pi ( 180 ) angles are bad, becaues the paths switch back onto themselves. if solution1.isBetterThan(solution2): self.solution = solution1 else: self.solution = solution2 # compute the trim distance, which is based on the angles between the edges # edges with vectors pi apart overlap, and 0 degrees are aligned # TODO: this assumes all angles are between zero and 2pi angleAtVertex = pointOnEdge1.vector.Angle(pointOnEdge2.vector) angleDiff = abs(math.pi - angleAtVertex) trimWidth = self.request.trackWidth if angleDiff < 0.1: # print "Trimmed Wire: two edges are very close to each other!" # TODO: here, if one of the edges is a curve we can re-evaluate along the curve # to find a better location. If the cuves are lines, the two should be removed. # for now, though, we'll handle this in the shortening routine, which will # essentially never allow replacing an entire edge trimDistance = trimWidth * 5.0 elif angleDiff < (math.pi / 2): # print "Trimmed Wire based on sin rule" trimDistance = trimWidth / 2 * (1 + (1 / math.sin(angleAtVertex))) else: # print "No Trim was necessary" trimDistance = trimWidth / 2 solution1.trimDistance = trimDistance solution2.trimDistance = trimDistance if self.solution is None: raise Exception("No solution selected, this should not ever occur.") return self.solution
def compute(self): tw = Topo(self.request.wire) eL = list(tw.edges_from_vertex(self.vertex)) if len(eL) > 2: raise Exception( "Cannot trim wire at vertex with more than two edges") if len(eL) == 0: raise Exception("Vertex has no edges, cannot trim") allVertices = list(tw.vertices()) #only one edge accessible from this vertex if len(eL) == 1: edgeWrapper = Wrappers.Edge(eL[0]) pointObj = edgeWrapper.getPointAtVertex(self.vertex) self.solution = JointSolution(self.request, pointObj) self.solution.trimDistance = self.request.trackWidth #for a single edge, simply trim the path width return self.solution #else len(eL) == 2. this is the most common case. (edge1, edge2) = eL[:2] edgeWrapper1 = Wrappers.Edge(eL[0]) edgeWrapper2 = Wrappers.Edge(eL[1]) #compute solutions using both edges pointOnEdge1 = edgeWrapper1.getPointAtVertex(self.vertex) pointOnEdge2 = edgeWrapper2.getPointAtVertex(self.vertex) solution1 = JointSolution(self.request, pointOnEdge1) solution2 = JointSolution(self.request, pointOnEdge2) #choose the solution that is best. ideally, we want wide angles, #remember, these are direction vectors, so small angles means 'same direction' which is good, #while pi ( 180 ) angles are bad, becaues the paths switch back onto themselves. if solution1.isBetterThan(solution2): self.solution = solution1 else: self.solution = solution2 #compute the trim distance, which is based on the angles between the edges #edges with vectors pi apart overlap, and 0 degrees are aligned #TODO: this assumes all angles are between zero and 2pi angleAtVertex = pointOnEdge1.vector.Angle(pointOnEdge2.vector) angleDiff = abs(math.pi - angleAtVertex) trimWidth = self.request.trackWidth if angleDiff < 0.1: #print "Trimmed Wire: two edges are very close to each other!" #TODO: here, if one of the edges is a curve we can re-evaluate along the curve #to find a better location. If the cuves are lines, the two should be removed. #for now, though, we'll handle this in the shortening routine, which will #essentially never allow replacing an entire edge trimDistance = trimWidth * 5.0 elif angleDiff < (math.pi / 2): #print "Trimmed Wire based on sin rule" trimDistance = trimWidth / 2 * (1 + (1 / math.sin(angleAtVertex))) else: #print "No Trim was necessary" trimDistance = trimWidth / 2 solution1.trimDistance = trimDistance solution2.trimDistance = trimDistance if self.solution is None: raise Exception( "No solution selected, this should not ever occur.") return self.solution