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 2d support for linestrips #1430

Merged
merged 1 commit into from
Feb 28, 2023
Merged
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
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