File size: 6,055 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# 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/components/annotation_context.def.rs".

# You can extend this class by creating a "AnnotationContextExt" class in "annotation_context_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,
    ComponentBatchMixin,
    ComponentMixin,
)
from .annotation_context_ext import AnnotationContextExt

__all__ = ["AnnotationContext", "AnnotationContextArrayLike", "AnnotationContextBatch", "AnnotationContextLike"]


@define(init=False)
class AnnotationContext(AnnotationContextExt, ComponentMixin):
    """
    **Component**: The annotation context provides additional information on how to display entities.

    Entities can use [`encodings.ClassId`][rerun.encodings.ClassId]s and [`encodings.KeypointId`][rerun.encodings.KeypointId]s to provide annotations, and
    the labels and colors will be looked up in the appropriate
    annotation context. We use the *first* annotation context we find in the
    path-hierarchy when searching up through the ancestors of a given entity
    path.

    ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
    """

    _BATCH_TYPE = None

    def __init__(self: Any, class_map: AnnotationContextLike) -> None:
        """
        Create a new instance of the AnnotationContext component.

        Parameters
        ----------
        class_map:
            List of class descriptions, mapping class indices to class names, colors etc.

        """

        # You can define your own __init__ function as a member of AnnotationContextExt in annotation_context_ext.py
        self.__attrs_init__(class_map=class_map)

    class_map: list[encodings.ClassDescriptionMapElem] = field(
        converter=AnnotationContextExt.class_map__field_converter_override,  # type: ignore[misc]
    )
    # List of class descriptions, mapping class indices to class names, colors etc.
    #
    # (Docstring intentionally commented out to hide this field from the docs)

    def __len__(self) -> int:
        # You can define your own __len__ function as a member of AnnotationContextExt in annotation_context_ext.py
        return len(self.class_map)


if TYPE_CHECKING:
    from .. import encodings

    AnnotationContextLike = (
        AnnotationContext | encodings.ClassDescriptionArrayLike | Sequence[encodings.ClassDescriptionMapElemLike]
    )
    """A type alias for any AnnotationContext-like object."""
else:
    AnnotationContextLike = Any

AnnotationContextArrayLike = AnnotationContext | Sequence[AnnotationContextLike]
"""A type alias for any AnnotationContext-like array object."""


class AnnotationContextBatch(BaseBatch[AnnotationContextArrayLike], ComponentBatchMixin):
    _ARROW_DATATYPE = pa.list_(
        pa.field(
            "item",
            pa.struct([
                pa.field("class_id", pa.uint16(), nullable=False, metadata={}),
                pa.field(
                    "class_description",
                    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={},
                        ),
                    ]),
                    nullable=False,
                    metadata={},
                ),
            ]),
            nullable=False,
            metadata={},
        )
    )
    _COMPONENT_TYPE: str = "rerun.components.AnnotationContext"

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


# This is patched in late to avoid circular dependencies.
AnnotationContext._BATCH_TYPE = AnnotationContextBatch  # type: ignore[assignment]