supervisely 6.73.281__py3-none-any.whl → 6.73.282__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of supervisely might be problematic. Click here for more details.

@@ -8,6 +8,13 @@ from typing import Dict, List, Optional, Union
8
8
 
9
9
  import numpy as np
10
10
 
11
+ from supervisely.geometry.constants import (
12
+ CLASS_ID,
13
+ CREATED_AT,
14
+ ID,
15
+ LABELER_LOGIN,
16
+ UPDATED_AT,
17
+ )
11
18
  from supervisely.geometry.geometry import Geometry
12
19
  from supervisely.geometry.graph import EDGES, GraphNodes, Node, _maybe_transform_colors
13
20
  from supervisely.geometry.point_location import PointLocation
@@ -36,19 +43,19 @@ CUBOID2D_EDGES_MAPPING = [
36
43
 
37
44
  class Cuboid2d(GraphNodes):
38
45
  """
39
- GraphNodes geometry for a single :class:`Label<supervisely.annotation.label.Label>`. :class:`GraphNodes<GraphNodes>` class object is immutable.
46
+ Cuboid2d geometry for a single :class:`Label<supervisely.annotation.label.Label>`. :class:`Cuboid2d<Cuboid2d>` class object is immutable.
40
47
 
41
48
  :param nodes: Dict or List containing nodes of graph
42
49
  :type nodes: dict
43
- :param sly_id: GraphNodes ID in Supervisely server.
50
+ :param sly_id: Cuboid2d ID in Supervisely server.
44
51
  :type sly_id: int, optional
45
- :param class_id: ID of :class:`ObjClass<supervisely.annotation.obj_class.ObjClass>` to which GraphNodes belongs.
52
+ :param class_id: ID of :class:`ObjClass<supervisely.annotation.obj_class.ObjClass>` to which Cuboid2d belongs.
46
53
  :type class_id: int, optional
47
- :param labeler_login: Login of the user who created GraphNodes.
54
+ :param labeler_login: Login of the user who created Cuboid2d.
48
55
  :type labeler_login: str, optional
49
- :param updated_at: Date and Time when GraphNodes was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: '2021-01-22T19:37:50.158Z'.
56
+ :param updated_at: Date and Time when Cuboid2d was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: '2021-01-22T19:37:50.158Z'.
50
57
  :type updated_at: str, optional
51
- :param created_at: Date and Time when GraphNodes was created. Date Format is the same as in "updated_at" parameter.
58
+ :param created_at: Date and Time when Cuboid2d was created. Date Format is the same as in "updated_at" parameter.
52
59
  :type created_at: str, optional
53
60
 
54
61
  :Usage example:
@@ -56,13 +63,13 @@ class Cuboid2d(GraphNodes):
56
63
  .. code-block:: python
57
64
 
58
65
  import supervisely as sly
59
- from supervisely.geometry.graph import Node, GraphNodes
66
+ from supervisely.geometry.graph import Node, Cuboid2d
60
67
 
61
68
  vertex_1 = Node(sly.PointLocation(5, 5))
62
69
  vertex_2 = Node(sly.PointLocation(100, 100))
63
70
  vertex_3 = Node(sly.PointLocation(200, 250))
64
71
  nodes = {0: vertex_1, 1: vertex_2, 2: vertex_3}
65
- figure = GraphNodes(nodes)
72
+ figure = Cuboid2d(nodes)
66
73
  """
67
74
 
68
75
  items_json_field = VERTICES
@@ -79,6 +86,9 @@ class Cuboid2d(GraphNodes):
79
86
  labeler_login: Optional[int] = None,
80
87
  updated_at: Optional[str] = None,
81
88
  created_at: Optional[str] = None,
89
+ position: Optional[Dict] = None,
90
+ rotation: Optional[Dict] = None,
91
+ dimensions: Optional[Dict] = None,
82
92
  ):
83
93
  super().__init__(
84
94
  nodes=nodes,
@@ -88,6 +98,9 @@ class Cuboid2d(GraphNodes):
88
98
  updated_at=updated_at,
89
99
  created_at=created_at,
90
100
  )
101
+ self._position = position
102
+ self._rotation = rotation
103
+ self._dimensions = dimensions
91
104
 
92
105
  if len(self._nodes) != 8:
93
106
  raise ValueError("Cuboid2d must have exactly 8 vertices")
@@ -98,10 +111,169 @@ class Cuboid2d(GraphNodes):
98
111
  Copy of Cuboid2d vertices.
99
112
 
100
113
  :return: Cuboid2d vertices
