valetudo-map-parser 0.1.10rc6__py3-none-any.whl → 0.1.11b0__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.
- valetudo_map_parser/__init__.py +8 -10
- valetudo_map_parser/config/drawable.py +91 -329
- valetudo_map_parser/config/drawable_elements.py +0 -2
- valetudo_map_parser/config/rand256_parser.py +162 -44
- valetudo_map_parser/config/shared.py +30 -12
- valetudo_map_parser/config/status_text/status_text.py +1 -0
- valetudo_map_parser/config/types.py +12 -3
- valetudo_map_parser/config/utils.py +44 -136
- valetudo_map_parser/hypfer_draw.py +0 -2
- valetudo_map_parser/hypfer_handler.py +14 -22
- valetudo_map_parser/map_data.py +17 -11
- valetudo_map_parser/rand256_handler.py +79 -53
- valetudo_map_parser/reimg_draw.py +13 -18
- valetudo_map_parser/rooms_handler.py +10 -10
- {valetudo_map_parser-0.1.10rc6.dist-info → valetudo_map_parser-0.1.11b0.dist-info}/METADATA +2 -2
- valetudo_map_parser-0.1.11b0.dist-info/RECORD +32 -0
- valetudo_map_parser/config/auto_crop.py +0 -452
- valetudo_map_parser/config/color_utils.py +0 -105
- valetudo_map_parser/config/enhanced_drawable.py +0 -324
- valetudo_map_parser/hypfer_rooms_handler.py +0 -599
- valetudo_map_parser-0.1.10rc6.dist-info/RECORD +0 -36
- {valetudo_map_parser-0.1.10rc6.dist-info → valetudo_map_parser-0.1.11b0.dist-info}/WHEEL +0 -0
- {valetudo_map_parser-0.1.10rc6.dist-info → valetudo_map_parser-0.1.11b0.dist-info}/licenses/LICENSE +0 -0
- {valetudo_map_parser-0.1.10rc6.dist-info → valetudo_map_parser-0.1.11b0.dist-info}/licenses/NOTICE.txt +0 -0
@@ -1,324 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Enhanced Drawable Class.
|
3
|
-
Provides drawing utilities with element selection support.
|
4
|
-
Version: 0.1.9
|
5
|
-
"""
|
6
|
-
|
7
|
-
from __future__ import annotations
|
8
|
-
|
9
|
-
import logging
|
10
|
-
|
11
|
-
# math is not used in this file
|
12
|
-
from typing import Optional, Tuple
|
13
|
-
|
14
|
-
import numpy as np
|
15
|
-
|
16
|
-
from .colors import ColorsManagement
|
17
|
-
from .drawable import Drawable
|
18
|
-
from .drawable_elements import (
|
19
|
-
DrawableElement,
|
20
|
-
DrawingConfig,
|
21
|
-
)
|
22
|
-
|
23
|
-
|
24
|
-
# Type aliases
|
25
|
-
NumpyArray = np.ndarray
|
26
|
-
Color = Tuple[int, int, int, int]
|
27
|
-
|
28
|
-
_LOGGER = logging.getLogger(__name__)
|
29
|
-
|
30
|
-
|
31
|
-
class EnhancedDrawable(Drawable):
|
32
|
-
"""Enhanced drawing utilities with element selection support."""
|
33
|
-
|
34
|
-
def __init__(self, drawing_config: Optional[DrawingConfig] = None):
|
35
|
-
"""Initialize with optional drawing configuration."""
|
36
|
-
super().__init__()
|
37
|
-
self.drawing_config = drawing_config or DrawingConfig()
|
38
|
-
|
39
|
-
# Color blending methods have been moved to ColorsManagement class in colors.py
|
40
|
-
|
41
|
-
# Pixel blending methods have been moved to ColorsManagement class in colors.py
|
42
|
-
|
43
|
-
async def draw_map(
|
44
|
-
self, map_data: dict, base_array: Optional[NumpyArray] = None
|
45
|
-
) -> NumpyArray:
|
46
|
-
"""
|
47
|
-
Draw the map with selected elements.
|
48
|
-
|
49
|
-
Args:
|
50
|
-
map_data: The map data dictionary
|
51
|
-
base_array: Optional base array to draw on
|
52
|
-
|
53
|
-
Returns:
|
54
|
-
The image array with all elements drawn
|
55
|
-
"""
|
56
|
-
# Get map dimensions
|
57
|
-
size_x = map_data.get("size", {}).get("x", 1024)
|
58
|
-
size_y = map_data.get("size", {}).get("y", 1024)
|
59
|
-
|
60
|
-
# Create empty image if none provided
|
61
|
-
if base_array is None:
|
62
|
-
background_color = self.drawing_config.get_property(
|
63
|
-
DrawableElement.FLOOR, "color", (200, 200, 200, 255)
|
64
|
-
)
|
65
|
-
base_array = await self.create_empty_image(size_x, size_y, background_color)
|
66
|
-
|
67
|
-
# Draw elements in order of z-index
|
68
|
-
for element in self.drawing_config.get_drawing_order():
|
69
|
-
if element == DrawableElement.FLOOR:
|
70
|
-
base_array = await self._draw_floor(map_data, base_array)
|
71
|
-
elif element == DrawableElement.WALL:
|
72
|
-
base_array = await self._draw_walls(map_data, base_array)
|
73
|
-
elif element == DrawableElement.ROBOT:
|
74
|
-
base_array = await self._draw_robot(map_data, base_array)
|
75
|
-
elif element == DrawableElement.CHARGER:
|
76
|
-
base_array = await self._draw_charger(map_data, base_array)
|
77
|
-
elif element == DrawableElement.VIRTUAL_WALL:
|
78
|
-
base_array = await self._draw_virtual_walls(map_data, base_array)
|
79
|
-
elif element == DrawableElement.RESTRICTED_AREA:
|
80
|
-
base_array = await self._draw_restricted_areas(map_data, base_array)
|
81
|
-
elif element == DrawableElement.NO_MOP_AREA:
|
82
|
-
base_array = await self._draw_no_mop_areas(map_data, base_array)
|
83
|
-
elif element == DrawableElement.PATH:
|
84
|
-
base_array = await self._draw_path(map_data, base_array)
|
85
|
-
elif element == DrawableElement.PREDICTED_PATH:
|
86
|
-
base_array = await self._draw_predicted_path(map_data, base_array)
|
87
|
-
elif element == DrawableElement.GO_TO_TARGET:
|
88
|
-
base_array = await self._draw_go_to_target(map_data, base_array)
|
89
|
-
elif DrawableElement.ROOM_1 <= element <= DrawableElement.ROOM_15:
|
90
|
-
room_id = element - DrawableElement.ROOM_1 + 1
|
91
|
-
base_array = await self._draw_room(map_data, room_id, base_array)
|
92
|
-
|
93
|
-
return base_array
|
94
|
-
|
95
|
-
async def _draw_floor(self, map_data: dict, array: NumpyArray) -> NumpyArray:
|
96
|
-
"""Draw the floor layer."""
|
97
|
-
if not self.drawing_config.is_enabled(DrawableElement.FLOOR):
|
98
|
-
return array
|
99
|
-
|
100
|
-
# Implementation depends on the map data format
|
101
|
-
# This is a placeholder - actual implementation would use map_data to draw floor
|
102
|
-
|
103
|
-
return array
|
104
|
-
|
105
|
-
async def _draw_walls(self, map_data: dict, array: NumpyArray) -> NumpyArray:
|
106
|
-
"""Draw the walls."""
|
107
|
-
if not self.drawing_config.is_enabled(DrawableElement.WALL):
|
108
|
-
return array
|
109
|
-
|
110
|
-
# Get wall color from drawing config
|
111
|
-
wall_color = self.drawing_config.get_property(
|
112
|
-
DrawableElement.WALL, "color", (255, 255, 0, 255)
|
113
|
-
)
|
114
|
-
|
115
|
-
# Implementation depends on the map data format
|
116
|
-
# For Valetudo maps, we would look at the layers with type "wall"
|
117
|
-
# This is a simplified example - in a real implementation, we would extract the actual wall pixels
|
118
|
-
|
119
|
-
# Find wall data in map_data
|
120
|
-
wall_pixels = []
|
121
|
-
for layer in map_data.get("layers", []):
|
122
|
-
if layer.get("type") == "wall":
|
123
|
-
# Extract wall pixels from the layer
|
124
|
-
# This is a placeholder - actual implementation would depend on the map data format
|
125
|
-
wall_pixels = layer.get("pixels", [])
|
126
|
-
break
|
127
|
-
|
128
|
-
# Draw wall pixels with color blending
|
129
|
-
for x, y in wall_pixels:
|
130
|
-
# Use sample_and_blend_color from ColorsManagement
|
131
|
-
blended_color = ColorsManagement.sample_and_blend_color(
|
132
|
-
array, x, y, wall_color
|
133
|
-
)
|
134
|
-
if 0 <= y < array.shape[0] and 0 <= x < array.shape[1]:
|
135
|
-
array[y, x] = blended_color
|
136
|
-
|
137
|
-
return array
|
138
|
-
|
139
|
-
async def _draw_robot(self, map_data: dict, array: NumpyArray) -> NumpyArray:
|
140
|
-
"""Draw the robot."""
|
141
|
-
if not self.drawing_config.is_enabled(DrawableElement.ROBOT):
|
142
|
-
return array
|
143
|
-
|
144
|
-
# Get robot color from drawing config
|
145
|
-
robot_color = self.drawing_config.get_property(
|
146
|
-
DrawableElement.ROBOT, "color", (255, 255, 204, 255)
|
147
|
-
)
|
148
|
-
|
149
|
-
# Extract robot position and angle from map_data
|
150
|
-
robot_position = map_data.get("robot", {}).get("position", None)
|
151
|
-
robot_angle = map_data.get("robot", {}).get("angle", 0)
|
152
|
-
|
153
|
-
if robot_position:
|
154
|
-
x, y = robot_position.get("x", 0), robot_position.get("y", 0)
|
155
|
-
|
156
|
-
# Draw robot with color blending
|
157
|
-
# Create a circle around the robot position
|
158
|
-
radius = 25 # Same as in the robot drawing method
|
159
|
-
for dy in range(-radius, radius + 1):
|
160
|
-
for dx in range(-radius, radius + 1):
|
161
|
-
if dx * dx + dy * dy <= radius * radius:
|
162
|
-
map_x, map_y = int(x + dx), int(y + dy)
|
163
|
-
# Use sample_and_blend_color from ColorsManagement
|
164
|
-
blended_color = ColorsManagement.sample_and_blend_color(
|
165
|
-
array, map_x, map_y, robot_color
|
166
|
-
)
|
167
|
-
if 0 <= map_y < array.shape[0] and 0 <= map_x < array.shape[1]:
|
168
|
-
array[map_y, map_x] = blended_color
|
169
|
-
return array
|
170
|
-
|
171
|
-
async def _draw_charger(self, map_data: dict, array: NumpyArray) -> NumpyArray:
|
172
|
-
"""Draw the charger."""
|
173
|
-
if not self.drawing_config.is_enabled(DrawableElement.CHARGER):
|
174
|
-
return array
|
175
|
-
|
176
|
-
# Get charger color from drawing config
|
177
|
-
charger_color = self.drawing_config.get_property(
|
178
|
-
DrawableElement.CHARGER, "color", (255, 128, 0, 255)
|
179
|
-
)
|
180
|
-
|
181
|
-
# Implementation depends on the map data format
|
182
|
-
# This would extract charger data from map_data and draw it
|
183
|
-
|
184
|
-
return array
|
185
|
-
|
186
|
-
async def _draw_virtual_walls(
|
187
|
-
self, map_data: dict, array: NumpyArray
|
188
|
-
) -> NumpyArray:
|
189
|
-
"""Draw virtual walls."""
|
190
|
-
if not self.drawing_config.is_enabled(DrawableElement.VIRTUAL_WALL):
|
191
|
-
return array
|
192
|
-
|
193
|
-
# Get virtual wall color from drawing config
|
194
|
-
wall_color = self.drawing_config.get_property(
|
195
|
-
DrawableElement.VIRTUAL_WALL, "color", (255, 0, 0, 255)
|
196
|
-
)
|
197
|
-
|
198
|
-
# Implementation depends on the map data format
|
199
|
-
# This would extract virtual wall data from map_data and draw it
|
200
|
-
|
201
|
-
return array
|
202
|
-
|
203
|
-
async def _draw_restricted_areas(
|
204
|
-
self, map_data: dict, array: NumpyArray
|
205
|
-
) -> NumpyArray:
|
206
|
-
"""Draw restricted areas."""
|
207
|
-
if not self.drawing_config.is_enabled(DrawableElement.RESTRICTED_AREA):
|
208
|
-
return array
|
209
|
-
|
210
|
-
# Get restricted area color from drawing config
|
211
|
-
area_color = self.drawing_config.get_property(
|
212
|
-
DrawableElement.RESTRICTED_AREA, "color", (255, 0, 0, 125)
|
213
|
-
)
|
214
|
-
|
215
|
-
# Implementation depends on the map data format
|
216
|
-
# This would extract restricted area data from map_data and draw it
|
217
|
-
|
218
|
-
return array
|
219
|
-
|
220
|
-
async def _draw_no_mop_areas(self, map_data: dict, array: NumpyArray) -> NumpyArray:
|
221
|
-
"""Draw no-mop areas."""
|
222
|
-
if not self.drawing_config.is_enabled(DrawableElement.NO_MOP_AREA):
|
223
|
-
return array
|
224
|
-
|
225
|
-
# Get no-mop area color from drawing config
|
226
|
-
area_color = self.drawing_config.get_property(
|
227
|
-
DrawableElement.NO_MOP_AREA, "color", (0, 0, 255, 125)
|
228
|
-
)
|
229
|
-
|
230
|
-
# Implementation depends on the map data format
|
231
|
-
# This would extract no-mop area data from map_data and draw it
|
232
|
-
|
233
|
-
return array
|
234
|
-
|
235
|
-
async def _draw_path(self, map_data: dict, array: NumpyArray) -> NumpyArray:
|
236
|
-
"""Draw the robot's path."""
|
237
|
-
if not self.drawing_config.is_enabled(DrawableElement.PATH):
|
238
|
-
return array
|
239
|
-
|
240
|
-
# Get path color from drawing config
|
241
|
-
path_color = self.drawing_config.get_property(
|
242
|
-
DrawableElement.PATH, "color", (238, 247, 255, 255)
|
243
|
-
)
|
244
|
-
|
245
|
-
# Implementation depends on the map data format
|
246
|
-
# This would extract path data from map_data and draw it
|
247
|
-
|
248
|
-
return array
|
249
|
-
|
250
|
-
async def _draw_predicted_path(
|
251
|
-
self, map_data: dict, array: NumpyArray
|
252
|
-
) -> NumpyArray:
|
253
|
-
"""Draw the predicted path."""
|
254
|
-
if not self.drawing_config.is_enabled(DrawableElement.PREDICTED_PATH):
|
255
|
-
return array
|
256
|
-
|
257
|
-
# Get predicted path color from drawing config
|
258
|
-
path_color = self.drawing_config.get_property(
|
259
|
-
DrawableElement.PREDICTED_PATH, "color", (238, 247, 255, 125)
|
260
|
-
)
|
261
|
-
|
262
|
-
# Implementation depends on the map data format
|
263
|
-
# This would extract predicted path data from map_data and draw it
|
264
|
-
|
265
|
-
return array
|
266
|
-
|
267
|
-
async def _draw_go_to_target(self, map_data: dict, array: NumpyArray) -> NumpyArray:
|
268
|
-
"""Draw the go-to target."""
|
269
|
-
if not self.drawing_config.is_enabled(DrawableElement.GO_TO_TARGET):
|
270
|
-
return array
|
271
|
-
|
272
|
-
# Get go-to target color from drawing config
|
273
|
-
target_color = self.drawing_config.get_property(
|
274
|
-
DrawableElement.GO_TO_TARGET, "color", (0, 255, 0, 255)
|
275
|
-
)
|
276
|
-
|
277
|
-
# Implementation depends on the map data format
|
278
|
-
# This would extract go-to target data from map_data and draw it
|
279
|
-
|
280
|
-
return array
|
281
|
-
|
282
|
-
async def _draw_room(
|
283
|
-
self, map_data: dict, room_id: int, array: NumpyArray
|
284
|
-
) -> NumpyArray:
|
285
|
-
"""Draw a specific room."""
|
286
|
-
element = getattr(DrawableElement, f"ROOM_{room_id}")
|
287
|
-
if not self.drawing_config.is_enabled(element):
|
288
|
-
return array
|
289
|
-
|
290
|
-
# Get room color from drawing config
|
291
|
-
room_color = self.drawing_config.get_property(
|
292
|
-
element,
|
293
|
-
"color",
|
294
|
-
(135, 206, 250, 255), # Default light blue
|
295
|
-
)
|
296
|
-
|
297
|
-
# Implementation depends on the map data format
|
298
|
-
# For Valetudo maps, we would look at the layers with type "segment"
|
299
|
-
# This is a simplified example - in a real implementation, we would extract the actual room pixels
|
300
|
-
|
301
|
-
# Find room data in map_data
|
302
|
-
room_pixels = []
|
303
|
-
for layer in map_data.get("layers", []):
|
304
|
-
if layer.get("type") == "segment" and str(
|
305
|
-
layer.get("metaData", {}).get("segmentId")
|
306
|
-
) == str(room_id):
|
307
|
-
# Extract room pixels from the layer
|
308
|
-
# This is a placeholder - actual implementation would depend on the map data format
|
309
|
-
# For example, it might use compressed pixels or other data structures
|
310
|
-
|
311
|
-
# For demonstration, let's assume we have a list of (x, y) coordinates
|
312
|
-
room_pixels = layer.get("pixels", [])
|
313
|
-
break
|
314
|
-
|
315
|
-
# Draw room pixels with color blending
|
316
|
-
for x, y in room_pixels:
|
317
|
-
# Use sample_and_blend_color from ColorsManagement
|
318
|
-
blended_color = ColorsManagement.sample_and_blend_color(
|
319
|
-
array, x, y, room_color
|
320
|
-
)
|
321
|
-
if 0 <= y < array.shape[0] and 0 <= x < array.shape[1]:
|
322
|
-
array[y, x] = blended_color
|
323
|
-
|
324
|
-
return array
|