예제 #1
0
파일: LR1.py 프로젝트: SteveZhangBit/JHinge
def first(stmt, search_set):
    if len(stmt) == 0:
        return search_set
    elif stmt[0] in terminal_set:
        return set([stmt[0]])
    elif stmt[0] in non_terminal_set:
        re = first_set(stmt[0])

        if '' in re:
            re = re.copy()
            re.remove('')
            re = re.union(first(stmt[1:], search_set))

        return re
예제 #2
0
파일: LL1.py 프로젝트: SteveZhangBit/JHinge
def first_for_stat(left, statement):
    global terminal_set
    global non_terminal_set

    if len(statement) == 0:
        return follow(left)
    else:
        word = statement[0]
        if word in terminal_set:
            return set([word])
        elif word in non_terminal_set:
            re = first(word)
            if '' in re:
                re = re.union(first_for_stat(left, statement[1:]))
                re.remove('')
                return re
            else:
                return re
예제 #3
0
파일: LR1.py 프로젝트: SteveZhangBit/JHinge
def first_set(nonterminal):
    # prevent left recursion
    first_set.recursion.add(nonterminal)

    if nonterminal in first_set.dic:
        first_set.recursion.remove(nonterminal)
        return first_set.dic[nonterminal]
    else:
        re = first_set.dic[nonterminal] = set()
        for s in bnf_dic[nonterminal]:
            if len(s) == 0:
                re.add('')
            elif s[0] in terminal_set:
                re.add(s[0])
            elif s[0] in non_terminal_set and s[0] not in first_set.recursion:
                re = re.union(first_set(s[0]))
                first_set.dic[nonterminal] = re

        first_set.recursion.remove(nonterminal)
        return first_set.dic[nonterminal]
예제 #4
0
def processGeo(path, file_name):
    # print(file_name)
    ans = np.zeros(1)
    try:
        objfile = open(path + '/' + file_name)
        point_num = 0
        face_num = 0
        point_buf_arr = []
        face_buf_arr = []
        input_str = objfile.readline()
        while input_str != "":
            input_str = objfile.readline()
            if input_str[:2] == 'v ':
                point_num += 1
                for i in range(1, 4):
                    point_buf_arr.append(eval(input_str.split()[i]))
            elif input_str[:2] == 'f ':
                face_num += 1
                for i in range(1, 4):
                    face_buf_arr.append(
                        int(eval(input_str.split()[i].split('/')[0])))

        if point_num == 0 or face_num == 0:
            return np.zeros(1)

        parr = np.array(point_buf_arr, dtype=np.float)
        parr = parr.reshape(point_num, 3)
        delta = parr.max(axis=0) - parr.min(axis=0)
        parr = np.delete(parr, np.where(delta == min(delta)), axis=1)

        farr = np.array(face_buf_arr, dtype=np.int)
        farr = farr.reshape(face_num, 3) - np.ones((face_num, 3))

        # print(parr, point_num)

        # print(farr, face_num)

        re = Polygon()
        for f in farr:
            points = [(parr[int(p)][0], parr[int(p)][1]) for p in f]
            poly = Polygon(points)

            # print(poly)
            # plt.plot(*poly.exterior.xy)
            # plt.show()
            if (poly.is_valid):
                re = re.union(poly)
            # print(re)
            # plt.plot(*re.exterior.xy)
            # plt.show()
            # input()

        # plt.cla()
        # plt.plot(*re.exterior.xy)
        # plt.show()
        # print(re)
        # print(re)
        # print( orient(re,1.0))
        re = orient(re, 1.0)
        ans = np.array(re.exterior.xy).T
        ans = ans[:-1]

        if get_norm:
            p = polygen(ans)
            ans = p.get_norm()
        # print(ans)

    except Exception as e:
        print('!!!Wrong at ' + file_name + '\n' + str(e))
        print(ans)
        return ans

    finally:

        if savepic:
            plt.cla()
            plt.scatter(ans[:, 0], ans[:, 1], s=1)
            if get_norm:
                plt.scatter(ans[:, 0] + ans[:, 2], ans[:, 1] + ans[:, 3], s=2)
            plt.plot(*re.exterior.xy)
            for i in range(0, len(ans)):
                plt.annotate(i, (ans[i][0], ans[i][1]))
            plt.savefig(path + '/' + file_name + '.png')

        return ans