* _cacheSegmentation * Store the given segmentation in the caches * @param {Object} cache - the cache to use * @param {Object} props - the segmentation properties * @return {Object?} The segmentation data, or `null` if we are skipping it (see below)
(cache, props)
| 1254 | * @return {Object?} The segmentation data, or `null` if we are skipping it (see below) |
| 1255 | */ |
| 1256 | _cacheSegmentation(cache, props) { |
| 1257 | // Note: not all segmentations are ones we can work with. |
| 1258 | // For now, we'll only keep the ones that correspond to the known object detections and traffic_signs. |
| 1259 | const isDetection = this.getDetectionPresetID(props.value); |
| 1260 | const isTrafficSign = /^(regulatory|information|warning|complementary)/.test(props.value); |
| 1261 | if (!isDetection && !isTrafficSign) return null; |
| 1262 | |
| 1263 | let segmentation = cache.data.get(props.id); |
| 1264 | if (!segmentation) { |
| 1265 | // Convert encoded geometry into a polygon.. |
| 1266 | const decodedGeometry = window.atob(props.geometry); |
| 1267 | let arr = new Uint8Array(decodedGeometry.length); |
| 1268 | for (let i = 0; i < decodedGeometry.length; i++) { |
| 1269 | arr[i] = decodedGeometry.charCodeAt(i); |
| 1270 | } |
| 1271 | const tile = new VectorTile(new Protobuf(arr.buffer)); |
| 1272 | const layer = tile.layers['mpy-or']; |
| 1273 | const geometries = layer.feature(0).loadGeometry(); |
| 1274 | const polygon = geometries |
| 1275 | .map(ring => ring.map(point => [point.x / layer.extent, point.y / layer.extent])); |
| 1276 | const geometry = new window.mapillary.PolygonGeometry(polygon[0]); |
| 1277 | |
| 1278 | segmentation = { |
| 1279 | id: props.id, |
| 1280 | imageID: props.imageID, |
| 1281 | geometry: geometry, |
| 1282 | value: props.value |
| 1283 | }; |
| 1284 | |
| 1285 | cache.data.set(segmentation.id, segmentation); |
| 1286 | } |
| 1287 | |
| 1288 | // Update whatever additional props we were passed.. |
| 1289 | if (props.created_at) segmentation.created_at = props.created_at; |
| 1290 | if (props.detectionID) segmentation.detectionID = props.detectionID; |
| 1291 | |
| 1292 | return segmentation; |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | /** |
no test coverage detected