Unverified Commit 6cbf0011 authored by Pascal Roth's avatar Pascal Roth Committed by GitHub

Adds ordering parameter for raycaster grid pattern (#483)

# Description

Allow changing of the indexing mode for the grid pattern of the
RayCaster. Possible options are:

- “xy”: the points are ordered with their y-dimension iterated over
first.
- “yx”: the points are ordered with their x-dimension iterated over
first.

## Type of change

- New feature (non-breaking change which adds functionality)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have run all the tests with `./orbit.sh --test` and they pass
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
parent 3acff1be
[package]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.15.7"
version = "0.15.8"
# Description
title = "ORBIT framework for Robot Learning"
......
Changelog
---------
0.15.8 (2024-04-02)
~~~~~~~~~~~~~~~~~~~
Added
^^^^^
* Adds option to define ordering of points for the mesh-grid generation in the
:func:`omni.isaac.orbit.sensors.ray_caster.patterns.grid_pattern`. This parameter defaults to 'xy'
for backward compatibility.
0.15.7 (2024-03-28)
~~~~~~~~~~~~~~~~~~~
......
......@@ -25,17 +25,35 @@ def grid_pattern(cfg: patterns_cfg.GridPatternCfg, device: str) -> tuple[torch.T
Returns:
The starting positions and directions of the rays.
Raises:
ValueError: If the ordering is not "xy" or "yx".
ValueError: If the resolution is less than or equal to 0.
"""
# check valid arguments
if cfg.ordering not in ["xy", "yx"]:
raise ValueError(f"Ordering must be 'xy' or 'yx'. Received: '{cfg.ordering}'.")
if cfg.resolution <= 0:
raise ValueError(f"Resolution must be greater than 0. Received: '{cfg.resolution}'.")
# resolve mesh grid indexing (note: torch meshgrid is different from numpy meshgrid)
# check: https://github.com/pytorch/pytorch/issues/15301
indexing = cfg.ordering if cfg.ordering == "xy" else "ij"
# define grid pattern
x = torch.arange(start=-cfg.size[0] / 2, end=cfg.size[0] / 2 + 1.0e-9, step=cfg.resolution, device=device)
y = torch.arange(start=-cfg.size[1] / 2, end=cfg.size[1] / 2 + 1.0e-9, step=cfg.resolution, device=device)
grid_x, grid_y = torch.meshgrid(x, y, indexing="xy")
grid_x, grid_y = torch.meshgrid(x, y, indexing=indexing)
# store into ray starts
num_rays = grid_x.numel()
ray_starts = torch.zeros(num_rays, 3, device=device)
ray_starts[:, 0] = grid_x.flatten()
ray_starts[:, 1] = grid_y.flatten()
# define ray-cast directions
ray_directions = torch.zeros_like(ray_starts)
ray_directions[..., :] = torch.tensor(list(cfg.direction), device=device)
return ray_starts, ray_directions
......
......@@ -10,6 +10,7 @@ from __future__ import annotations
import torch
from collections.abc import Callable, Sequence
from dataclasses import MISSING
from typing import Literal
from omni.isaac.orbit.utils import configclass
......@@ -33,17 +34,39 @@ class GridPatternCfg(PatternBaseCfg):
"""Configuration for the grid pattern for ray-casting.
Defines a 2D grid of rays in the coordinates of the sensor.
.. attention::
The points are ordered based on the :attr:`ordering` attribute.
"""
func: Callable = patterns.grid_pattern
resolution: float = MISSING
"""Grid resolution (in meters)."""
size: tuple[float, float] = MISSING
"""Grid size (length, width) (in meters)."""
direction: tuple[float, float, float] = (0.0, 0.0, -1.0)
"""Ray direction. Defaults to (0.0, 0.0, -1.0)."""
ordering: Literal["xy", "yx"] = "xy"
"""Specifies the ordering of points in the generated grid. Defaults to ``"xy"``.
Consider a grid pattern with points at :math:`(x, y)` where :math:`x` and :math:`y` are the grid indices.
The ordering of the points can be specified as "xy" or "yx". This determines the outer and inner loop order
when iterating over the grid points.
* If *"xy"* is selected, the points are ordered with outer loop over "x" and inner loop over "y".
* If *"yx"* is selected, the points are ordered with outer loop over "y" and inner loop over "x".
For example, the grid pattern points with :math:`X = (0, 1, 2)` and :math:`Y = (3, 4)`:
* *"xy"* ordering: :math:`[(0, 3), (0, 4), (1, 3), (1, 4), (2, 3), (2, 4)]`
* *"yx"* ordering: :math:`[(0, 3), (1, 3), (2, 3), (1, 4), (2, 4), (2, 4)]`
"""
@configclass
class PinholeCameraPatternCfg(PatternBaseCfg):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment