Skip to content

Commit

Permalink
Add 2d support for linestrips
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Feb 28, 2023
1 parent 1f52337 commit 4a50687
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
19 changes: 17 additions & 2 deletions examples/python/api_demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@ 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
print(pts)
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 +275,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

0 comments on commit 4a50687

Please sign in to comment.