File size: 1,113 Bytes
1e3ce4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Selectors: WHAT a cursor targets in pixel space.

Hierarchy (each subsumes the previous as a special case):
    Point < Mask < Region < Layer < Anchor3D

Token is orthogonal — semantic rather than spatial; the cross-attention map
of the bound model materializes the spatial extent at op time.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Optional, Tuple, Union

import numpy as np


@dataclass(frozen=True, slots=True)
class Point:
    x: float
    y: float
    z: Optional[float] = None


@dataclass(frozen=True, slots=True)
class Region:
    x: int
    y: int
    w: int
    h: int


@dataclass(frozen=True, slots=True, eq=False)
class Mask:
    bitmap: np.ndarray
    is_soft: bool = False


@dataclass(frozen=True, slots=True)
class Token:
    text: str
    embedding_id: Optional[str] = None


@dataclass(frozen=True, slots=True)
class Layer:
    layer_id: str


@dataclass(frozen=True, slots=True)
class Anchor3D:
    anchor_id: str
    bbox: Tuple[float, float, float, float, float, float]


Selector = Union[Point, Region, Mask, Token, Layer, Anchor3D]