예제 #1
0
파일: test.py 프로젝트: Daiver/jff
def bigRandomMeshTest():
    width, height = 900, 900
    numOfPoints = 2000
    mesh = Mesh(width, height)
    for i in xrange(numOfPoints):
        x = random.randint(0, width/5)*5
        y = random.randint(0, height/5)*5
        mesh.addPointAndTriangulate((x, y))
        if i % 10 == 0:
            if countOfNotDelTriangles(mesh) > 0:
                print 'ERROR', countOfNotDelTriangles(mesh), '>', x, y
                cv2.imshow('', mesh.draw())
                cv2.imwrite('dump.png', mesh.draw())
                with open('fail_vertexes_dump', 'w') as f:
                    for v in mesh.vertexes:
                        f.write('%d %d\n' % (v.point[0], v.point[1]))
                exit()
                cv2.waitKey(1000)
        if i % 50 == 0:
            print 'i', i
    #cv2.imshow('', mesh.draw())
    print 'End'
    return mesh
예제 #2
0
def bigRandomMeshTest():
    width, height = 900, 900
    numOfPoints = 2000
    mesh = Mesh(width, height)
    for i in xrange(numOfPoints):
        x = random.randint(0, width / 5) * 5
        y = random.randint(0, height / 5) * 5
        mesh.addPointAndTriangulate((x, y))
        if i % 10 == 0:
            if countOfNotDelTriangles(mesh) > 0:
                print 'ERROR', countOfNotDelTriangles(mesh), '>', x, y
                cv2.imshow('', mesh.draw())
                cv2.imwrite('dump.png', mesh.draw())
                with open('fail_vertexes_dump', 'w') as f:
                    for v in mesh.vertexes:
                        f.write('%d %d\n' % (v.point[0], v.point[1]))
                exit()
                cv2.waitKey(1000)
        if i % 50 == 0:
            print 'i', i
    #cv2.imshow('', mesh.draw())
    print 'End'
    return mesh
예제 #3
0
    import sys
    if len(sys.argv) > 1:
        points = readPoints(sys.argv[1])
        width = max(points, key=lambda (x, y): x)[0] + 0
        height = max(points, key=lambda (x, y): y)[1] + 0
        mesh = Mesh(width, height)
        for p in points:
            mesh.addPointAndTriangulate(p)
    else:
        mesh = Mesh(600, 600)

    print 'num of errors', test.countOfNotDelTriangles(mesh)

    def mouseClick(event, x, y, f, mesh):
        if event == cv2.EVENT_LBUTTONDOWN:
            print x, y
            point = (x/scale, (y)/scale)
            mesh.addPointAndTriangulate(point)
            cv2.imshow('2', mesh.draw())
            print test.countOfNotDelTriangles(mesh)
            #img1 = cv2.flip(mesh.draw(), 0)
            #points = mesh.faces[triIndx].vertexesPoints()
            #cv2.fillPoly(img1,np.array( [points]), (0,0,255))
            #cv2.imshow('423', cv2.flip(img1, 0))

    img2 = mesh.draw()
    cv2.imshow('2', img2)
    cv2.setMouseCallback('2', mouseClick, mesh)
    cv2.waitKey()