def testSplitWire2(): "intersections on different edges. one edge completely inside" e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(2,0,0)); e2 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(2,0,0),gp.gp_Pnt(5,0,0)); e3 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(5,0,0),gp.gp_Pnt(6,0,0)); #trick here. after building a wire, the edges change identity. #evidently, BRepBuilder_MakeWire makes copies of the underliying edges. w = Wrappers.wireFromEdges([e1,e2,e3]); ee = Wrappers.Wire(w).edgesAsList(); print "Original Edges: %d %d %d " % ( hashE(ee[0]),hashE(ee[1]),hashE(ee[2])); p1 = PointOnAnEdge(ee[0],1.0,gp.gp_Pnt(1.0,0,0)); p2 = PointOnAnEdge(ee[2],0.5,gp.gp_Pnt(5.0,0,0)); ee = splitWire(w,[p2,p1]); assert len(ee) == 3; length = 0; for e in ee: ew = Wrappers.Edge(e); length += ew.distanceBetweenEnds(); TestDisplay.display.showShape(e); print "length=%0.3f" % length; assert length == 4.5;
def testSplitWire2(): "intersections on different edges. one edge completely inside" e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(2,0,0)); e2 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(2,0,0),gp.gp_Pnt(5,0,0)); e3 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(5,0,0),gp.gp_Pnt(6,0,0)); #trick here. after building a wire, the edges change identity. #evidently, BRepBuilder_MakeWire makes copies of the underliying edges. w = Wrappers.wireFromEdges([e1,e2,e3]); ee = Wrappers.Wire(w).edgesAsList(); #print "Original Edges: %d %d %d " % ( ee[0].__hash__(),ee[1].__hash__(),ee[2].__hash__()); p1 = PointOnAnEdge(ee[0],1.0,gp.gp_Pnt(1.0,0,0)); p2 = PointOnAnEdge(ee[2],0.5,gp.gp_Pnt(5.0,0,0)); ee = splitWire(w,[p2,p1]); assert len(ee) == 1; length = 0; for e in ee[0]: ew = Wrappers.Edge(e); length += ew.distanceBetweenEnds(); TestDisplay.display.showShape(e); #print "length=%0.3f" % length; assert length == 4.5;
def makePieWire(): e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(4.0, 0, 0)) e2 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(4.0, 0, 0), gp.gp_Pnt(2.0, 0.1, 0)) e3 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(2.0, 0.1, 0), gp.gp_Pnt(3.0, 1.0, 0)) e4 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(3.0, 1.0, 0), gp.gp_Pnt(00, 0, 0)) return Wrappers.wireFromEdges([e1, e2, e3, e4])
def makeHeartWire(): "make a heart wire" e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0), gp.gp_Pnt(4.0,4.0,0)); circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2,4,0),gp.gp().DZ()),2); e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4,4,0),gp.gp_Pnt(0,4,0)).Edge(); circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2,4,0),gp.gp().DZ()),2); e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0,4,0),gp.gp_Pnt(-4,4,0)).Edge(); e4 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(-4,4,0), gp.gp_Pnt(0,0,0)); return Wrappers.wireFromEdges([e1,e2,e3,e4]);
def squareWire(centerPt, w): "makes a square wire with center at the desired point" w2 = w / 2.0 p1 = gp.gp_Pnt(centerPt.X() - w2, centerPt.Y() - w2, centerPt.Z()) p2 = gp.gp_Pnt(centerPt.X() - w2, centerPt.Y() + w2, centerPt.Z()) p3 = gp.gp_Pnt(centerPt.X() + w2, centerPt.Y() + w2, centerPt.Z()) p4 = gp.gp_Pnt(centerPt.X() + w2, centerPt.Y() - w2, centerPt.Z()) e1 = Wrappers.edgeFromTwoPoints(p1, p4) e2 = Wrappers.edgeFromTwoPoints(p4, p3) e3 = Wrappers.edgeFromTwoPoints(p3, p2) e4 = Wrappers.edgeFromTwoPoints(p2, p1) return Wrappers.wireFromEdges([e1, e2, e3, e4])
def squareWire(centerPt,w ): "makes a square wire with center at the desired point" w2 = w/2.0; p1 = gp.gp_Pnt(centerPt.X() - w2,centerPt.Y() -w2 , centerPt.Z() ) p2 = gp.gp_Pnt(centerPt.X() - w2,centerPt.Y() +w2, centerPt.Z() ) p3 = gp.gp_Pnt(centerPt.X() + w2,centerPt.Y() +w2, centerPt.Z() ) p4 = gp.gp_Pnt(centerPt.X() + w2,centerPt.Y() -w2, centerPt.Z() ) e1 = Wrappers.edgeFromTwoPoints(p1,p4); e2 = Wrappers.edgeFromTwoPoints(p4,p3); e3 = Wrappers.edgeFromTwoPoints(p3,p2); e4 = Wrappers.edgeFromTwoPoints(p2,p1); return Wrappers.wireFromEdges([e1,e2,e3,e4] );
def makeHeartWire(): "make a heart wire" e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(4.0, 4.0, 0)) circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 4, 0), gp.gp().DZ()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4, 4, 0), gp.gp_Pnt(0, 4, 0)).Edge() circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2, 4, 0), gp.gp().DZ()), 2) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0, 4, 0), gp.gp_Pnt(-4, 4, 0)).Edge() e4 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(-4, 4, 0), gp.gp_Pnt(0, 0, 0)) return Wrappers.wireFromEdges([e1, e2, e3, e4])
def testSplitWire1(): """ Test split wire function. there are two main cases: wires with intersection on different edges, and a wire with a single edge split in many places """ #case 1: a single edge with lots of intersections along its length e = Wrappers.edgeFromTwoPoints( gp.gp_Pnt(0,0,0),gp.gp_Pnt(5,0,0)); w = Wrappers.wireFromEdges([e]); #out of order on purpose p1 = PointOnAnEdge(e,1.0,gp.gp_Pnt(1.0,0,0)); p3 = PointOnAnEdge(e,3.0,gp.gp_Pnt(3.0,0,0)); p2 = PointOnAnEdge(e,2.0,gp.gp_Pnt(2.0,0,0)); p4 = PointOnAnEdge(e,4.0,gp.gp_Pnt(4.0,0,0)); ee = splitWire(w,[p1,p3,p2,p4] ); assert len(ee) == 2; length = 0; for e in ee: ew = Wrappers.Edge(e[0]); length += ew.distanceBetweenEnds(); TestDisplay.display.showShape(e); assert length == 2.0;
def testSplitWire1(): """ Test split wire function. there are two main cases: wires with intersection on different edges, and a wire with a single edge split in many places """ #case 1: a single edge with lots of intersections along its length e = Wrappers.edgeFromTwoPoints( gp.gp_Pnt(0,0,0),gp.gp_Pnt(5,0,0)); w = Wrappers.wireFromEdges([e]); #out of order on purpose p1 = PointOnAnEdge(e,1.0,gp.gp_Pnt(1.0,0,0)); p3 = PointOnAnEdge(e,3.0,gp.gp_Pnt(3.0,0,0)); p2 = PointOnAnEdge(e,2.0,gp.gp_Pnt(2.0,0,0)); p4 = PointOnAnEdge(e,4.0,gp.gp_Pnt(4.0,0,0)); ee = splitWire(w,[p1,p3,p2,p4] ); assert len(ee) == 2; length = 0; for e in ee: ew = Wrappers.Edge(e); length += ew.distanceBetweenEnds(); TestDisplay.display.showShape(e); assert length == 2.0;
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 displayGraph(graph): "display an networkx graph" "this is just a hack-- the tuples are in integer coordinates, and this will be terribly slow" for e in graph.edges_iter(): try: TestDisplay.display.showShape(Wrappers.edgeFromTwoPoints(pnt(e[0]),pnt(e[1]))); except: pass;
def displayGraph(graph): "display an networkx graph" "this is just a hack-- the tuples are in integer coordinates, and this will be terribly slow" for e in graph.edges_iter(): try: TestDisplay.display.showShape( Wrappers.edgeFromTwoPoints(pnt(e[0]), pnt(e[1]))) except: pass
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 makePeriodic(self, center, positive=1.0): """ center is the center of the first hex, as an (x,y,z) tuple. positive is 1 for the upper portion, -1 for the lower portion makes the upper part of a periodic hex pattern. Note that the upper and lower flats are adjusted for line width, so that they can be stacked and allow double-drawing of the horizontal flats. this offset is controlled by the linewidth parameter. the points are numbered below (2) (3) /-----\ ____/ + \_____ (0) (1) (4) (5) """ cX = center[0] cY = center[1] cZ = center[2] (XA, YA) = self.lineWidthAdjust() baselineY = (cY + YA) * positive topY = (cY + (self.width / 2.0 - YA)) * positive p0 = gp.gp_Pnt(cX - self.cartesianSpacing()[0], baselineY, cZ) p1 = gp.gp_Pnt(cX - self.centerToCorner() + XA, baselineY, cZ) p2 = gp.gp_Pnt(cX - self.halfAflat() - XA, topY, cZ) p3 = gp.gp_Pnt(cX + self.halfAflat() + XA, topY, cZ) p4 = gp.gp_Pnt(cX + self.centerToCorner() - XA, baselineY, cZ) p5 = gp.gp_Pnt(cX + self.cartesianSpacing()[0], baselineY, cZ) #make the edges and the wires edges = [] edges.append(Wrappers.edgeFromTwoPoints(p0, p1)) edges.append(Wrappers.edgeFromTwoPoints(p1, p2)) edges.append(Wrappers.edgeFromTwoPoints(p2, p3)) edges.append(Wrappers.edgeFromTwoPoints(p3, p4)) edges.append(Wrappers.edgeFromTwoPoints(p4, p5)) wire = Wrappers.wireFromEdges(edges) return wire
def makePeriodic(self,center,positive=1.0): """ center is the center of the first hex, as an (x,y,z) tuple. positive is 1 for the upper portion, -1 for the lower portion makes the upper part of a periodic hex pattern. Note that the upper and lower flats are adjusted for line width, so that they can be stacked and allow double-drawing of the horizontal flats. this offset is controlled by the linewidth parameter. the points are numbered below (2) (3) /-----\ ____/ + \_____ (0) (1) (4) (5) """ cX = center[0]; cY = center[1]; cZ = center[2]; (XA,YA) = self.lineWidthAdjust(); baselineY = (cY + YA ) * positive; topY = (cY + ( self.width/2.0 - YA )) * positive ; p0 = gp.gp_Pnt(cX - self.cartesianSpacing()[0], baselineY,cZ); p1 = gp.gp_Pnt( cX - self.centerToCorner() + XA, baselineY ,cZ ); p2 = gp.gp_Pnt( cX - self.halfAflat() - XA, topY , cZ ); p3 = gp.gp_Pnt( cX + self.halfAflat() + XA , topY, cZ ); p4 = gp.gp_Pnt( cX + self.centerToCorner() - XA , baselineY , cZ ); p5 = gp.gp_Pnt( cX + self.cartesianSpacing()[0], baselineY , cZ ); #make the edges and the wires edges = []; edges.append( Wrappers.edgeFromTwoPoints(p0,p1) ); edges.append( Wrappers.edgeFromTwoPoints(p1,p2) ); edges.append( Wrappers.edgeFromTwoPoints(p2,p3) ); edges.append( Wrappers.edgeFromTwoPoints(p3,p4) ); edges.append( Wrappers.edgeFromTwoPoints(p4,p5) ); wire = Wrappers.wireFromEdges(edges); return wire;
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 splitPerfTest(): "make a long wire of lots of edges" """ performance of the wire split routine is surprisingly bad! """ WIDTH=0.1 edges = []; for i in range(1,50): e = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(i*WIDTH,0,0),gp.gp_Pnt((i+1)*WIDTH,0,0)) TestDisplay.display.showShape(e); edges.append(e); #trick here. after building a wire, the edges change identity. #evidently, BRepBuilder_MakeWire makes copies of the underliying edges. w = Wrappers.wireFromEdges(edges); ee = Wrappers.Wire(w).edgesAsList(); #compute two intersections e1 = Wrappers.Edge(ee[5]); e2 = Wrappers.Edge(ee[30]); e1p = (e1.lastParameter - e1.firstParameter )/ 2; e2p = (e2.lastParameter - e2.firstParameter )/ 2; p1 = PointOnAnEdge(e1.edge,e1p ,e1.pointAtParameter(e1p)); p2 = PointOnAnEdge(e2.edge,e2p ,e2.pointAtParameter(e2p)); #cProfile.runctx('for i in range(1,100): ee=splitWire(w,[p2,p1])', globals(), locals(), filename="slicer.prof") #p = pstats.Stats('slicer.prof') #p.sort_stats('time') #p.print_stats(.98); t = Wrappers.Timer(); for i in range(1,100): ee = splitWire(w,[p2,p1]); print "Elapsed for 100 splits:",t.finishedString();
def makePieWire(): e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0), gp.gp_Pnt(4.0,0,0)); e2 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(4.0,0,0), gp.gp_Pnt(2.0,0.1,0)); e3 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(2.0,0.1,0), gp.gp_Pnt(3.0,1.0,0)); e4 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(3.0,1.0,0), gp.gp_Pnt(00,0,0)); return Wrappers.wireFromEdges([e1,e2,e3,e4]);
if MW.IsDone(): WhiteWire = MW.Wire() return WhiteWire; if __name__=='__main__': ###Logging Configuration logging.basicConfig(level=logging.WARN, format='%(asctime)s [%(funcName)s] %(levelname)s %(message)s', stream=sys.stdout) "PathExport: A Module for Navigating Wires, Edges, and Shapes" print "Running Test Cases..." print "Connected Edges" edge1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(1,1,0)); edge2 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(1,1,0),gp.gp_Pnt(2,2,0)); edge3 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(2,2,0),gp.gp_Pnt(3,2.2,0)); #the correct answer is: # MoveTo 0,0 # DrawTo 2,2 # DrawTo 3,2.2 assert testMoves([edge1,edge2,edge3]) == 3,"There should be Thee Moves" print "[OK]" print "Disconnected Edges" #the correct answer is: # MoveTo 0,0 # Lineto 1,1 # MoveTo 2,2 # LineTo 3,2.2
import Wrappers import timeit from OCC import gp e = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(1,1,1)); e2 t = Wrappers.Timer(); #conclusion of this test: #__hash__ is slightly faster. #__hash__ is much more readable, and works with built-in python N = 1000000; for i in range(1,N): e.__hash__(); print t.finishedString(); t = Wrappers.Timer(); for i in range(1,N): e.HashCode(1000000000); print t.finishedString();
WhiteWire = MW.Wire() return WhiteWire if __name__ == '__main__': ###Logging Configuration logging.basicConfig( level=logging.WARN, format='%(asctime)s [%(funcName)s] %(levelname)s %(message)s', stream=sys.stdout) "PathExport: A Module for Navigating Wires, Edges, and Shapes" print "Running Test Cases..." print "Connected Edges" edge1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(1, 1, 0)) edge2 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(1, 1, 0), gp.gp_Pnt(2, 2, 0)) edge3 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(2, 2, 0), gp.gp_Pnt(3, 2.2, 0)) #the correct answer is: # MoveTo 0,0 # DrawTo 2,2 # DrawTo 3,2.2 assert testMoves([edge1, edge2, edge3]) == 3, "There should be Thee Moves" print "[OK]" print "Disconnected Edges" #the correct answer is: # MoveTo 0,0 # Lineto 1,1 # MoveTo 2,2
assert len(ee) == 1; print "Elapsed for 1000splits:",t.finishedString(); #TestDisplay.display.showShape(ee); def runProfiled(cmd,level=1.0): "run a command profiled and output results" cProfile.runctx(cmd, globals(), locals(), filename="slicer.prof") p = pstats.Stats('slicer.prof') p.sort_stats('cum') p.print_stats(level); if __name__=='__main__': print "Basic Wrappers and Utilities Module" e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(2,0,0)); """ t = Wrappers.Timer(); for i in range(1,20000): ew = Wrappers.Edge(e1); print "Create 10000 edgewrappers= %0.3f" % t.elapsed(); print ew.firstParameter, ew.lastParameter; t = Wrappers.Timer(); for i in range(1,20000): (s,e) = brepTool.Range(e1); print "Get parameters 10000 times= %0.3f" % t.elapsed(); print s,e """
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;
ee = splitWire(w,[p2,p1]); print "Elapsed for 100splits:",t.finishedString(); #TestDisplay.display.showShape(ee); def runProfiled(cmd,level=1.0): "run a command profiled and output results" cProfile.runctx(cmd, globals(), locals(), filename="slicer.prof") p = pstats.Stats('slicer.prof') p.sort_stats('cum') p.print_stats(level); if __name__=='__main__': print "Basic Wrappers and Utilities Module" e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(2,0,0)); """ t = Wrappers.Timer(); for i in range(1,20000): ew = Wrappers.Edge(e1); print "Create 10000 edgewrappers= %0.3f" % t.elapsed(); print ew.firstParameter, ew.lastParameter; t = Wrappers.Timer(); for i in range(1,20000): (s,e) = brepTool.Range(e1); print "Get parameters 10000 times= %0.3f" % t.elapsed(); print s,e """
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