()
| 14 | return pointer |
| 15 | |
| 16 | def main(): |
| 17 | |
| 18 | kwargs = dict(num_groups=2, group_size=1000, dist=100.0, seed=1) |
| 19 | # generate random normally distributed clusters of points, 200 X 2 numpy array. |
| 20 | points = generate_test_points(**kwargs) |
| 21 | lmax = get_estimated_lmax(**kwargs) |
| 22 | polylidar_kwargs = dict(alpha=0.0, lmax=lmax, min_triangles=5) |
| 23 | # print(polylidar_kwargs) |
| 24 | # Convert Points and make Polylidar |
| 25 | points_mat = MatrixDouble(points) |
| 26 | polylidar = Polylidar3D(**polylidar_kwargs) |
| 27 | # Extracts planes and polygons, time |
| 28 | t1 = time.perf_counter() |
| 29 | mesh, planes, polygons = polylidar.extract_planes_and_polygons(points_mat) |
| 30 | t2 = time.perf_counter() |
| 31 | triangles = np.asarray(mesh.triangles) |
| 32 | # print(triangles, triangles.shape) |
| 33 | triangles = triangles.flatten() |
| 34 | # print(triangles, triangles.shape) |
| 35 | planes_np = np.asarray(planes) |
| 36 | # print(planes_np) |
| 37 | print("Took {:.2f} milliseconds".format((t2 - t1) * 1000)) |
| 38 | |
| 39 | # Plot Data |
| 40 | if points.shape[0] < 100000: |
| 41 | fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1) |
| 42 | # plot points |
| 43 | print("Plot Points") |
| 44 | ax.scatter(points[:, 0], points[:, 1], c='k', s=20.0) |
| 45 | fig.savefig("assets/scratch/Basic2DAlgorithm_pointcloud.png", bbox_inches='tight', pad_inches=-0.6) |
| 46 | plt.show() |
| 47 | |
| 48 | print("Plot Mesh") |
| 49 | fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1) |
| 50 | # plot points |
| 51 | ax.scatter(points[:, 0], points[:, 1], c='k', s=0.1) |
| 52 | # plot all triangles |
| 53 | plot_triangles(get_triangles_from_list(triangles, points), ax) |
| 54 | fig.savefig("assets/scratch/Basic2DAlgorithm_mesh.png", bbox_inches='tight', pad_inches=-0.6) |
| 55 | plt.show() |
| 56 | |
| 57 | print("Planes and Polygons") |
| 58 | fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1) |
| 59 | # plot points |
| 60 | ax.scatter(points[:, 0], points[:, 1], c='k', s=0.1) |
| 61 | # plot all triangles |
| 62 | plot_triangles(get_triangles_from_list(triangles, points), ax) |
| 63 | # plot mesh triangles |
| 64 | triangle_meshes = get_colored_planar_segments(planes_np, triangles, points) |
| 65 | plot_triangle_meshes(triangle_meshes, ax) |
| 66 | # plot polygons |
| 67 | plot_polygons(polygons, points, ax) |
| 68 | |
| 69 | plt.axis('equal') |
| 70 | |
| 71 | plt.show() |
| 72 | |
| 73 | if __name__ == "__main__": |
no test coverage detected