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

Fix default stroke width handling in log_line_strip_Xd and log_obbs #3720

Merged
merged 2 commits into from
Oct 6, 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
14 changes: 9 additions & 5 deletions rerun_py/rerun_sdk/rerun/log_deprecated/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ def _normalize_ids(class_ids: OptionalClassIds = None) -> npt.NDArray[np.uint16]
return np.atleast_1d(np.array(class_ids, dtype=np.uint16, copy=False))


def _normalize_radii(radii: npt.ArrayLike | None = None) -> npt.NDArray[np.float32]:
"""Normalize flexible radii arrays."""
if radii is None:
return np.array((), dtype=np.float32)
def _radii_from_stroke_width(stroke_width: npt.ArrayLike | None = None) -> npt.NDArray[np.float32] | None:
"""
Normalize and converts stroke widths to radii.

Returns None if radii is None.
"""
if stroke_width is None:
return None
else:
return np.atleast_1d(np.array(radii, dtype=np.float32, copy=False))
return np.atleast_1d(np.array(stroke_width, dtype=np.float32, copy=False)) / 2.0


def _normalize_labels(labels: str | Sequence[str] | None) -> Sequence[str]:
Expand Down
7 changes: 2 additions & 5 deletions rerun_py/rerun_sdk/rerun/log_deprecated/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Color,
Colors,
OptionalClassIds,
_radii_from_stroke_width,
)
from rerun.log_deprecated.log_decorator import log_decorator
from rerun.recording_stream import RecordingStream
Expand Down Expand Up @@ -177,11 +178,7 @@ def log_obbs(
else:
rotations = None

if stroke_widths is not None:
radii = np.asarray(stroke_widths, dtype="float32")
radii /= 2.0
else:
radii = None
radii = _radii_from_stroke_width(stroke_widths)

arch = Boxes3D(
half_sizes=half_sizes,
Expand Down
11 changes: 4 additions & 7 deletions rerun_py/rerun_sdk/rerun/log_deprecated/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rerun.any_value import AnyValues
from rerun.archetypes import LineStrips2D, LineStrips3D
from rerun.error_utils import _send_warning
from rerun.log_deprecated import Color, Colors, _normalize_radii
from rerun.log_deprecated import Color, Colors, _radii_from_stroke_width
from rerun.log_deprecated.log_decorator import log_decorator
from rerun.recording_stream import RecordingStream

Expand Down Expand Up @@ -86,8 +86,7 @@ def log_line_strip(

recording = RecordingStream.to_native(recording)

stroke_widths = _normalize_radii(stroke_width)
radii = stroke_widths / 2.0
radii = _radii_from_stroke_width(stroke_width)

positions = np.require(positions, dtype="float32")
if positions.shape[1] == 2:
Expand Down Expand Up @@ -190,8 +189,7 @@ def log_line_strips_2d(
if not isinstance(line_strips, Sequence) and isinstance(line_strips, Iterable):
line_strips = list(line_strips)

stroke_widths = _normalize_radii(stroke_widths)
radii = stroke_widths / 2.0
radii = _radii_from_stroke_width(stroke_widths)

arch = LineStrips2D(
line_strips,
Expand Down Expand Up @@ -279,8 +277,7 @@ def log_line_strips_3d(
if not isinstance(line_strips, Sequence) and isinstance(line_strips, Iterable):
line_strips = list(line_strips)

stroke_widths = _normalize_radii(stroke_widths)
radii = stroke_widths / 2.0
radii = _radii_from_stroke_width(stroke_widths)

arch = LineStrips3D(
line_strips,
Expand Down
Loading