Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument parsing to the rerun_demo #1925

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions rerun_py/rerun_sdk/rerun_demo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,42 @@
import sys


def run_cube():
def run_cube(args: argparse.Namespace):
import math

import numpy as np
import rerun as rr

rr.init("Cube", spawn=True, default_enabled=True)
from rerun_demo.data import build_color_grid

rr.script_setup(args, "Cube")

STEPS = 100
twists = math.pi * np.sin(np.linspace(0, math.tau, STEPS)) / 4
for t in range(STEPS):
rr.set_time_sequence("step", t)
cube = build_color_grid(10, 10, 10, twist=twists[t])
rr.log_points("cube", positions=cube.positions, colors=cube.colors, radii=0.5)

rr.script_teardown(args)


def run_colmap():
def run_colmap(args):
from rerun import bindings, unregister_shutdown # type: ignore[attr-defined]

serve_opts = []

# TODO(https://github.com/rerun-io/rerun/issues/1924): The need to special-case
# this flag conversion is a bit awkward.
if args.connect or args.addr:
print("Connecting to external viewer is only supported with the --cube demo.", file=sys.stderr)
exit(1)
if args.save:
print("Saving an RRD file is only supported from the --cube demo.", file=sys.stderr)
exit(1)
if args.serve:
serve_opts.append("--web-viewer")

# We don't need to call shutdown in this case. Rust should be handling everything
unregister_shutdown()

Expand All @@ -33,11 +49,13 @@ def run_colmap():
print("No demo file found at {}. Package was built without demo support".format(rrd_file), file=sys.stderr)
exit(1)
else:
exit(bindings.main([sys.argv[0], str(rrd_file)]))
exit(bindings.main([sys.argv[0], str(rrd_file)] + serve_opts))


def main() -> None:
parser = argparse.ArgumentParser(description="Run rerun example programs")
import rerun as rr

parser = argparse.ArgumentParser(description="Run rerun example programs.")

group = parser.add_mutually_exclusive_group()

Expand All @@ -53,16 +71,18 @@ def main() -> None:
help="Run the COLMAP data demo",
)

rr.script_add_args(parser)

args = parser.parse_args()

if not any([args.cube, args.colmap]):
args.cube = True

if args.cube:
run_cube()
run_cube(args)

elif args.colmap:
run_colmap()
run_colmap(args)


if __name__ == "__main__":
Expand Down