File size: 5,174 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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/class_description.def.rs".

# You can extend this class by creating a "ClassDescriptionExt" class in "class_description_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 .._baseclasses import (
    BaseBatch,
)
from .class_description_ext import ClassDescriptionExt

__all__ = ["ClassDescription", "ClassDescriptionArrayLike", "ClassDescriptionBatch", "ClassDescriptionLike"]


@define(init=False)
class ClassDescription(ClassDescriptionExt):
    """
    **Encoding**: The description of a semantic Class.

    If an entity is annotated with a corresponding [`components.ClassId`][rerun.components.ClassId], Rerun will use
    the attached [`encodings.AnnotationInfo`][rerun.encodings.AnnotationInfo] to derive labels and colors.

    Keypoints within an annotation class can similarly be annotated with a
    [`components.KeypointId`][rerun.components.KeypointId] in which case we should defer to the label and color for the
    [`encodings.AnnotationInfo`][rerun.encodings.AnnotationInfo] specifically associated with the Keypoint.

    Keypoints within the class can also be decorated with skeletal edges.
    Keypoint-connections are pairs of [`components.KeypointId`][rerun.components.KeypointId]s. If an edge is
    defined, and both keypoints exist within the instance of the class, then the
    keypoints should be connected with an edge. The edge should be labeled and
    colored as described by the class's [`encodings.AnnotationInfo`][rerun.encodings.AnnotationInfo].

    Note that a `ClassDescription` can be directly logged using `rerun.log`.
    This is equivalent to logging a `rerun.AnnotationContext` containing
    a single `ClassDescription`.
    """

    # __init__ can be found in class_description_ext.py

    info: encodings.AnnotationInfo = field(
        converter=ClassDescriptionExt.info__field_converter_override,  # type: ignore[misc]
    )
    # The [`encodings.AnnotationInfo`][rerun.encodings.AnnotationInfo] for the class.
    #
    # (Docstring intentionally commented out to hide this field from the docs)

    keypoint_annotations: list[encodings.AnnotationInfo] = field(
        converter=ClassDescriptionExt.keypoint_annotations__field_converter_override,  # type: ignore[misc]
    )
    # The [`encodings.AnnotationInfo`][rerun.encodings.AnnotationInfo] for all of the keypoints.
    #
    # (Docstring intentionally commented out to hide this field from the docs)

    keypoint_connections: list[encodings.KeypointPair] = field(
        converter=ClassDescriptionExt.keypoint_connections__field_converter_override,  # type: ignore[misc]
    )
    # The connections between keypoints.
    #
    # (Docstring intentionally commented out to hide this field from the docs)


if TYPE_CHECKING:
    from .. import encodings

    ClassDescriptionLike = ClassDescription | encodings.AnnotationInfoLike
    """A type alias for any ClassDescription-like object."""
else:
    ClassDescriptionLike = Any

ClassDescriptionArrayLike = ClassDescription | Sequence[ClassDescriptionLike]
"""A type alias for any ClassDescription-like array object."""


class ClassDescriptionBatch(BaseBatch[ClassDescriptionArrayLike]):
    _ARROW_DATATYPE = pa.struct([
        pa.field(
            "info",
            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={}),
            ]),
            nullable=False,
            metadata={},
        ),
        pa.field(
            "keypoint_annotations",
            pa.list_(
                pa.field(
                    "item",
                    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={}),
                    ]),
                    nullable=False,
                    metadata={},
                )
            ),
            nullable=False,
            metadata={},
        ),
        pa.field(
            "keypoint_connections",
            pa.list_(
                pa.field(
                    "item",
                    pa.struct([
                        pa.field("keypoint0", pa.uint16(), nullable=False, metadata={}),
                        pa.field("keypoint1", pa.uint16(), nullable=False, metadata={}),
                    ]),
                    nullable=False,
                    metadata={},
                )
            ),
            nullable=False,
            metadata={},
        ),
    ])

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