valetudo-map-parser 0.1.9b56__py3-none-any.whl → 0.1.9b57__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.
@@ -1,148 +0,0 @@
1
- """
2
- Room Outline Extraction Utilities.
3
- Uses scipy for efficient room outline extraction.
4
- Version: 0.1.9
5
- """
6
-
7
- from __future__ import annotations
8
-
9
- import numpy as np
10
- from scipy import ndimage
11
-
12
- from .types import LOGGER
13
-
14
-
15
- async def extract_room_outline_with_scipy(
16
- room_mask, min_x, min_y, max_x, max_y, file_name=None, room_id=None
17
- ):
18
- """Extract a room outline using scipy for contour finding.
19
-
20
- Args:
21
- room_mask: Binary mask of the room (1 for room, 0 for non-room)
22
- min_x, min_y, max_x, max_y: Bounding box coordinates
23
- file_name: Optional file name for logging
24
- room_id: Optional room ID for logging
25
-
26
- Returns:
27
- List of points forming the outline of the room
28
- """
29
- # If the mask is empty, return a rectangular outline
30
- if np.sum(room_mask) == 0:
31
- LOGGER.warning(
32
- "%s: Empty room mask for room %s, using rectangular outline",
33
- file_name or "RoomOutline",
34
- str(room_id) if room_id is not None else "unknown",
35
- )
36
- return [(min_x, min_y), (max_x, min_y), (max_x, max_y), (min_x, max_y)]
37
-
38
- # Use scipy to clean up the mask (remove noise, fill holes)
39
- # Fill small holes
40
- room_mask = ndimage.binary_fill_holes(room_mask).astype(np.uint8)
41
-
42
- # Remove small objects
43
- labeled_array, num_features = ndimage.label(room_mask)
44
- if num_features > 1:
45
- # Find the largest connected component
46
- component_sizes = np.bincount(labeled_array.ravel())[1:]
47
- largest_component = np.argmax(component_sizes) + 1
48
- room_mask = (labeled_array == largest_component).astype(np.uint8)
49
-
50
- # Find the boundary points by tracing the perimeter
51
- boundary_points = []
52
- height, width = room_mask.shape
53
-
54
- # Scan horizontally (top and bottom edges)
55
- for x in range(width):
56
- # Top edge
57
- for y in range(height):
58
- if room_mask[y, x] == 1:
59
- boundary_points.append((x + min_x, y + min_y))
60
- break
61
-
62
- # Bottom edge
63
- for y in range(height - 1, -1, -1):
64
- if room_mask[y, x] == 1:
65
- boundary_points.append((x + min_x, y + min_y))
66
- break
67
-
68
- # Scan vertically (left and right edges)
69
- for y in range(height):
70
- # Left edge
71
- for x in range(width):
72
- if room_mask[y, x] == 1:
73
- boundary_points.append((x + min_x, y + min_y))
74
- break
75
-
76
- # Right edge
77
- for x in range(width - 1, -1, -1):
78
- if room_mask[y, x] == 1:
79
- boundary_points.append((x + min_x, y + min_y))
80
- break
81
-
82
- # Remove duplicates while preserving order
83
- unique_points = []
84
- for point in boundary_points:
85
- if point not in unique_points:
86
- unique_points.append(point)
87
-
88
- # If we have too few points, return a simple rectangle
89
- if len(unique_points) < 4:
90
- LOGGER.warning(
91
- "%s: Too few boundary points for room %s, using rectangular outline",
92
- file_name or "RoomOutline",
93
- str(room_id) if room_id is not None else "unknown",
94
- )
95
- return [(min_x, min_y), (max_x, min_y), (max_x, max_y), (min_x, max_y)]
96
-
97
- # Simplify the outline by keeping only significant points
98
- simplified = simplify_outline(unique_points, tolerance=5)
99
-
100
- LOGGER.debug(
101
- "%s: Extracted outline for room %s with %d points",
102
- file_name or "RoomOutline",
103
- str(room_id) if room_id is not None else "unknown",
104
- len(simplified),
105
- )
106
-
107
- return simplified
108
-
109
-
110
- def simplify_outline(points, tolerance=5):
111
- """Simplify an outline by removing points that don't contribute much to the shape."""
112
- if len(points) <= 4:
113
- return points
114
-
115
- # Start with the first point
116
- simplified = [points[0]]
117
-
118
- # Process remaining points
119
- for i in range(1, len(points) - 1):
120
- # Get previous and next points
121
- prev = simplified[-1]
122
- current = points[i]
123
- next_point = points[i + 1]
124
-
125
- # Calculate vectors
126
- v1 = (current[0] - prev[0], current[1] - prev[1])
127
- v2 = (next_point[0] - current[0], next_point[1] - current[1])
128
-
129
- # Calculate change in direction
130
- dot_product = v1[0] * v2[0] + v1[1] * v2[1]
131
- len_v1 = (v1[0] ** 2 + v1[1] ** 2) ** 0.5
132
- len_v2 = (v2[0] ** 2 + v2[1] ** 2) ** 0.5
133
-
134
- # Avoid division by zero
135
- if len_v1 == 0 or len_v2 == 0:
136
- continue
137
-
138
- # Calculate cosine of angle between vectors
139
- cos_angle = dot_product / (len_v1 * len_v2)
140
-
141
- # If angle is significant or distance is large, keep the point
142
- if abs(cos_angle) < 0.95 or len_v1 > tolerance or len_v2 > tolerance:
143
- simplified.append(current)
144
-
145
- # Add the last point
146
- simplified.append(points[-1])
147
-
148
- return simplified
@@ -1,27 +0,0 @@
1
- valetudo_map_parser/__init__.py,sha256=Fz-gtKf_OlZcDQqVfGlBwIWi5DJAiRucMbBMdQ2tX_U,1060
2
- valetudo_map_parser/config/__init__.py,sha256=DQ9plV3ZF_K25Dp5ZQHPDoG-40dQoJNdNi-dfNeR3Zc,48
3
- valetudo_map_parser/config/auto_crop.py,sha256=6xt_wJQqphddWhlrr7MNUkodCi8ZYdRk42qvAaxlYCM,13546
4
- valetudo_map_parser/config/color_utils.py,sha256=nXD6WeNmdFdoMxPDW-JFpjnxJSaZR1jX-ouNfrx6zvE,4502
5
- valetudo_map_parser/config/colors.py,sha256=DG-oPQoN5gsnwDbEsuFr8a0hRCxmbFHObWa4_5pr-70,29910
6
- valetudo_map_parser/config/drawable.py,sha256=2MeVHXqZuVuJk3eerMJYGwo25rVetHx3xB_vxecEFOQ,34168
7
- valetudo_map_parser/config/drawable_elements.py,sha256=o-5oiXmfqPwNQLzKIhkEcZD_A47rIU9E0CqKgWipxgc,11516
8
- valetudo_map_parser/config/enhanced_drawable.py,sha256=QlGxlUMVgECUXPtFwIslyjubWxQuhIixsRymWV3lEvk,12586
9
- valetudo_map_parser/config/optimized_element_map.py,sha256=52BCnkvVv9bre52LeVIfT8nhnEIpc0TuWTv1xcNu0Rk,15744
10
- valetudo_map_parser/config/rand25_parser.py,sha256=kIayyqVZBfQfAMkiArzqrrj9vqZB3pkgT0Y5ufrQmGA,16448
11
- valetudo_map_parser/config/room_outline.py,sha256=D20D-yeyKnlmVbW9lI7bsPtQGn2XkcWow6YNOEPnWVg,4800
12
- valetudo_map_parser/config/shared.py,sha256=Vr4bicL7aJoRQbwbXyjEpiWhfzZ-cakLlfRqL3LBhpM,10475
13
- valetudo_map_parser/config/types.py,sha256=TaRKoo7G7WIUw7ljOz2Vn5oYzKaLyQH-7Eb8ZYql8Ls,17464
14
- valetudo_map_parser/config/utils.py,sha256=CFuuiS5IufEu9aeaZwi7xa1jEF1z6yDZB0mcyVX79Xo,29261
15
- valetudo_map_parser/hypfer_draw.py,sha256=bwNTYopTJFY0nElrHquQrSfGHgN_-6t5E-8xBxDsRXA,26660
16
- valetudo_map_parser/hypfer_handler.py,sha256=wvkZt6MsUF0gkHZDAwiUgOOawkdvakRzYBV3NtjxuJQ,19938
17
- valetudo_map_parser/hypfer_rooms_handler.py,sha256=NkpOA6Gdq-2D3lLAxvtNuuWMvPXHxeMY2TO5RZLSHlU,22652
18
- valetudo_map_parser/map_data.py,sha256=zQKE8EzWxR0r0qyfD1QQq51T1wFrpcIeXtnpm92-LXQ,17743
19
- valetudo_map_parser/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- valetudo_map_parser/rand25_handler.py,sha256=GpY9R9EGWM06KYF4VQ1NxYw0idaJ8lZNkkA5wa0cr-c,22292
21
- valetudo_map_parser/reimg_draw.py,sha256=1q8LkNTPHEA9Tsapc_JnVw51kpPYNhaBU-KmHkefCQY,12507
22
- valetudo_map_parser/rooms_handler.py,sha256=YP8OLotBH-RXluv398l7TTT2zIBHJp91b8THWxl3NdI,17794
23
- valetudo_map_parser-0.1.9b56.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
24
- valetudo_map_parser-0.1.9b56.dist-info/METADATA,sha256=LJXXb676sSJ9W7NGafpcJSF4CRGGhbg_lCyrzcxkge0,3321
25
- valetudo_map_parser-0.1.9b56.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
26
- valetudo_map_parser-0.1.9b56.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
27
- valetudo_map_parser-0.1.9b56.dist-info/RECORD,,