Elffuss BraidHub

kikocis/SpatialLM public

974be99f8b28 · 2.6 KiBRawPermalink
1import argparse
2import numpy as np
3import rerun as rr
4import rerun.blueprint as rrb
5
6from spatiallm import Layout
7from spatiallm.pcd import load_o3d_pcd, get_points_and_colors
8
9if __name__ == "__main__":
10 parser = argparse.ArgumentParser("Layout Visualization with rerun")
11 parser.add_argument(
12 "-p",
13 "--point_cloud",
14 type=str,
15 required=True,
16 help="Path to the input point cloud file",
17 )
18 parser.add_argument(
19 "-l",
20 "--layout",
21 type=str,
22 required=True,
23 help="Path to the layout txt file",
24 )
25 parser.add_argument(
26 "--radius",
27 type=float,
28 default=0.01,
29 help="The radius of the points for visualization",
30 )
31 parser.add_argument(
32 "--max_points",
33 type=int,
34 default=1000000,
35 help="The maximum number of points for visualization",
36 )
37 rr.script_add_args(parser)
38 args = parser.parse_args()
39
40 with open(args.layout, "r") as f:
41 layout_content = f.read()
42
43 pcd = load_o3d_pcd(args.point_cloud)
44 points, colors = get_points_and_colors(pcd)
45
46 # parse layout_content
47 layout = Layout(layout_content)
48 floor_plan = layout.to_boxes()
49
50 # ReRun visualization
51 blueprint = rrb.Blueprint(
52 rrb.Spatial3DView(name="3D", origin="/world", background=[255, 255, 255]),
53 collapse_panels=True,
54 )
55 rr.script_setup(args, "rerun_spatiallm", default_blueprint=blueprint)
56
57 rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Z_UP, static=True)
58 point_indices = np.arange(points.shape[0])
59 np.random.shuffle(point_indices)
60 point_indices = point_indices[: args.max_points]
61 points = points[point_indices]
62 colors = colors[point_indices]
63 rr.log(
64 "world/points",
65 rr.Points3D(
66 positions=points,
67 colors=colors,
68 radii=args.radius,
69 ),
70 static=True,
71 )
72
73 num_entities = len(floor_plan)
74 seconds = 0.5
75 for ti in range(num_entities + 1):
76 sub_floor_plan = floor_plan[:ti]
77
78 rr.set_time_seconds("time_sec", ti * seconds)
79 for box in sub_floor_plan:
80 uid = box["id"]
81 group = box["class"]
82 label = box["label"]
83
84 rr.log(
85 f"world/pred/{group}/{uid}",
86 rr.Boxes3D(
87 centers=box["center"],
88 half_sizes=0.5 * box["scale"],
89 labels=label,
90 ),
91 rr.InstancePoses3D(mat3x3=box["rotation"]),
92 static=False,
93 )
94 rr.script_teardown(args)