Skip to content

Commit dd6ca6c

Browse files
jleibsemilk
authored andcommitted
Add 2d support for linestrips (#1430)
1 parent ba67cde commit dd6ca6c

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

examples/python/api_demo/main.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@ def run_segmentation() -> None:
7575
rr.log_text_entry("logs/seg_demo_log", "label1 disappears and everything with label3 is now default colored again")
7676

7777

78-
def run_points_3d() -> None:
78+
def run_2d_lines() -> None:
79+
import numpy as np
80+
81+
T = np.linspace(0, 5, 100)
82+
for n in range(2, len(T)):
83+
rr.set_time_seconds("sim_time", T[n])
84+
t = T[:n]
85+
x = np.cos(t * 5) * t
86+
y = np.sin(t * 5) * t
87+
pts = np.vstack([x, y]).T
88+
rr.log_line_strip("2d_lines/spiral", positions=pts)
89+
90+
91+
def run_3d_points() -> None:
7992
import random
8093

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

262275
def main() -> None:
263276
demos = {
264-
"3d_points": run_points_3d,
277+
"2d_lines": run_2d_lines,
278+
"3d_points": run_3d_points,
265279
"log_cleared": run_log_cleared,
266280
"rects": run_rects,
267281
"segmentation": run_segmentation,

rerun_py/rerun_sdk/rerun/log/lines.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def log_line_strip(
4444
timeless: bool = False,
4545
) -> None:
4646
r"""
47-
Log a line strip through 3D space.
47+
Log a line strip through 2D or 3D space.
4848
4949
A line strip is a list of points connected by line segments. It can be used to draw approximations of smooth curves.
5050
@@ -61,7 +61,7 @@ def log_line_strip(
6161
entity_path:
6262
Path to the path in the space hierarchy
6363
positions:
64-
A Nx3 array of points along the path.
64+
An Nx2 or Nx3 array of points along the path.
6565
stroke_width:
6666
Optional width of the line.
6767
color:
@@ -83,7 +83,12 @@ def log_line_strip(
8383
splats: Dict[str, Any] = {}
8484

8585
if positions is not None:
86-
instanced["rerun.linestrip3d"] = LineStrip3DArray.from_numpy_arrays([positions])
86+
if positions.shape[1] == 2:
87+
instanced["rerun.linestrip2d"] = LineStrip2DArray.from_numpy_arrays([positions])
88+
elif positions.shape[1] == 3:
89+
instanced["rerun.linestrip3d"] = LineStrip3DArray.from_numpy_arrays([positions])
90+
else:
91+
raise TypeError("Positions should be either Nx2 or Nx3")
8792

8893
if color:
8994
colors = _normalize_colors([color])
@@ -132,7 +137,7 @@ def log_line_segments(
132137
entity_path:
133138
Path to the line segments in the space hierarchy
134139
positions:
135-
A Nx3 array of points along the path.
140+
An Nx2 or Nx3 array of points. Even-odd pairs will be connected as segments.
136141
stroke_width:
137142
Optional width of the line.
138143
color:

0 commit comments

Comments
 (0)