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 not taking np.array for single colors #2569

Merged
merged 1 commit into from
Jun 30, 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
2 changes: 2 additions & 0 deletions rerun_py/rerun_sdk/rerun/components/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
class ColorRGBAArray(pa.ExtensionArray): # type: ignore[misc]
def from_numpy(array: npt.NDArray[np.uint8]) -> ColorRGBAArray:
"""Build a `ColorRGBAArray` from an numpy array."""
if array.ndim == 1:
array = np.reshape(array, (1, -1))
storage = pa.array(u8_array_to_rgba(array), type=ColorRGBAType.storage_type)
# TODO(john) enable extension type wrapper
# return cast(ColorRGBAArray, pa.ExtensionArray.from_storage(ColorRGBAType(), storage))
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def log_arrow(
vector = np.require(vector, dtype="float32")
instanced["rerun.arrow3d"] = Arrow3DArray.from_numpy(origin.reshape(1, 3), vector.reshape(1, 3))

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

if label:
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def log_obb(
else:
raise TypeError("rotation should be 1x4")

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

# We store the stroke_width in radius
Expand Down
12 changes: 6 additions & 6 deletions rerun_py/rerun_sdk/rerun/log/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def log_line_strip(
else:
raise TypeError("Positions should be either Nx2 or Nx3")

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

# We store the stroke_width in radius
Expand Down Expand Up @@ -190,13 +190,13 @@ def log_line_segments(
# If not a multiple of 2, drop the last row
if len(positions) % 2:
positions = positions[:-1]
if positions.shape[1] == 2:
if positions.ndim > 1 and positions.shape[1] == 2:
# Reshape even-odd pairs into a collection of line-strips of length2
# [[a00, a01], [a10, a11], [b00, b01], [b10, b11]]
# -> [[[a00, a01], [a10, a11]], [[b00, b01], [b10, b11]]]
positions = positions.reshape([len(positions) // 2, 2, 2])
instanced["rerun.linestrip2d"] = LineStrip2DArray.from_numpy_arrays(positions)
elif positions.shape[1] == 3:
elif positions.ndim > 1 and positions.shape[1] == 3:
# Same as above but for 3d points
positions = positions.reshape([len(positions) // 2, 2, 3])
instanced["rerun.linestrip3d"] = LineStrip3DArray.from_numpy_arrays(positions)
Expand All @@ -205,8 +205,8 @@ def log_line_segments(

# The current API splats both color and stroke-width, though the data-model doesn't
# require that we do so.
if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
splats["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

# We store the stroke_width in radius
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def log_point(
else:
raise TypeError("Position must have a total size of 2 or 3")

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

if radius:
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/rects.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def log_rect(

instanced["rerun.rect2d"] = Rect2DArray.from_numpy_and_format(rects, rect_format)

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

if label:
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def log_scalar(
if label:
instanced["rerun.label"] = LabelArray.new([label])

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

if radius:
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def log_text_entry(
else:
logging.warning(f"Null text entry in log_text_entry('{entity_path}') will be dropped.")

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

if ext:
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/text_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def log_text_entry_internal(
else:
logging.warning(f"Null text entry in log_text_entry('{entity_path}') will be dropped.")

if color:
colors = _normalize_colors([color])
if color is not None:
colors = _normalize_colors(color)
instanced["rerun.colorrgba"] = ColorRGBAArray.from_numpy(colors)

if splats:
Expand Down