File size: 3,940 Bytes
9ff4bea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs
# Based on "crates/build/re_type_definitions/rerun/encodings/annotation_info.def.rs".

# You can extend this class by creating a "AnnotationInfoExt" class in "annotation_info_ext.py".

from __future__ import annotations

from collections.abc import Sequence
from typing import TYPE_CHECKING, Any

import pyarrow as pa
from attrs import define, field

from .. import encodings
from .._baseclasses import (
    BaseBatch,
)
from .annotation_info_ext import AnnotationInfoExt

__all__ = ["AnnotationInfo", "AnnotationInfoArrayLike", "AnnotationInfoBatch", "AnnotationInfoLike"]


def _annotation_info__label__special_field_converter_override(x: encodings.Utf8Like | None) -> encodings.Utf8 | None:
    if x is None:
        return None
    elif isinstance(x, encodings.Utf8):
        return x
    else:
        return encodings.Utf8(x)


def _annotation_info__color__special_field_converter_override(
    x: encodings.Rgba32Like | None,
) -> encodings.Rgba32 | None:
    if x is None:
        return None
    elif isinstance(x, encodings.Rgba32):
        return x
    else:
        return encodings.Rgba32(x)


@define(init=False)
class AnnotationInfo(AnnotationInfoExt):
    """
    **Encoding**: Annotation info annotating a class id or key-point id.

    Color and label will be used to annotate entities/keypoints which reference the id.
    The id refers either to a class or key-point id
    """

    def __init__(
        self: Any, id: int, label: encodings.Utf8Like | None = None, color: encodings.Rgba32Like | None = None
    ) -> None:
        """
        Create a new instance of the AnnotationInfo encoding.

        Parameters
        ----------
        id:
            [`encodings.ClassId`][rerun.encodings.ClassId] or [`encodings.KeypointId`][rerun.encodings.KeypointId] to which this annotation info belongs.
        label:
            The label that will be shown in the UI.
        color:
            The color that will be applied to the annotated entity.

        """

        # You can define your own __init__ function as a member of AnnotationInfoExt in annotation_info_ext.py
        self.__attrs_init__(id=id, label=label, color=color)

    id: int = field(converter=int)
    # [`encodings.ClassId`][rerun.encodings.ClassId] or [`encodings.KeypointId`][rerun.encodings.KeypointId] to which this annotation info belongs.
    #
    # (Docstring intentionally commented out to hide this field from the docs)

    label: encodings.Utf8 | None = field(
        default=None, converter=_annotation_info__label__special_field_converter_override
    )
    # The label that will be shown in the UI.
    #
    # (Docstring intentionally commented out to hide this field from the docs)

    color: encodings.Rgba32 | None = field(
        default=None, converter=_annotation_info__color__special_field_converter_override
    )
    # The color that will be applied to the annotated entity.
    #
    # (Docstring intentionally commented out to hide this field from the docs)


if TYPE_CHECKING:
    AnnotationInfoLike = AnnotationInfo | int | tuple[int, str] | tuple[int, str, encodings.Rgba32Like]
    """A type alias for any AnnotationInfo-like object."""
else:
    AnnotationInfoLike = Any

AnnotationInfoArrayLike = AnnotationInfo | Sequence[AnnotationInfoLike]
"""A type alias for any AnnotationInfo-like array object."""


class AnnotationInfoBatch(BaseBatch[AnnotationInfoArrayLike]):
    _ARROW_DATATYPE = pa.struct([
        pa.field("id", pa.uint16(), nullable=False, metadata={}),
        pa.field("label", pa.utf8(), nullable=True, metadata={}),
        pa.field("color", pa.uint32(), nullable=True, metadata={}),
    ])

    @staticmethod
    def _native_to_pa_array(data: AnnotationInfoArrayLike, data_type: pa.DataType) -> pa.Array:
        return AnnotationInfoExt.native_to_pa_array_override(data, data_type)