101
- :rtype: :class:`dict`
114
+ :rtype: Optional[Dict]
102
115
  """
103
116
  return self.nodes
104
117
 
118
+ @property
119
+ def position(self) -> Optional[Dict]:
120
+ """
121
+ Copy of the position of the Cuboid2d.
122
+
123
+ :return: Position of the Cuboid2d
124
+ :rtype: Optional[Dict]
125
+ """
126
+ if isinstance(self._position, dict):
127
+ return self._position.copy()
128
+
129
+ @property
130
+ def rotation(self) -> Optional[Dict]:
131
+ """
132
+ Copy of the rotation of the Cuboid2d.
133
+
134
+ :return: Rotation of the Cuboid2d
135
+ :rtype: Optional[Dict]
136
+ """
137
+ if isinstance(self._rotation, dict):
138
+ return self._rotation.copy()
139
+
140
+ @property
141
+ def dimensions(self) -> Optional[Dict]:
142
+ """
143
+ Copy of the dimensions of the Cuboid2d.
144
+
145
+ :return: Dimensions of the Cuboid2d
146
+ :rtype: :class:`dict`
147
+ """
148
+ if isinstance(self._dimensions, dict):
149
+ return self._dimensions.copy()
150
+
151
+ @classmethod
152
+ def from_json(cls, data: Dict[str, Dict]) -> Cuboid2d:
153
+ """
154
+ Convert a json dict to Cuboid2d. Read more about `Supervisely format <https://docs.supervise.ly/data-organization/00_ann_format_navi>`_.
155
+
156
+ :param data: Cuboid2d in json format as a dict.
157
+ :type data: Dict[str, Dict]
158
+ :return: Cuboid2d object
159
+ :rtype: :class:`Cuboid2d<Cuboid2d>`
160
+ :Usage example:
161
+
162
+ .. code-block:: python
163
+
164
+ figure_json = {
165
+ "vertices": {
166
+ "0": {
167
+ "loc": [5, 5]
168
+ },
169
+ "1": {
170
+ "loc": [100, 100]
171
+ },
172
+ "2": {
173
+ "loc": [250, 200]
174
+ },
175
+ "position": {
176
+ "x": 0.0657651107620552,
177
+ "y": -0.05634319555373257,
178
+ "z": 0.7267282757573887
179
+ },
180
+ "rotation": { "x": 0, "y": 0, "z": 0 },
181
+ "dimensions": {
182
+ "x": 0.1425456564648202,
183
+ "y": 0.1,
184
+ "z": 0.36738880874660756
185
+ }
186
+ }
187
+ }
188
+ from supervisely.geometry.graph import Cuboid2d
189
+ figure = Cuboid2d.from_json(figure_json)
190
+ """
191
+ nodes = {
192
+ node_id: Node.from_json(node_json)
193
+ for node_id, node_json in data[cls.items_json_field].items()
194
+ }
195
+ labeler_login = data.get(LABELER_LOGIN, None)
196
+ updated_at = data.get(UPDATED_AT, None)
197
+ created_at = data.get(CREATED_AT, None)
198
+ sly_id = data.get(ID, None)
199
+ class_id = data.get(CLASS_ID, None)
200
+ position = data.get("position", None)
201
+ rotation = data.get("rotation", None)
202
+ dimensions = data.get("dimensions", None)
203
+ return cls(
204
+ nodes=nodes,
205
+ sly_id=sly_id,
206
+ class_id=class_id,
207
+ labeler_login=labeler_login,
208
+ updated_at=updated_at,
209
+ created_at=created_at,
210
+ position=position,
211
+ rotation=rotation,
212
+ dimensions=dimensions,
213
+ )
214
+
215
+ def to_json(self) -> Dict[str, Dict]:
216
+ """
217
+ Convert the Cuboid2d to list. Read more about `Supervisely format <https://docs.supervise.ly/data-organization/00_ann_format_navi>`_.
218
+
219
+ :return: Json format as a dict
220
+ :rtype: Dict[str, Dict]
221
+ :Usage example:
222
+
223
+ .. code-block:: python
224
+
225
+ import supervisely as sly
226
+ from supervisely.geometry.graph import Node, Cuboid2d
227
+
228
+ vertex_1 = Node(sly.PointLocation(5, 5))
229
+ vertex_2 = Node(sly.PointLocation(100, 100))
230
+ vertex_3 = Node(sly.PointLocation(200, 250))
231
+ nodes = {0: vertex_1, 1: vertex_2, 2: vertex_3}
232
+ figure = Cuboid2d(nodes)
233
+
234
+ figure_json = figure.to_json()
235
+ print(figure_json)
236
+ # Output: {
237
+ # "nodes": {
238
+ # "0": {
239
+ # "loc": [5, 5]
240
+ # },
241
+ # "1": {
242
+ # "loc": [100, 100]
243
+ # },
244
+ # "2": {
245
+ # "loc": [250, 200]
246
+ # }
247
+ # },
248
+ # "position": {
249
+ # "x": 0.0657651107620552,
250
+ # "y": -0.05634319555373257,
251
+ # "z": 0.7267282757573887
252
+ # },
253
+ # "rotation": { "x": 0, "y": 0, "z": 0 },
254
+ # "dimensions": {
255
+ # "x": 0.1425456564648202,
256
+ # "y": 0.1,
257
+ # "z": 0.36738880874660756
258
+ # }
259
+
260
+ # }
261
+ """
262
+ res = {
263
+ self.items_json_field: {
264
+ node_id: node.to_json() for node_id, node in self._nodes.items()
265
+ }
266
+ }
267
+ if self._position is not None:
268
+ res["position"] = self._position
269
+ if self._rotation is not None:
270
+ res["rotation"] = self._rotation
271
+ if self._dimensions is not None:
272
+ res["dimensions"] = self._dimensions
273
+
274
+ self._add_creation_info(res)
275
+ return res
276
+
105
277
  def validate(self, name: str, settings: Dict) -> None:
106
278
  """
