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 log_obb usage #1761

Merged
merged 6 commits into from
Apr 4, 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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ _Expect breaking changes!_
Some shortcomings:
* Big points clouds (1M+) are slow ([#1136](https://github.com/rerun-io/rerun/issues/1136))
* The data you want to visualize must fit in RAM.
- See <https://github.com/rerun-io/rerun/issues/1138> for how to bound memory use
- See <https://www.rerun.io/docs/howto/limit-ram> for how to bound memory use
- We plan on having a disk-based data store some time in the future
- Additionally, Rerun is using more memory than it should at the moment ([#1242](https://github.com/rerun-io/rerun/pull/1242))
* The Rust library takes a long time to compile
- We have way too many big dependencies, and we are planning on improving the situation ([#1316](https://github.com/rerun-io/rerun/pull/1316))

Expand Down
17 changes: 7 additions & 10 deletions examples/python/arkitscenes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,38 @@ def log_annotated_bboxes(
uid = label_info["uid"]
label = label_info["label"]

# TODO(pablovela5620): half this value once #1701 is resolved
scale = np.array(label_info["segments"]["obbAligned"]["axesLengths"]).reshape(-1, 3)[0]
transform = np.array(label_info["segments"]["obbAligned"]["centroid"]).reshape(-1, 3)[0]
half_size = 0.5 * np.array(label_info["segments"]["obbAligned"]["axesLengths"]).reshape(-1, 3)[0]
centroid = np.array(label_info["segments"]["obbAligned"]["centroid"]).reshape(-1, 3)[0]
rotation = np.array(label_info["segments"]["obbAligned"]["normalizedAxes"]).reshape(3, 3)

rot = R.from_matrix(rotation).inv()

rr.log_obb(
f"world/annotations/box-{uid}-{label}",
half_size=scale,
position=transform,
half_size=half_size,
position=centroid,
rotation_q=rot.as_quat(),
label=label,
color=color_list[i],
timeless=True,
)

box3d = compute_box_3d(scale, transform, rotation)
box3d = compute_box_3d(half_size, centroid, rotation)
bbox_list.append(box3d)
bbox_labels.append(label)
bboxes_3d = np.array(bbox_list)
return bboxes_3d, bbox_labels, color_list


def compute_box_3d(
scale: npt.NDArray[np.float64], transform: npt.NDArray[np.float64], rotation: npt.NDArray[np.float64]
half_size: npt.NDArray[np.float64], transform: npt.NDArray[np.float64], rotation: npt.NDArray[np.float64]
) -> npt.NDArray[np.float64]:
"""
Given obb compute 3d keypoints of the box.

TODO(pablovela5620): Once #1581 is resolved this can be removed
"""
scale = scale.tolist()
scales = [i / 2 for i in scale]
length, height, width = scales
length, height, width = half_size.tolist()
center = np.reshape(transform, (-1, 3))
center = center.reshape(3)
x_corners = [length, length, -length, -length, length, length, -length, -length]
Expand Down
2 changes: 1 addition & 1 deletion examples/python/clock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def rotate(angle: float, len: float) -> Tuple[float, float, float]:

rr.log_obb(
"world/frame",
half_size=[2 * LENGTH_S, 2 * LENGTH_S, 1.0],
half_size=[LENGTH_S, LENGTH_S, 1.0],
position=[0.0, 0.0, 0.0],
rotation_q=[0.0, 0.0, 0.0, 0.0],
timeless=True,
Expand Down
6 changes: 3 additions & 3 deletions examples/python/objectron/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def log_annotated_bboxes(bboxes: Iterable[Object]) -> None:
rot = R.from_matrix(np.asarray(bbox.rotation).reshape((3, 3)))
rr.log_obb(
f"world/annotations/box-{bbox.id}",
bbox.scale,
bbox.translation,
rot.as_quat(),
half_size=0.5 * np.array(bbox.scale),
position=bbox.translation,
rotation_q=rot.as_quat(),
color=[160, 230, 130, 255],
label=bbox.category,
timeless=True,
Expand Down
2 changes: 1 addition & 1 deletion examples/python/ros/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self) -> None:
# # TODO(jleibs): Log the real map once [#1531](https://github.com/rerun-io/rerun/issues/1531) is merged
rr.log_obb(
"map/box",
half_size=[6, 6, 2],
half_size=[3, 3, 1],
position=[0, 0, 1],
color=[255, 255, 255, 255],
timeless=True,
Expand Down
4 changes: 1 addition & 3 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,7 @@ def disconnect() -> None:

def save(path: str) -> None:
"""
Save previously logged data to a file.

This only works if you have not called `connect`.
Stream all log-data to a file.

Parameters
----------
Expand Down
13 changes: 7 additions & 6 deletions rerun_py/rerun_sdk/rerun/log/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@log_decorator
def log_obb(
entity_path: str,
*,
half_size: Optional[npt.ArrayLike],
position: Optional[npt.ArrayLike] = None,
rotation_q: Optional[npt.ArrayLike] = None,
Expand Down Expand Up @@ -72,28 +73,28 @@ def log_obb(
splats: Dict[str, Any] = {}

if half_size is not None:
size = np.require(half_size, dtype="float32")
half_size = np.require(half_size, dtype="float32")

if size.shape[0] == 3:
instanced["rerun.box3d"] = Box3DArray.from_numpy(size.reshape(1, 3))
if half_size.shape[0] == 3:
instanced["rerun.box3d"] = Box3DArray.from_numpy(half_size.reshape(1, 3))
else:
raise TypeError("Position should be 1x3")
raise TypeError("half_size should be 1x3")

if position is not None:
position = np.require(position, dtype="float32")

if position.shape[0] == 3:
instanced["rerun.vec3d"] = Vec3DArray.from_numpy(position.reshape(1, 3))
else:
raise TypeError("Position should be 1x3")
raise TypeError("position should be 1x3")

if rotation_q is not None:
rotation = np.require(rotation_q, dtype="float32")

if rotation.shape[0] == 4:
instanced["rerun.quaternion"] = QuaternionArray.from_numpy(rotation.reshape(1, 4))
else:
raise TypeError("Rotation should be 1x4")
raise TypeError("rotation should be 1x4")

if color:
colors = _normalize_colors([color])
Expand Down
1 change: 1 addition & 0 deletions rerun_py/rerun_sdk/rerun/log/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
def log_scalar(
entity_path: str,
scalar: float,
*,
label: Optional[str] = None,
color: Optional[Sequence[int]] = None,
radius: Optional[float] = None,
Expand Down