Exemple #1
0
def merge_shapes(shape_a,shape_b,vis=False):
    bo=BooleanOp()
    print "Shape_a,shape_b: ",shape_a,shape_b
    bo.step1_add_lines(shape_a,shape_b)
    bo.step2_intersect_lines()
    
    bo.step3_create_edges()
    bo.step4_eliminate_deadends()    
    bo.step5_create_cells()
    print "Calling determine hierarchy"
    bo.step5b_determine_cell_hierarchy()
    #dump_cells(bo)
    bo.step6_determine_cell_cover()
        
    bas=BooleanOrStrategy()
    bo.step7_classify_cells(bas)
    
    bo.step8_merge_cells();
    bo.step9_calc_result();
    #bo.step10_eliminate_enclosed_cells();
	
    #bo.step8_merge_cells()
    #bo.step9_calc_result()
    shape=bo.step11_get_result()
    polys=list(shape.get_polys())
    if vis:
        plines=set()
        for poly in polys:
            #print "Poly: %s %s"%(poly.get_kind_str(),list(poly.get_lines()))
            plines=plines.union(frozenset(poly.get_lines()))
        sqs=[]
        for line in plines:
            sqs.append(visualize.Line(
                line.get_v1().get_x(),
                line.get_v1().get_y(),
                line.get_v2().get_x(),
                line.get_v2().get_y(),                       
                (255,0,0)))
        draw_things(sqs)    
    return shape