Skip to content

Commit

Permalink
Add constructors for Python, that don't work
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 26, 2024
1 parent a831154 commit 18bc9f6
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 47 deletions.
7 changes: 3 additions & 4 deletions docs/snippets/all/annotation_context_rects.py
@@ -1,12 +1,11 @@
import rerun as rr
import rerun.blueprint as rrb

rr.init("rerun_example_annotation_context_rects", spawn=True)
blueprint = rrb.Spatial2DView(background=[128, 0, 0], visual_bounds=rrb.VisualBounds(min=[-4.5, -2.5], max=[2.5, 2.5]))
rr.init("rerun_example_annotation_context_rects", spawn=True, default_blueprint=blueprint)

# Log an annotation context to assign a label and color to each class
rr.log("/", rr.AnnotationContext([(1, "red", (255, 0, 0)), (2, "green", (0, 255, 0))]), static=True)

# Log a batch of 2 rectangles with different `class_ids`
rr.log("detections", rr.Boxes2D(mins=[[-2, -2], [0, 0]], sizes=[[3, 3], [2, 2]], class_ids=[1, 2]))

# Log an extra rect to set the view bounds
rr.log("bounds", rr.Boxes2D(half_sizes=[2.5, 2.5]))
1 change: 1 addition & 0 deletions rerun_py/rerun_sdk/rerun/blueprint/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 4 additions & 24 deletions rerun_py/rerun_sdk/rerun/blueprint/archetypes/visual_bounds.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions rerun_py/rerun_sdk/rerun/blueprint/archetypes/visual_bounds_ext.py
@@ -0,0 +1,35 @@
from __future__ import annotations

from typing import Any

from ... import components, datatypes
from ...error_utils import catch_and_log_exceptions


class VisualBoundsExt:
"""Extension for [VisualBounds][rerun.blueprint.archetypes.VisualBounds]."""

def __init__(
self: Any,
*,
min: datatypes.Vec2DLike,
max: datatypes.Vec2DLike,
):
"""
Create a new instance of the VisualBounds archetype.
Parameters
----------
min:
The minimum point of the visible parts of a 2D space view, in the coordinate space of the scene.
Usually the left-top corner.
max:
The maximum point of the visible parts of a 2D space view, in the coordinate space of the scene.
Usually the right-bottom corner.
"""

with catch_and_log_exceptions(context=self.__class__.__name__):
self.__attrs_init__(visual_bounds=components.AABB2D(min=min, max=max))
return
self.__attrs_clear__()
5 changes: 3 additions & 2 deletions rerun_py/rerun_sdk/rerun/components/aabb2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions rerun_py/rerun_sdk/rerun/components/aabb2d_ext.py
@@ -0,0 +1,31 @@
from __future__ import annotations

from typing import Any

from ..datatypes import AABB2D, Vec2DLike


class AABB2DExt:
"""Extension for [AABB2D][rerun.blueprint.components.AABB2D]."""

def __init__(
self: Any,
*,
min: Vec2DLike,
max: Vec2DLike,
):
"""
Create a new instance of the AABB2D component.
Parameters
----------
min:
The minimum point of the visible parts of a 2D space view, in the coordinate space of the scene.
Usually the left-top corner.
max:
The maximum point of the visible parts of a 2D space view, in the coordinate space of the scene.
Usually the right-bottom corner.
"""

self.__attrs_init__(AABB2D(min=min, max=max))
21 changes: 4 additions & 17 deletions rerun_py/rerun_sdk/rerun/datatypes/aabb2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions rerun_py/rerun_sdk/rerun/datatypes/aabb2d_ext.py
@@ -0,0 +1,34 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any

import numpy as np

if TYPE_CHECKING:
from . import Vec2DLike


class AABB2DExt:
"""Extension for [AABB2D][rerun.blueprint.datatypes.AABB2D]."""

def __init__(
self: Any,
min: Vec2DLike,
max: Vec2DLike,
):
"""
Create a new instance of the AABB2D datatype.
Parameters
----------
min:
The minimum point of the visible parts of a 2D space view, in the coordinate space of the scene.
Usually the left-top corner.
max:
The maximum point of the visible parts of a 2D space view, in the coordinate space of the scene.
Usually the right-bottom corner.
"""

self.min_xy = np.array(min, np.float64)
self.max_xy = np.array(max, np.float64)

0 comments on commit 18bc9f6

Please sign in to comment.