Skip to content
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: 3 additions & 4 deletions src/av2/rendering/rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ def xyz_to_bev(
# Otherwise, use the provided intensity.
intensity: NDArrayByte
if xyz.shape[-1] == 3:
intensity = np.ones_like(xyz.shape[0], np.uint8)
cart = xyz.copy()
intensity = np.ones_like(xyz[:, 0:1], np.uint8)
else:
cart = xyz[..., :-1].copy()
intensity = xyz[..., -1].copy().astype(np.uint8)

# Grab the Cartesian coordinates (xyz).
cart = xyz[..., :-1].copy()

# Move the origin to the center of the image.
cart += np.divide(grid_size_m, 2)

Expand Down
41 changes: 41 additions & 0 deletions tests/rendering/test_rasterize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Tests for the rasterize module."""

from typing import Tuple

import numpy as np

from av2.rendering.rasterize import xyz_to_bev
from av2.utils.typing import NDArrayFloat


def _build_dummy_raster_inputs(
n: int, d: int
) -> Tuple[NDArrayFloat, Tuple[float, float, float], Tuple[float, float, float], NDArrayFloat]:
"""Build dummy inputs for the rasterize function.

Args:
n: Number of points.
d: Number of dimensions.

Returns:
(n,d) points, (3,) voxel resolution, (3,) grid size, (n,) cmap values.
"""
xyz = np.ones((n, d))
voxel_resolution = (0.1, 0.1, 0.1)
grid_size_m = (50.0, 50.0, 10.0)
cmap = np.ones_like(xyz[:, 0:1])
return xyz, voxel_resolution, grid_size_m, cmap


def test_rasterize_Nx3() -> None:
"""Test the rasterize function with (N,3) input."""
n, d = 1000, 3
xyz, voxel_resolution, grid_size_m, cmap = _build_dummy_raster_inputs(n, d)
xyz_to_bev(xyz, voxel_resolution, grid_size_m, cmap)


def test_rasterize_Nx4() -> None:
"""Test the rasterize function with (N,4) input."""
n, d = 1000, 4
xyz, voxel_resolution, grid_size_m, cmap = _build_dummy_raster_inputs(n, d)
xyz_to_bev(xyz, voxel_resolution, grid_size_m, cmap)