107
279
  Checks the graph for correctness and compliance with the template
@@ -184,7 +356,7 @@ class Cuboid2dTemplate(Cuboid2d, Geometry):
184
356
  """
185
357
  config = {VERTICES: {}, EDGES: []}
186
358
 
187
- x = y = w = h = s = 1 # sample values only for config creation
359
+ x = y = w = h = s = 1 # sample values only for config creation
188
360
  base_vertices = [(x, y), (x + w, y), (x + w, y + h), (x, y + h)]
189
361
  shifted_vertices = [(vx + s, vy + s) for vx, vy in base_vertices]
190
362
  verices_coords = base_vertices + shifted_vertices
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.281
3
+ Version: 6.73.282
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -674,7 +674,7 @@ supervisely/geometry/closed_surface_mesh.py,sha256=3ZplCm3Q2bhPcxNmtv2U1UfdezRkC
674
674
  supervisely/geometry/constants.py,sha256=TPYWGcr2GsbgEtKiZj1L_6wpmbaWU9Qjtlwjg136iVg,788
675
675
  supervisely/geometry/conversions.py,sha256=ZY6xWYFWaDA5KDJkcIBBP8LAmMfZwxMeVFfYUYEM6fw,1170
676
676
  supervisely/geometry/cuboid.py,sha256=oxsRoTKuwTNxH4Vp6khyvw1TCrBagSWNV5HmQKJZHt0,20693
677
- supervisely/geometry/cuboid_2d.py,sha256=tJoaqIAAl1ED-EMu1tEeuMvNi5CIE1rGE0RMLnpkpcg,7933
677
+ supervisely/geometry/cuboid_2d.py,sha256=-oXeKiUS2gguQ4GyIZYp1cNPPhOLsGOFZl7uI71BfZM,13438
678
678
  supervisely/geometry/cuboid_3d.py,sha256=x472ZPHTZDIY5Dj8tKbLQG3BCukFPgSvPJlxfHdKi1w,4168
679
679
  supervisely/geometry/geometry.py,sha256=dbXnct8hrr7Wour6yCrtAef22KSJ2uYRm1F5GE10_MM,15287
680
680
  supervisely/geometry/graph.py,sha256=1_tX7FGmYkXuAx3P_w4zA4p8mRYnCN4iZ--2pMyxseI,24121
@@ -1070,9 +1070,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
1070
1070
  supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
1071
1071
  supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
1072
1072
  supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
1073
- supervisely-6.73.281.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1074
- supervisely-6.73.281.dist-info/METADATA,sha256=24JmJE-D0v4zGZJO-XnHJ3yiFXVK69F_UwSGz0rItEQ,33573
1075
- supervisely-6.73.281.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
1076
- supervisely-6.73.281.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1077
- supervisely-6.73.281.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1078
- supervisely-6.73.281.dist-info/RECORD,,
1073
+ supervisely-6.73.282.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1074
+ supervisely-6.73.282.dist-info/METADATA,sha256=qGp4_zjqrTMz3V40SpkZe9J1yy-1HCAPicbSc5vpeGo,33573
1075
+ supervisely-6.73.282.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
1076
+ supervisely-6.73.282.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1077
+ supervisely-6.73.282.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1078
+ supervisely-6.73.282.dist-info/RECORD,,