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 --blueprint to DNA example + time-range override checklist #8558

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions examples/python/dna/dna.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np
import rerun as rr # pip install rerun-sdk
from rerun import blueprint as rrb
from rerun.utilities import bounce_lerp, build_color_spiral

DESCRIPTION = """
Expand Down Expand Up @@ -60,10 +61,33 @@ def log_data() -> None:
def main() -> None:
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.")
rr.script_add_args(parser)
parser.add_argument(
"--blueprint",
action="store_true",
help="Logs a blueprint that enables a cursor-relative time range on the beads.",
)
args = parser.parse_args()

rr.script_setup(args, "rerun_example_dna_abacus")
log_data()

if args.blueprint:
blueprint = rrb.Blueprint(
rrb.Spatial3DView(
origin="/",
overrides={
"helix/structure/scaffolding/beads": [
rrb.VisibleTimeRange(
"stable_time",
start=rrb.TimeRangeBoundary.cursor_relative(seconds=-0.3),
end=rrb.TimeRangeBoundary.cursor_relative(seconds=0.3),
),
]
},
),
)
rr.send_blueprint(blueprint)

rr.script_teardown(args)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from __future__ import annotations

import os
from argparse import Namespace
from math import tau
from uuid import uuid4

import numpy as np
import rerun as rr
import rerun.blueprint as rrb
from rerun.utilities import bounce_lerp, build_color_spiral

README = """\
# Individual time-range overrides

You should see the familiar Helix example, but the beads (and the beads only), should have a cursor-relative
time-range applied to them.

If you select the beads, you should see a `Visible Time Range` set to `[-0.3, +0.3]`.
"""

EXPECTED = """\
It should look something like this:
* ![expected](https://static.rerun.io/individual_overrides/7a9813500b81c2eeaf2a86f3603dab88bfd6b8c1/480w.png)
"""


def blueprint() -> rrb.BlueprintLike:
return rrb.Blueprint(
rrb.Horizontal(
contents=[
rrb.Spatial3DView(
origin="/",
overrides={
"helix/structure/scaffolding/beads": [
rrb.VisibleTimeRange(
"stable_time",
start=rrb.TimeRangeBoundary.cursor_relative(seconds=-0.3),
end=rrb.TimeRangeBoundary.cursor_relative(seconds=0.3),
),
]
},
),
rrb.Vertical(
rrb.TextDocumentView(origin="readme"),
rrb.TextDocumentView(origin="expected"),
row_shares=[1, 3],
),
]
),
)


def log_readme() -> None:
rr.log("readme", rr.TextDocument(README, media_type=rr.MediaType.MARKDOWN), static=True)


def log_helix() -> None:
rr.set_time_seconds("stable_time", 0)

rr.log(
"expected",
rr.TextDocument(EXPECTED, media_type=rr.MediaType.MARKDOWN),
)

NUM_POINTS = 100

# points and colors are both np.array((NUM_POINTS, 3))
points1, colors1 = build_color_spiral(NUM_POINTS)
points2, colors2 = build_color_spiral(NUM_POINTS, angular_offset=tau * 0.5)
rr.log("helix/structure/left", rr.Points3D(points1, colors=colors1, radii=0.08), static=True)
rr.log("helix/structure/right", rr.Points3D(points2, colors=colors2, radii=0.08), static=True)

rr.log(
"helix/structure/scaffolding",
rr.LineStrips3D(np.stack((points1, points2), axis=1), colors=[128, 128, 128]),
static=True,
)

time_offsets = np.random.rand(NUM_POINTS)
for i in range(400):
time = i * 0.01
rr.set_time_seconds("stable_time", time)

times = np.repeat(time, NUM_POINTS) + time_offsets
beads = [bounce_lerp(points1[n], points2[n], times[n]) for n in range(NUM_POINTS)]
colors = [[int(bounce_lerp(80, 230, times[n] * 2))] for n in range(NUM_POINTS)]
rr.log(
"helix/structure/scaffolding/beads", rr.Points3D(beads, radii=0.06, colors=np.repeat(colors, 3, axis=-1))
)

rr.log(
"helix/structure",
rr.Transform3D(rotation=rr.RotationAxisAngle(axis=[0, 0, 1], radians=time / 4.0 * tau)),
)


def run(args: Namespace) -> None:
rr.script_setup(args, f"{os.path.basename(__file__)}", recording_id=uuid4())

rr.send_blueprint(blueprint(), make_default=True, make_active=True)

log_readme()
log_helix()


if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser(description="Interactive release checklist")
rr.script_add_args(parser)
args = parser.parse_args()
run(args)
Loading