def normalEdgesAlongEdge(edge, length , interval): "compute an edge having length at the specified parameter on the supplied curve:" edgeList = []; ew = Wrappers.Edge(edge); zDir = gp.gp().DZ(); zVec = gp.gp_Vec(zDir); curve = ew.curve; pStart = ew.firstParameter; pEnd = ew.lastParameter; for p in Wrappers.frange6(pStart,pEnd,interval): tangent = gp.gp_Vec(); tanpoint = gp.gp_Pnt(); curve.D1(p,tanpoint,tangent ); axis = gp.gp_Ax1(tanpoint, gp.gp_Dir(tangent.Crossed(zVec) ) ); line = Geom.Geom_Line(axis ); e = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(line.GetHandle(),0, length).Edge(); if e: edgeList.append(e); return edgeList;
def makeFillEdges2d(xMin, yMin, xMax, yMax, spacing): "make straight hatch lines." edges = [] for y in Wrappers.frange6(yMin, yMax, spacing): e = edgeFromTwoPoints((xMin, y), (xMax, y)) #TestDisplay.display.showShape(e); edges.append(e) return edges
def makeFillEdges2d(xMin, yMin, xMax, yMax, spacing): "make straight hatch lines." edges = [] for y in Wrappers.frange6(yMin, yMax, spacing): e = edgeFromTwoPoints((xMin, y), (xMax, y)) # TestDisplay.display.showShape(e); edges.append(e) return edges
def scanlinesFromBoundingBox(boundingBox,interval): (xMin,yMin,zMin,xMax,yMax,zMax) = boundingBox; print boundingBox; edges = []; for y in Wrappers.frange6(yMin,yMax,interval): e = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(xMin,y,0),gp.gp_Pnt(xMax,y,0)); #TestDisplay.display.showShape(e); edges.append((y,Wrappers.wireFromEdges([e]))); return edges;
def scanlinesFromBoundingBox(boundingBox, interval): (xMin, yMin, zMin, xMax, yMax, zMax) = boundingBox print boundingBox edges = [] for y in Wrappers.frange6(yMin, yMax, interval): e = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(xMin, y, 0), gp.gp_Pnt(xMax, y, 0)) #TestDisplay.display.showShape(e); edges.append((y, Wrappers.wireFromEdges([e]))) return edges
def makeFillCurves2d(xMin, yMin, xMax, yMax, spacing): """ makes a set of lines that are curves not edges probably the minimal possible construction """ lines = [] for y in Wrappers.frange6(yMin, yMax, spacing): l = GCE2d.GCE2d_MakeSegment(tP(xMin, y), tP(xMax, y)).Value() lines.append(l) return lines
def _makeHatchLines(self): "make straight hatch lines." xMin = self.bounds[0] - (self.HATCH_PADDING) yMin = self.bounds[1] - (self.HATCH_PADDING) xMax = self.bounds[2] + (self.HATCH_PADDING) yMax = self.bounds[3] + (self.HATCH_PADDING) wires = [] for y in Wrappers.frange6(yMin, yMax, 0.02): e = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(xMin, y, self.zLevel), gp.gp_Pnt(xMax, y, self.zLevel)) #display.DisplayShape(e); wires.append(Wrappers.wireFromEdges([e])) return wires
def makeHexForBoundingBox(self, bottomLeftCorner, topRightCorner): """ make a hex array that covers the specified bounding box bottomLeftCorner is a tuple (x,y,z) representing the bottom left topRightCorner is a tuple (x,y,z) representing the top right. The algo guarantees that full hexes cover the specified bounding box Complete re-implementation from the original transformation based version for speed """ (xMin, yMin) = bottomLeftCorner (xMax, yMax) = topRightCorner dX = abs(bottomLeftCorner[0] - topRightCorner[0]) dY = abs(bottomLeftCorner[1] - topRightCorner[1]) #spacing of the pattern horizontally and vertically yIncrement = self.cartesianSpacing()[1] xIncrement = self.cartesianSpacing()[0] * 2.0 rows = [] for y in Wrappers.frange6(yMin, yMax, yIncrement): curves = [] #make the bottom row for x in Wrappers.frange6(xMin, xMax, xIncrement): edges = self.makePeriodic((x, y), -1) curves.extend(edges) rows.append(curves) curves = [] #make the upper row for x in Wrappers.frange6(xMin, xMax, xIncrement): edges = self.makePeriodic((x, y), 1) curves.extend(edges) rows.append(curves) #list of list of lines return rows
def computePixelGrid(face, resolution=0.1): """ makes a pixel grid of a face at the requested resolution." A dictionary is used to store the values. """ box = Bnd.Bnd_Box(); b = BRepBndLib.BRepBndLib(); b.Add(face,box); TOLERANCE = 5; bounds = box.Get(); xMin = bounds[0]; xMax = bounds[3]; xDim = abs(xMax - xMin); yMin = bounds[1]; yMax = bounds[4]; yDim = abs(yMax - yMin); zMin = bounds[2]; pixelTable = {}; for y in Wrappers.frange6(yMin,yMax,resolution): #create a horizontal scan line edge = Wrappers.edgeFromTwoPoints( gp.gp_Pnt(xMin - TOLERANCE,y,zMin), gp.gp_Pnt(xMax + TOLERANCE,y,zMin) ); #get list of wires from the face #TODO:// this should be encapsulated by a face abstraction wires = [] ow = brt.OuterWire(face); wires.append(ow); for w in Topo(face).wires(): if not w.IsSame(ow): wires.append(w); #compute intersection points with each wire #this is a hack because i know how to make edges from lines #but really, it would be better to do 2d here and use #Geom2dAPI_InterCurveCurve xIntersections = []; for w in wires: #display.DisplayShape(w); brp = BRepExtrema.BRepExtrema_DistShapeShape(); #display.DisplayShape(edge); brp.LoadS1(w); brp.LoadS2(edge); if brp.Perform() and brp.Value() < 0.01: for k in range(1,brp.NbSolution()+1): if brp.SupportTypeShape1(k) == BRepExtrema.BRepExtrema_IsOnEdge: xIntersections.append(brp.PointOnShape1(k).X() ); if len(xIntersections) == 0: print "No intersection found."; continue; #else: #print "there are %d intersections " % len(xIntersections); #sort intersection points by x value xIntersections.sort(); #fill pixel table with values on surface based on scanlines #TODO: for now ignore horizontals and edge vertices, this is just a test #better to use a generator here too #also need to implement edge table of scanline fill if (len(xIntersections) % 2 == 0) : i = 0; inside = False; cx = xMin; #print xIntersections; while i < len(xIntersections): cint = xIntersections[i]; if inside: while cx < cint: key = ( cx, y ); pixelTable[key] = 1; #print cx; cx += resolution; else: while cx<cint: cx += resolution; #print cx; continue; i += 1; inside = not inside; else: print "Odd number of intersections encountred." #displayPixelGrid(pixelTable); return pixelTable;
def computePixelGrid(face, resolution=0.1): """ makes a pixel grid of a face at the requested resolution." A dictionary is used to store the values. """ box = Bnd.Bnd_Box() b = BRepBndLib.BRepBndLib() b.Add(face, box) TOLERANCE = 5 bounds = box.Get() xMin = bounds[0] xMax = bounds[3] xDim = abs(xMax - xMin) yMin = bounds[1] yMax = bounds[4] yDim = abs(yMax - yMin) zMin = bounds[2] pixelTable = {} for y in Wrappers.frange6(yMin, yMax, resolution): #create a horizontal scan line edge = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(xMin - TOLERANCE, y, zMin), gp.gp_Pnt(xMax + TOLERANCE, y, zMin)) #get list of wires from the face #TODO:// this should be encapsulated by a face abstraction wires = [] ow = brt.OuterWire(face) wires.append(ow) for w in Topo(face).wires(): if not w.IsSame(ow): wires.append(w) #compute intersection points with each wire #this is a hack because i know how to make edges from lines #but really, it would be better to do 2d here and use #Geom2dAPI_InterCurveCurve xIntersections = [] for w in wires: #display.DisplayShape(w); brp = BRepExtrema.BRepExtrema_DistShapeShape() #display.DisplayShape(edge); brp.LoadS1(w) brp.LoadS2(edge) if brp.Perform() and brp.Value() < 0.01: for k in range(1, brp.NbSolution() + 1): if brp.SupportTypeShape1( k) == BRepExtrema.BRepExtrema_IsOnEdge: xIntersections.append(brp.PointOnShape1(k).X()) if len(xIntersections) == 0: print "No intersection found." continue #else: #print "there are %d intersections " % len(xIntersections); #sort intersection points by x value xIntersections.sort() #fill pixel table with values on surface based on scanlines #TODO: for now ignore horizontals and edge vertices, this is just a test #better to use a generator here too #also need to implement edge table of scanline fill if (len(xIntersections) % 2 == 0): i = 0 inside = False cx = xMin #print xIntersections; while i < len(xIntersections): cint = xIntersections[i] if inside: while cx < cint: key = (cx, y) pixelTable[key] = 1 #print cx; cx += resolution else: while cx < cint: cx += resolution #print cx; continue i += 1 inside = not inside else: print "Odd number of intersections encountred." #displayPixelGrid(pixelTable); return pixelTable