예제 #1
0
def trimEdges(edgeList, pixmap):
	"accepts a list of tuples ( each represents an edge)"
	"returns a networkx network of points, based on edges in the pixmap"
	"the network is in pixel coordinates ( integers )"
	
	g = nx.Graph();
	errors = 0;
	for e in edgeList:
		#print "Trimming Edge",e
		try:
			"walk each pixel, trimming it to segments inside the surface"
			start = pixmap.index(e[0]);
			end = pixmap.index(e[1]);
			#print e,start,end
			result_edges = bres.piecewise_bresenham_line(pixmap.p,start,end );
			for re in result_edges:
				"each of these are on the map"
				g.add_edge(re[0],re[1] );
		except:
			errors += 1;
			#print "error trimming."
			#raise;
	
	print "Errors Trimming %d edges" % errors;
	return g;
예제 #2
0
def trimEdges(edgeList, pixmap):
    "accepts a list of tuples ( each represents an edge)"
    "returns a networkx network of points, based on edges in the pixmap"
    "the network is in pixel coordinates ( integers )"

    g = nx.Graph()
    errors = 0
    for e in edgeList:
        #print "Trimming Edge",e
        try:
            "walk each pixel, trimming it to segments inside the surface"
            start = pixmap.index(e[0])
            end = pixmap.index(e[1])
            #print e,start,end
            result_edges = bres.piecewise_bresenham_line(pixmap.p, start, end)
            for re in result_edges:
                "each of these are on the map"
                g.add_edge(re[0], re[1])
        except:
            errors += 1
            #print "error trimming."
            #raise;

    print "Errors Trimming %d edges" % errors
    return g
예제 #3
0
def testWirePixmap(face):
	"""
		tests drawing a wire while adjusting sharp borders
	"""
	PIXEL = 0.01 ;
	DEFLECTION = PIXEL / 4.0;

	#get bounding box
	(xMin,yMin,zMin,xMax,yMax,zMax) = boundingBox([face]);
	g = nx.Graph();
	#adjust boundaries a bit
	BUFFER=PIXEL*5;
	#make pixmap
	pixmap = pixmaptest.pixmap((xMin-BUFFER,yMin-BUFFER),(xMax+BUFFER,yMax+BUFFER),PIXEL);

	
	ow = brt.OuterWire(face);
	boundary = tuplesFromWire(ow,DEFLECTION);
	
	for et in Wrappers.pairwise(boundary):
		p1 = et[0];
		p2 = et[1];
		g.add_edge(p1,p2);

		i1 = pixmap.index(p1);
		i2 = pixmap.index(p2);
		#print i1,i2,p1,p2
		lines = bres.piecewise_bresenham_line(pixmap.p,i1,i2);
		
		#add to the graph. this is tricky. we want to add the original locations
		#to the graph if nothing changed, but we want to add the new locations
		#to the graph is something did change or new points were added
		for l in lines:
			#print "adding edge."
			g.add_edge(l[0],l[1]);
	
	return g;
예제 #4
0
def testWirePixmap(face):
    """
		tests drawing a wire while adjusting sharp borders
	"""
    PIXEL = 0.01
    DEFLECTION = PIXEL / 4.0

    #get bounding box
    (xMin, yMin, zMin, xMax, yMax, zMax) = boundingBox([face])
    g = nx.Graph()
    #adjust boundaries a bit
    BUFFER = PIXEL * 5
    #make pixmap
    pixmap = pixmaptest.pixmap((xMin - BUFFER, yMin - BUFFER),
                               (xMax + BUFFER, yMax + BUFFER), PIXEL)

    ow = brt.OuterWire(face)
    boundary = tuplesFromWire(ow, DEFLECTION)

    for et in Wrappers.pairwise(boundary):
        p1 = et[0]
        p2 = et[1]
        g.add_edge(p1, p2)

        i1 = pixmap.index(p1)
        i2 = pixmap.index(p2)
        #print i1,i2,p1,p2
        lines = bres.piecewise_bresenham_line(pixmap.p, i1, i2)

        #add to the graph. this is tricky. we want to add the original locations
        #to the graph if nothing changed, but we want to add the new locations
        #to the graph is something did change or new points were added
        for l in lines:
            #print "adding edge."
            g.add_edge(l[0], l[1])

    return g