Skip to content

Commit

Permalink
feat: add data-classes to represent objects (#10)
Browse files Browse the repository at this point in the history
* feat: add dataclasses

Signed-off-by: ktro2828 <[email protected]>

* docs: update API documentation

Signed-off-by: ktro2828 <[email protected]>

* feat: apply `dataclass.Box*`

Signed-off-by: ktro2828 <[email protected]>

* feat: update `Label` enum and its test

Signed-off-by: ktro2828 <[email protected]>

* feat: rename `Label` to `LabelID`

Signed-off-by: ktro2828 <[email protected]>

* test: add unit testing for boxes

Signed-off-by: ktro2828 <[email protected]>

* feat: rename `Label` to `LabelID`

Signed-off-by: ktro2828 <[email protected]>

* test: add unit testing for boxes

Signed-off-by: ktro2828 <[email protected]>

* TODO: add dataclasses of pointcloud

Signed-off-by: ktro2828 <[email protected]>

* chore: move `transform.py` into `common`

Signed-off-by: ktro2828 <[email protected]>

* chore: move `transform.py` into `common`

Signed-off-by: ktro2828 <[email protected]>

* docs: update documents

Signed-off-by: ktro2828 <[email protected]>

* feat: update dataclasses

Signed-off-by: ktro2828 <[email protected]>

* style(pre-commit): autofix

---------

Signed-off-by: ktro2828 <[email protected]>
Co-authored-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 and ktro2828 authored Oct 17, 2024
1 parent cc41b9d commit 0d7736e
Show file tree
Hide file tree
Showing 29 changed files with 1,754 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Editor configurations
.vscode
6 changes: 2 additions & 4 deletions docs/apis/common.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# `common`

<!-- prettier-ignore-start -->
::: t4_devkit.common.box
options:
show_bases: false

::: t4_devkit.common.color

::: t4_devkit.common.geometry

::: t4_devkit.common.io

::: t4_devkit.common.timestamp

::: t4_devkit.common.transform
<!-- prettier-ignore-end -->
23 changes: 23 additions & 0 deletions docs/apis/dataclass.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# `dataclass`

<!-- prettier-ignore-start -->
::: t4_devkit.dataclass.box
options:
filters: ["!BaseBox"]
show_bases: false

::: t4_devkit.dataclass.label
options:
show_bases: false

::: t4_devkit.dataclass.pointcloud
options:
show_bases: false

::: t4_devkit.dataclass.roi

::: t4_devkit.dataclass.shape

::: t4_devkit.dataclass.trajectory

<!-- prettier-ignore-end -->
1 change: 1 addition & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav:
- API:
- TIER IV: apis/tier4.md
- Schema: apis/schema.md
- DataClass: apis/dataclass.md
- Common: apis/common.md

theme:
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ packages = [{ include = "t4_devkit" }]
[tool.poetry.dependencies]
python = ">=3.10,<3.13"
rerun-sdk = "0.17.0"
nuscenes-devkit = "^1.1.11"
pyquaternion = "^0.9.9"
matplotlib = "^3.9.2"
shapely = "<2.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.2"
Expand All @@ -24,3 +26,6 @@ ruff = "^0.6.8"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
line-length = 100
76 changes: 0 additions & 76 deletions t4_devkit/common/box.py

This file was deleted.

4 changes: 1 addition & 3 deletions t4_devkit/common/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def distance_color(
Color map in the shape of (N,). If input type is any number, returns a color as
`tuple[float, float, float]`. Otherwise, returns colors as `NDArrayF64`.
"""
color_map = (
matplotlib.colormaps["turbo_r"] if cmap is None else matplotlib.colormaps[cmap]
)
color_map = matplotlib.colormaps["turbo_r"] if cmap is None else matplotlib.colormaps[cmap]
norm = matplotlib.colors.Normalize(v_min, v_max)
return color_map(norm(distances))
12 changes: 4 additions & 8 deletions t4_devkit/common/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from typing import TYPE_CHECKING

import numpy as np

from t4_devkit.schema import VisibilityLevel

if TYPE_CHECKING:
from t4_devkit.dataclass import Box3D
from t4_devkit.typing import NDArrayF64

from .box import Box3D


__all__ = ("view_points", "is_box_in_image")

Expand Down Expand Up @@ -56,9 +56,7 @@ def view_points(
x_ = points[0]
y_ = points[1]
r2 = x_**2 + y_**2
f1 = (1 + k1 * r2 + k2 * r2**2 + k3 * r2**3) / (
1 + k4 * r2 + k5 * r2**2 + k6 * r2**3
)
f1 = (1 + k1 * r2 + k2 * r2**2 + k3 * r2**3) / (1 + k4 * r2 + k5 * r2**2 + k6 * r2**3)
f2 = x_ * y_
x__ = x_ * f1 + 2 * p1 * f2 + p2 * (r2 + 2 * x_**2) + s1 * r2 + s2 * r2**2
y__ = y_ * f1 + p1 * (r2 + 2 * y_**2) + 2 * p2 * f2 + s3 * r2 + s4 * r2**2
Expand Down Expand Up @@ -101,9 +99,7 @@ def is_box_in_image(
is_visible = np.logical_and(is_visible, corners_on_img[1, :] > 0)
is_visible = np.logical_and(is_visible, corners_on_img[2, :] > 1)

in_front = (
corners_3d[2, :] > 0.1
) # True if a corner is at least 0.1 meter in front of camera.
in_front = corners_3d[2, :] > 0.1 # True if a corner is at least 0.1 meter in front of camera.

if visibility == VisibilityLevel.FULL:
return all(is_visible) and all(in_front)
Expand Down
Loading

0 comments on commit 0d7736e

Please sign in to comment.