Skip to content

Commit

Permalink
Add 2d support for linestrips (#1430)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs authored Feb 28, 2023
1 parent 9c3ee1b commit 3710841
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
18 changes: 16 additions & 2 deletions examples/python/api_demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@ def run_segmentation() -> None:
rr.log_text_entry("logs/seg_demo_log", "label1 disappears and everything with label3 is now default colored again")


def run_points_3d() -> None:
def run_2d_lines() -> None:
import numpy as np

T = np.linspace(0, 5, 100)
for n in range(2, len(T)):
rr.set_time_seconds("sim_time", T[n])
t = T[:n]
x = np.cos(t * 5) * t
y = np.sin(t * 5) * t
pts = np.vstack([x, y]).T
rr.log_line_strip("2d_lines/spiral", positions=pts)


def run_3d_points() -> None:
import random

rr.set_time_seconds("sim_time", 1)
Expand Down Expand Up @@ -261,7 +274,8 @@ def run_extension_component() -> None:

def main() -> None:
demos = {
"3d_points": run_points_3d,
"2d_lines": run_2d_lines,
"3d_points": run_3d_points,
"log_cleared": run_log_cleared,
"rects": run_rects,
"segmentation": run_segmentation,
Expand Down
13 changes: 9 additions & 4 deletions rerun_py/rerun_sdk/rerun/log/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def log_line_strip(
timeless: bool = False,
) -> None:
r"""
Log a line strip through 3D space.
Log a line strip through 2D or 3D space.
A line strip is a list of points connected by line segments. It can be used to draw approximations of smooth curves.
Expand All @@ -61,7 +61,7 @@ def log_line_strip(
entity_path:
Path to the path in the space hierarchy
positions:
A Nx3 array of points along the path.
An Nx2 or Nx3 array of points along the path.
stroke_width:
Optional width of the line.
color:
Expand All @@ -83,7 +83,12 @@ def log_line_strip(
splats: Dict[str, Any] = {}

if positions is not None:
instanced["rerun.linestrip3d"] = LineStrip3DArray.from_numpy_arrays([positions])
if positions.shape[1] == 2:
instanced["rerun.linestrip2d"] = LineStrip2DArray.from_numpy_arrays([positions])
elif positions.shape[1] == 3:
instanced["rerun.linestrip3d"] = LineStrip3DArray.from_numpy_arrays([positions])
else:
raise TypeError("Positions should be either Nx2 or Nx3")

if color:
colors = _normalize_colors([color])
Expand Down Expand Up @@ -132,7 +137,7 @@ def log_line_segments(
entity_path:
Path to the line segments in the space hierarchy
positions:
A Nx3 array of points along the path.
An Nx2 or Nx3 array of points. Even-odd pairs will be connected as segments.
stroke_width:
Optional width of the line.
color:
Expand Down

1 comment on commit 3710841

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 3710841 Previous: 1f52337 Ratio
datastore/insert/batch/rects/insert 544196 ns/iter (± 1940) 617312 ns/iter (± 2195) 0.88
datastore/latest_at/batch/rects/query 1822 ns/iter (± 6) 1842 ns/iter (± 4) 0.99
datastore/latest_at/missing_components/primary 355 ns/iter (± 0) 355 ns/iter (± 10) 1
datastore/latest_at/missing_components/secondaries 425 ns/iter (± 0) 424 ns/iter (± 0) 1.00
datastore/range/batch/rects/query 153291 ns/iter (± 977) 156589 ns/iter (± 206) 0.98
mono_points_arrow/generate_message_bundles 47514201 ns/iter (± 1231756) 50313845 ns/iter (± 431092) 0.94
mono_points_arrow/generate_messages 135717587 ns/iter (± 1177378) 130017312 ns/iter (± 1296323) 1.04
mono_points_arrow/encode_log_msg 165358412 ns/iter (± 694312) 166195022 ns/iter (± 1179598) 0.99
mono_points_arrow/encode_total 351190021 ns/iter (± 1716074) 344666342 ns/iter (± 1564156) 1.02
mono_points_arrow/decode_log_msg 184741148 ns/iter (± 1019315) 183707166 ns/iter (± 736657) 1.01
mono_points_arrow/decode_message_bundles 71012913 ns/iter (± 1131543) 69732833 ns/iter (± 754934) 1.02
mono_points_arrow/decode_total 254709773 ns/iter (± 3198040) 250076421 ns/iter (± 1345984) 1.02
batch_points_arrow/generate_message_bundles 332632 ns/iter (± 1258) 335329 ns/iter (± 3390) 0.99
batch_points_arrow/generate_messages 6225 ns/iter (± 22) 6234 ns/iter (± 46) 1.00
batch_points_arrow/encode_log_msg 354207 ns/iter (± 1494) 410368 ns/iter (± 1497) 0.86
batch_points_arrow/encode_total 714943 ns/iter (± 2382) 775901 ns/iter (± 4557) 0.92
batch_points_arrow/decode_log_msg 346000 ns/iter (± 871) 396418 ns/iter (± 1695) 0.87
batch_points_arrow/decode_message_bundles 2081 ns/iter (± 17) 2059 ns/iter (± 37) 1.01
batch_points_arrow/decode_total 354301 ns/iter (± 685) 398273 ns/iter (± 2645) 0.89
arrow_mono_points/insert 6817562300 ns/iter (± 12906158) 6568740066 ns/iter (± 44376830) 1.04
arrow_mono_points/query 1739322 ns/iter (± 8158) 1870788 ns/iter (± 21492) 0.93
arrow_batch_points/insert 2641905 ns/iter (± 8333) 3120792 ns/iter (± 89870) 0.85
arrow_batch_points/query 17677 ns/iter (± 46) 17658 ns/iter (± 28) 1.00
tuid/Tuid::random 34 ns/iter (± 1) 41 ns/iter (± 0) 0.83

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.