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

Function main

examples/python/basic25d.py:19–65  ·  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 fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1,
40 subplot_kw=dict(projection='3d'))
41 # plot points
42 ax.scatter(*scale_points(points), s=2.5, c=points[:, 2], cmap=plt.cm.plasma)
43 set_axes_equal(ax)
44 ax.view_init(elev=15., azim=-35)
45 plt.show()
46
47 # Extracts planes and polygons, time
48 t1 = time.time()
49 mesh, planes, polygons = polylidar.extract_planes_and_polygons(points_mat)
50 t2 = time.time()
51 print("Took {:.2f} milliseconds".format((t2 - t1) * 1000))
52 print("Should see two planes extracted, please rotate.")
53
54 triangles = np.asarray(mesh.triangles)
55 fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1,
56 subplot_kw=dict(projection='3d'))
57 # plot all triangles
58 plot_planes_3d(points, triangles, planes, ax)
59 plot_polygons_3d(points, polygons, ax)
60 # plot points
61 ax.scatter(*scale_points(points), c='k', s=0.1)
62 set_axes_equal(ax)
63 ax.view_init(elev=15., azim=-35)
64 plt.show()
65 print("")
66
67
68if __name__ == "__main__":

Callers 1

basic25d.pyFile · 0.70

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