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

Python <-> Rust bridge fixes #42

Merged
merged 3 commits into from
Aug 19, 2022
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
7 changes: 2 additions & 5 deletions crates/re_sdk_python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def log_dummy_data(args):
"""Log a few frames of generated dummy data to show how the Rerun SDK is used."""
NUM_FRAMES = 20
NUM_FRAMES = 40

for sample in generate_dummy_data(num_frames=NUM_FRAMES):
# This will assign logged objects a "time source" called `frame_nr`.
Expand All @@ -22,10 +22,7 @@ def log_dummy_data(args):
# The depth image is in millimeters, so we set meter=1000
rerun.log_depth_image("depth", sample.depth_image_mm, meter=1000)

# TODO(nikolausWest): Make setting the color here optional
rgba = [200, 0, 100, 200]
colors = np.array([rgba])
rerun.log_points("depth3D", sample.point_cloud.copy(), colors)
rerun.log_points("depth3D", sample.point_cloud)

rerun.log_image("rgb", sample.rgb_image)

Expand Down
9 changes: 8 additions & 1 deletion crates/re_sdk_python/python/rerun_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def log_points(obj_path, positions, colors=None, space=None):
If no `space` is given, the space name "2D" or "3D" will be used,
depending on the dimensionality of the data.
"""
if colors is not None:
if colors is None:
# An empty array represents no colors.
colors = np.array((), dtype=np.uint8)
else:
# Rust expects colors in 0-255 uint8
if colors.dtype in ['float32', 'float64']:
if np.amax(colors) < 1.1:
Expand All @@ -119,6 +122,10 @@ def log_points(obj_path, positions, colors=None, space=None):

positions.astype('float32')

# Workaround to handle that `rerun_rs` can't handle numpy views correctly.
# TODO(nikolausWest): Remove this extra copy once underlying issue in Rust SDK is fixed.
positions = positions if positions.base is None else positions.copy()

rerun_rs.log_points_rs(obj_path, positions, colors, space)


Expand Down
2 changes: 1 addition & 1 deletion crates/re_sdk_python/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn log_bbox(
fn log_points_rs(
obj_path: &str,
positions: numpy::PyReadonlyArray2<'_, f64>,
colors: numpy::PyReadonlyArray2<'_, u8>,
colors: numpy::PyReadonlyArrayDyn<'_, u8>,
space: Option<String>,
) -> PyResult<()> {
if positions.is_empty() {
Expand Down