MCPcopy Create free account
hub / github.com/JeremyBYU/polylidar / main

Function main

examples/python/basic25d_algorithm.py:19–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17
18
19def main():
20 np.random.seed(1)
21 # generate random plane with hole
22 plane = generate_3d_plane(bounds_x=[0, 10, 0.5], bounds_y=[0, 10, 0.5], holes=[
23 [[3, 5], [3, 5]]], height_noise=0.02, planar_noise=0.02)
24 # Generate top of box (causing the hole that we see)
25 box_top = generate_3d_plane(bounds_x=[3, 5, 0.2], bounds_y=[3, 5, 0.2], holes=[
26 ], height_noise=0.02, height=2, planar_noise=0.02)
27 # Generate side of box (causing the hole that we see)
28 box_side = generate_3d_plane(bounds_x=[0, 2, 0.2], bounds_y=[
29 0, 2, 0.2], holes=[], height_noise=0.02, planar_noise=0.02)
30 rm = rotation_matrix([0, 1, 0], -math.pi / 2.0)
31 box_side = apply_rotation(rm, box_side) + [5, 3, 0]
32 # All points joined together
33 points = np.concatenate((plane, box_side, box_top))
34
35 points_mat = MatrixDouble(points)
36 polylidar_kwargs = dict(alpha=0.0, lmax=1.0, min_triangles=20, z_thresh=0.1, norm_thresh_min=0.94)
37 polylidar = Polylidar3D(**polylidar_kwargs)
38
39 elev = 15.0
40 azim = -35
41
42 # Show Point Cloud
43 print("Should see point raw point cloud")
44 fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1,
45 subplot_kw=dict(projection='3d'))
46 # plot points
47 ax.scatter(*scale_points(points), s=20.0, c=points[:, 2], cmap=plt.cm.plasma)
48 set_axes_equal(ax)
49 ax.view_init(elev=elev, azim=azim)
50 fig.savefig("assets/scratch/Basic25DAlgorithm_pointcloud.pdf", bbox_inches='tight')
51 fig.savefig("assets/scratch/Basic25DAlgorithm_pointcloud.png", bbox_inches='tight', pad_inches=-0.8)
52 plt.show()
53
54 # Extracts planes and polygons, time
55 t1 = time.time()
56 mesh, planes, polygons = polylidar.extract_planes_and_polygons(points_mat)
57 t2 = time.time()
58 print("Polylidar Took {:.2f} milliseconds".format((t2 - t1) * 1000))
59
60 triangles = np.asarray(mesh.triangles)
61 all_planes = [np.arange(triangles.shape[0])]
62
63 # Show Triangulation
64 fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1,
65 subplot_kw=dict(projection='3d'))
66
67 plot_planes_3d(points, triangles, all_planes, ax, alpha=0.0, z_value=-4.0)
68 plot_planes_3d(points, triangles, all_planes, ax, alpha=0.5)
69 # plot points
70 ax.scatter(*scale_points(points), s=0.1, c='k')
71 set_axes_equal(ax, ignore_z=True)
72 ax.set_zlim3d([-4, 6])
73 ax.view_init(elev=elev, azim=azim)
74 print("Should see triangulation point cloud")
75 fig.savefig("assets/scratch/Basic25DAlgorithm_mesh.pdf", bbox_inches='tight')
76 fig.savefig("assets/scratch/Basic25DAlgorithm_mesh.png", bbox_inches='tight', pad_inches=-0.8)

Callers 1

Calls 8

generate_3d_planeFunction · 0.90
rotation_matrixFunction · 0.90
apply_rotationFunction · 0.90
scale_pointsFunction · 0.90
set_axes_equalFunction · 0.90
plot_planes_3dFunction · 0.90
plot_polygons_3dFunction · 0.90
Polylidar3DClass · 0.85

Tested by

no test coverage detected