Skip to content

Commit 0a2b665

Browse files
WumpfCopilot
andauthored
Add simple test script for testing out widely branched transform hierarchies (#11437)
Co-authored-by: Copilot <[email protected]>
1 parent bcb148f commit 0a2b665

File tree

2 files changed

+95
-22
lines changed

2 files changed

+95
-22
lines changed

tests/python/many_entities/main.py

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from __future__ import annotations
2+
3+
import argparse
4+
5+
import rerun as rr
6+
import rerun.blueprint as rrb
7+
8+
9+
def main() -> None:
10+
parser = argparse.ArgumentParser(description="Simple benchmark for many transforms over time & space.")
11+
rr.script_add_args(parser)
12+
13+
parser.add_argument("--branching-factor", type=int, default=2, help="How many children each node has")
14+
parser.add_argument("--hierarchy-depth", type=int, default=10, help="How many levels of hierarchy we want")
15+
parser.add_argument(
16+
"--transforms-every-n-levels", type=int, default=2, help="At which level in the hierarchies we add transforms"
17+
)
18+
parser.add_argument(
19+
"--num-timestamps",
20+
type=int,
21+
default=100,
22+
help="Number of timestamps to log. Stamps shift for each entity a bit.",
23+
)
24+
parser.add_argument("--transforms-only", action="store_true", help="If set, don't log a point at each leaf")
25+
parser.add_argument(
26+
"--num-views", type=int, default=6, help="Number of 3D views to create (each will use a different origin)"
27+
)
28+
29+
args = parser.parse_args()
30+
31+
rr.script_setup(args, "rerun_example_benchmark_many_transforms")
32+
rr.set_time("sim_time", duration=0)
33+
34+
entity_paths = []
35+
call_id = 0
36+
37+
def log_hierarchy(entity_path: str, level: int) -> None:
38+
nonlocal call_id
39+
call_id += 1
40+
entity_paths.append(entity_path)
41+
42+
# Add a transform at every 'transforms_every_n_levels' level except root
43+
if level > 0 and level % args.transforms_every_n_levels == 0:
44+
# Add a static transform that has to be combined in to stress the per-timestamp transform resolve.
45+
rr.log(
46+
entity_path,
47+
# Have to be careful to not override all other transforms, therefore, use `from_fields`.
48+
rr.Transform3D.from_fields( #
49+
mat3x3=[
50+
[1.0 + level * 0.1, 0.0, 0.0], #
51+
[0.0, 1.0 + level * 0.1, 0.0],
52+
[0.0, 0.0, 1.0 + level * 0.1],
53+
]
54+
),
55+
static=True,
56+
)
57+
58+
# Add a transform that changes for each timestamp.
59+
for i in range(args.num_timestamps):
60+
call_id_factor = call_id * 0.02
61+
rr.set_time("sim_time", duration=i + call_id_factor)
62+
rr.log(
63+
entity_path,
64+
rr.Transform3D(
65+
translation=[i * 0.1 * level + call_id_factor, call_id_factor * level, 0.0],
66+
rotation_axis_angle=rr.RotationAxisAngle(axis=(0.0, 1.0, 0.0), degrees=i * 0.1),
67+
),
68+
)
69+
70+
if level == args.hierarchy_depth:
71+
if not args.transforms_only:
72+
# Log a single point at the leaf
73+
rr.set_time("sim_time", duration=0)
74+
rr.log(entity_path, rr.Points3D([[0.0, 0.0, 0.0]]))
75+
return
76+
77+
for i in range(args.branching_factor):
78+
child_path = f"{entity_path}/{i}_at_{level}"
79+
log_hierarchy(child_path, level + 1)
80+
81+
log_hierarchy("root", 0)
82+
83+
# All views display all entities.
84+
rr.send_blueprint(
85+
rrb.Blueprint(
86+
rrb.Grid(
87+
contents=[rrb.Spatial3DView(origin=path, contents="/**") for path in entity_paths[: args.num_views]]
88+
),
89+
collapse_panels=True, # Collapse panels, so perf is mostly about the data & the views.
90+
)
91+
)
92+
93+
94+
if __name__ == "__main__":
95+
main()

0 commit comments

Comments
 (0)