コード例 #1
0
ファイル: robust.py プロジェクト: x-malet/polylidar
def main():
    points = load_csv('robust_1.csv')
    polylidar_kwargs = dict(alpha=0.0, lmax=1000.0, min_triangles=1)

    points_mat = MatrixDouble(points)
    polylidar = Polylidar3D(**polylidar_kwargs)

    # Extracts planes and polygons, time
    t1 = time.time()
    # pick large lmax to get the convex hull, no triangles filtered
    mesh, planes, polygons = polylidar.extract_planes_and_polygons(points_mat)
    t2 = time.time()
    print("Took {:.2f} milliseconds".format((t2 - t1) * 1000))
    print(
        "If Robust Geometric Predicates is NOT activated, you should see a malformed convex hull"
    )
    print(
        "See README.md to activate if desired. ~20% performance penalty when active."
    )
    print("")
    # Convert to numpy format, no copy with np.asarray()
    triangles = np.asarray(mesh.triangles)

    fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1)
    # plot points
    ax.scatter(points[:, 0], points[:, 1], c='k')
    # plot all triangles
    plot_triangles(get_triangles_from_list(triangles, points), ax)
    # plot seperated planar triangular segments
    triangle_meshes = get_colored_planar_segments(planes, triangles, points)
    plot_triangle_meshes(triangle_meshes, ax)
    # plot polygons
    plot_polygons(polygons, points, ax)
    plt.axis('equal')
    plt.show()
コード例 #2
0
def main():

    letter_map = read_alphabet()
    # letters = ['P', 'O', 'L', 'Y', 'L', 'I', 'D', 'A', 'R']
    points = stitch_letters(letter_map)

    # plt.scatter(points[:, 0], points[:, 1], s=0.2)
    # plt.show()
    print(int(points.shape[0] / 2))
    idx = np.random.randint(0, points.shape[0], size=int(points.shape[0] / 2))
    points = np.ascontiguousarray(points[idx, :])
    lmax = 10.0
    polylidar_kwargs = dict(alpha=0.0, lmax=lmax, min_triangles=5)
    # print(polylidar_kwargs)
    # Convert Points and make Polylidar
    points_mat = MatrixDouble(points)
    polylidar = Polylidar3D(**polylidar_kwargs)
    # Extracts planes and polygons, time
    t1 = time.perf_counter()
    mesh, planes, polygons = polylidar.extract_planes_and_polygons(points_mat)
    t2 = time.perf_counter()
    triangles = np.asarray(mesh.triangles)
    # print(triangles, triangles.shape)
    triangles = triangles.flatten()
    # print(triangles, triangles.shape)
    planes_np = planes
    # print(planes_np)
    print("Took {:.2f} milliseconds".format((t2 - t1) * 1000))

    # Plot Data
    if points.shape[0] < 100000:
        fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1)
        ax.set_xticks([])
        ax.set_yticks([])
        plt.axis('equal')
        plt.axis('off')
        # plot points
        plot_points(points, ax)
        fig.savefig('assets/scratch/pl_logo_points.png',
                    bbox_inches='tight',
                    transparent=True)
        # plot all triangles
        plot_triangles(get_triangles_from_list(triangles, points), ax)
        # plot mesh triangles
        triangle_meshes = get_colored_planar_segments(planes_np, triangles,
                                                      points)
        plot_triangle_meshes(triangle_meshes, ax)
        # plot polygons
        plot_polygons(polygons, points, ax, linewidth=4.0)

        plt.subplots_adjust(wspace=0.185,
                            hspace=0.185,
                            left=0.110,
                            top=0.535,
                            right=0.750,
                            bottom=0.110)
        fig.savefig('assets/scratch/pl_logo.png',
                    bbox_inches='tight',
                    transparent=True)
        plt.show()
コード例 #3
0
def main():

    kwargs = dict(num_groups=2, group_size=1000, dist=100.0, seed=1)
    # generate random normally distributed clusters of points, 200 X 2 numpy array.
    points = generate_test_points(**kwargs)
    lmax = get_estimated_lmax(**kwargs)
    polylidar_kwargs = dict(alpha=0.0, lmax=lmax, min_triangles=5)
    # print(polylidar_kwargs)
    # Convert Points and make Polylidar
    points_mat = MatrixDouble(points)
    polylidar = Polylidar3D(**polylidar_kwargs)
    # Extracts planes and polygons, time
    t1 = time.perf_counter()
    mesh, planes, polygons = polylidar.extract_planes_and_polygons(points_mat)
    t2 = time.perf_counter()
    triangles = np.asarray(mesh.triangles)
    # print(triangles, triangles.shape)
    triangles = triangles.flatten()
    # print(triangles, triangles.shape)
    planes_np = np.asarray(planes)
    # print(planes_np)
    print("Took {:.2f} milliseconds".format((t2 - t1) * 1000))

    # Plot Data
    if points.shape[0] < 100000:
        fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1)
        # plot points
        print("Plot Points")
        ax.scatter(points[:, 0], points[:, 1], c='k', s=20.0)
        fig.savefig("assets/scratch/Basic2DAlgorithm_pointcloud.png",
                    bbox_inches='tight',
                    pad_inches=-0.6)
        plt.show()

        print("Plot Mesh")
        fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1)
        # plot points
        ax.scatter(points[:, 0], points[:, 1], c='k', s=0.1)
        # plot all triangles
        plot_triangles(get_triangles_from_list(triangles, points), ax)
        fig.savefig("assets/scratch/Basic2DAlgorithm_mesh.png",
                    bbox_inches='tight',
                    pad_inches=-0.6)
        plt.show()

        print("Planes and Polygons")
        fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1)
        # plot points
        ax.scatter(points[:, 0], points[:, 1], c='k', s=0.1)
        # plot all triangles
        plot_triangles(get_triangles_from_list(triangles, points), ax)
        # plot mesh triangles
        triangle_meshes = get_colored_planar_segments(planes_np, triangles,
                                                      points)
        plot_triangle_meshes(triangle_meshes, ax)
        # plot polygons
        plot_polygons(polygons, points, ax)

        plt.axis('equal')

        plt.show()