Skip to content

Commit

Permalink
Add Helix to demo.rerun.io (#2930)
Browse files Browse the repository at this point in the history
What the title says.

Didn't rename the `dna` folder on purpose: not particularly looking to
deal with broken links all over the place today :)

### What

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2930) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2930)
- [Docs preview](https://rerun.io/preview/pr%3Acmc%2Fhelix_demo/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Acmc%2Fhelix_demo/examples)
  • Loading branch information
teh-cmc authored and emilk committed Aug 17, 2023
1 parent a21b711 commit 8a45dae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
62 changes: 36 additions & 26 deletions examples/python/dna/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,54 @@
"""
from __future__ import annotations

import sys
import argparse
from math import tau

import numpy as np
import rerun as rr # pip install rerun-sdk
from rerun_demo.data import build_color_spiral
from rerun_demo.util import bounce_lerp, interleave

# sanity-check since all other example scripts take arguments:
assert len(sys.argv) == 1, f"{sys.argv[0]} does not take any arguments"

rr.init("DNA Abacus")
def log_data() -> None:
rr.set_time_seconds("stable_time", 0)

rr.spawn()
rr.set_time_seconds("stable_time", 0)
NUM_POINTS = 100

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_points("helix/structure/left", points1, colors=colors1, radii=0.08)
rr.log_points("helix/structure/right", points2, colors=colors2, radii=0.08)

# 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_points("dna/structure/left", points1, colors=colors1, radii=0.08)
rr.log_points("dna/structure/right", points2, colors=colors2, radii=0.08)
points = interleave(points1, points2)
rr.log_line_segments("helix/structure/scaffolding", points, color=[128, 128, 128])

points = interleave(points1, points2)
rr.log_line_segments("dna/structure/scaffolding", points, color=[128, 128, 128])
time_offsets = np.random.rand(NUM_POINTS)
for i in range(400):
time = i * 0.01
rr.set_time_seconds("stable_time", time)

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_points("helix/structure/scaffolding/beads", beads, radii=0.06, colors=np.repeat(colors, 3, axis=-1))

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_points("dna/structure/scaffolding/beads", beads, radii=0.06, colors=np.repeat(colors, 3, axis=-1))
rr.log_transform3d(
"helix/structure",
rr.RotationAxisAngle(axis=[0, 0, 1], radians=time / 4.0 * tau),
)

rr.log_transform3d(
"dna/structure",
rr.RotationAxisAngle(axis=[0, 0, 1], radians=time / 4.0 * tau),
)

def main() -> None:
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.")
rr.script_add_args(parser)
args = parser.parse_args()

rr.script_setup(args, "DNA Abacus")
log_data()
rr.script_teardown(args)


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions scripts/ci/build_demo_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ def main() -> None:
""",
"build_args": [],
},
"dna": {
"title": "Helix",
"description": """
Simple example of logging line primitives to draw a 3D helix.
""",
"build_args": [],
},
}

if __name__ == "__main__":
Expand Down

0 comments on commit 8a45dae

Please sign in to comment.