Compose candidate map area.
262 {
265
268 unsigned int filter_size_x = filter_x_;
269 unsigned int filter_size_y = filter_y_;
270
271
272 Eigen::Vector2d coord2d = left_top_coord2d;
273 coord2d[0] -= map_pixel_resolution * static_cast<float>(filter_size_x / 2);
274 coord2d[1] -= map_pixel_resolution * static_cast<float>(filter_size_y / 2);
275
276
282 unsigned int map_coord_x = 0;
283 unsigned int map_coord_y = 0;
284 map_node_lt->GetCoordinate(coord2d, &map_coord_x, &map_coord_y);
285
286 std::vector<std::vector<int>> map_nodes_zones;
287
288 int top_left_start_x = static_cast<int>(map_coord_x);
289 int top_left_start_y = static_cast<int>(map_coord_y);
290 int top_left_end_x = static_cast<int>(map_node_size_x) - 1;
291 int top_left_end_y = static_cast<int>(map_node_size_y) - 1;
292 std::vector<int> node_zone;
293 node_zone.push_back(top_left_start_x);
294 node_zone.push_back(top_left_start_y);
295 node_zone.push_back(top_left_end_x);
296 node_zone.push_back(top_left_end_y);
297 map_nodes_zones.push_back(node_zone);
298
299 int top_center_start_x = 0;
300 int top_center_start_y = top_left_start_y;
301 int top_center_end_x = static_cast<int>(map_coord_x) - 1 +
302 2 * static_cast<int>(filter_size_x / 2);
303 top_center_end_x = top_center_end_x > static_cast<int>(map_node_size_x) - 1
304 ? static_cast<int>(map_node_size_x) - 1
305 : top_center_end_x;
306 int top_center_end_y = static_cast<int>(map_node_size_y) - 1;
307 node_zone.clear();
308 node_zone.push_back(top_center_start_x);
309 node_zone.push_back(top_center_start_y);
310 node_zone.push_back(top_center_end_x);
311 node_zone.push_back(top_center_end_y);
312 map_nodes_zones.push_back(node_zone);
313
314 int top_right_start_x = 0;
315 int top_right_start_y = top_left_start_y;
316 int top_right_end_x = 2 * static_cast<int>(filter_size_x / 2) -
317 (top_left_end_x - top_left_start_x + 1) - 1;
318 int top_right_end_y = static_cast<int>(map_node_size_y) - 1;
319 node_zone.clear();
320 node_zone.push_back(top_right_start_x);
321 node_zone.push_back(top_right_start_y);
322 node_zone.push_back(top_right_end_x);
323 node_zone.push_back(top_right_end_y);
324 map_nodes_zones.push_back(node_zone);
325
326 int middle_left_start_x = top_left_start_x;
327 int middle_left_start_y = 0;
328 int middle_left_end_x = top_left_end_x;
329 int middle_left_end_y = static_cast<int>(map_coord_y) - 1 +
330 2 * static_cast<int>(filter_size_y / 2);
331 middle_left_end_y = middle_left_end_y > static_cast<int>(map_node_size_y) - 1
332 ? static_cast<int>(map_node_size_y) - 1
333 : middle_left_end_y;
334 node_zone.clear();
335 node_zone.push_back(middle_left_start_x);
336 node_zone.push_back(middle_left_start_y);
337 node_zone.push_back(middle_left_end_x);
338 node_zone.push_back(middle_left_end_y);
339 map_nodes_zones.push_back(node_zone);
340
341 int middle_center_start_x = 0;
342 int middle_center_start_y = 0;
343 int middle_center_end_x = top_center_end_x;
344 int middle_center_end_y = middle_left_end_y;
345 node_zone.clear();
346 node_zone.push_back(middle_center_start_x);
347 node_zone.push_back(middle_center_start_y);
348 node_zone.push_back(middle_center_end_x);
349 node_zone.push_back(middle_center_end_y);
350 map_nodes_zones.push_back(node_zone);
351
352 int middle_right_start_x = 0;
353 int middle_right_start_y = 0;
354 int middle_right_end_x = top_right_end_x;
355 int middle_right_end_y = middle_center_end_y;
356 node_zone.clear();
357 node_zone.push_back(middle_right_start_x);
358 node_zone.push_back(middle_right_start_y);
359 node_zone.push_back(middle_right_end_x);
360 node_zone.push_back(middle_right_end_y);
361 map_nodes_zones.push_back(node_zone);
362
363 int bottom_left_start_x = top_left_start_x;
364 int bottom_left_start_y = 0;
365 int bottom_left_end_x = top_left_end_x;
366 int bottom_left_end_y = 2 * static_cast<int>(filter_size_y / 2) -
367 (top_left_end_y - top_left_start_y + 1) - 1;
368 node_zone.clear();
369 node_zone.push_back(bottom_left_start_x);
370 node_zone.push_back(bottom_left_start_y);
371 node_zone.push_back(bottom_left_end_x);
372 node_zone.push_back(bottom_left_end_y);
373 map_nodes_zones.push_back(node_zone);
374
375 int bottom_center_start_x = middle_center_start_x;
376 int bottom_center_start_y = bottom_left_start_y;
377 int bottom_center_end_x = middle_center_end_x;
378 int bottom_center_end_y = bottom_left_end_y;
379 node_zone.clear();
380 node_zone.push_back(bottom_center_start_x);
381 node_zone.push_back(bottom_center_start_y);
382 node_zone.push_back(bottom_center_end_x);
383 node_zone.push_back(bottom_center_end_y);
384 map_nodes_zones.push_back(node_zone);
385
386 int bottom_right_start_x = middle_right_start_x;
387 int bottom_right_start_y = bottom_left_start_y;
388 int bottom_right_end_x = middle_right_end_x;
389 int bottom_right_end_y = bottom_left_end_y;
390 node_zone.clear();
391 node_zone.push_back(bottom_right_start_x);
392 node_zone.push_back(bottom_right_start_y);
393 node_zone.push_back(bottom_right_end_x);
394 node_zone.push_back(bottom_right_end_y);
395 map_nodes_zones.push_back(node_zone);
396
397 std::vector<int> start_x_indices(3, 0);
398 std::vector<int> start_y_indices(3, 0);
399 start_x_indices[0] = 0;
400 start_x_indices[1] = top_left_end_x - top_left_start_x + 1;
401 start_x_indices[2] =
402 start_x_indices[1] + top_center_end_x - top_center_start_x + 1;
403 start_y_indices[0] = 0;
404 start_y_indices[1] = top_left_end_y - top_left_start_y + 1;
405 start_y_indices[2] =
406 start_y_indices[1] + middle_center_end_y - middle_center_start_y + 1;
407
408 std::vector<std::pair<int, int>> composed_map_indices;
409 for (int y = 0; y < 3; ++y) {
410 for (int x = 0; x < 3; ++x) {
411 composed_map_indices.push_back(
412 std::make_pair(start_x_indices[x], start_y_indices[y]));
413 }
414 }
415
416 Eigen::Vector2d coord2d_center =
417 map_node_lt->GetCoordinate(map_node_size_x / 2, map_node_size_y / 2);
418
419 cell_map_.clear();
420 Eigen::Affine3d transform = inverse_transform.inverse();
421 Eigen::Vector3d R_inv_t = -transform.translation();
422
423 map_left_top_corner_ = Eigen::Vector3d::Zero();
424 map_left_top_corner_.block<2, 1>(0, 0) = map_node_lt->GetLeftTopCorner();
425 map_left_top_corner_ += R_inv_t;
426
427 for (int y = 0; y < 3; ++y) {
428 for (int x = 0; x < 3; ++x) {
429 if (map_nodes_zones[y * 3 + x][2] - map_nodes_zones[y * 3 + x][0] >= 0 &&
430 map_nodes_zones[y * 3 + x][3] - map_nodes_zones[y * 3 + x][1] >= 0) {
431
433 if (x == 0 && y == 0) {
434 map_node_ptr = map_node_lt;
435 } else {
436 Eigen::Vector2d coord2d_xy;
437 coord2d_xy[0] =
438 coord2d_center[0] + static_cast<double>(x * map_node_size_x) *
439 static_cast<double>(map_pixel_resolution);
440 coord2d_xy[1] =
441 coord2d_center[1] + static_cast<double>(y * map_node_size_y) *
442 static_cast<double>(map_pixel_resolution);
443
445 map_.
GetMapConfig(), coord2d_xy, resolution_id, zone_id);
449 map_node_ptr = map_node_xy;
450 }
451
452
454 dynamic_cast<NdtMapMatrix&
>(map_node_ptr->GetMapCellMatrix());
455
456
457 const Eigen::Vector2d& left_top_corner =
458 map_node_ptr->GetLeftTopCorner();
459 double resolution = map_node_ptr->GetMapResolution();
460 double resolution_z = map_node_ptr->GetMapResolutionZ();
461 for (int map_y = map_nodes_zones[y * 3 + x][1];
462 map_y <= map_nodes_zones[y * 3 + x][3]; ++map_y) {
463 for (int map_x = map_nodes_zones[y * 3 + x][0];
464 map_x <= map_nodes_zones[y * 3 + x][2]; ++map_x) {
465 const NdtMapCells& cell_ndt = map_cells.GetMapCell(map_y, map_x);
466 if (cell_ndt.cells_.size() > 0) {
467 for (auto it = cell_ndt.cells_.begin();
468 it != cell_ndt.cells_.end(); ++it) {
469 unsigned int cell_count = it->second.count_;
470 if (cell_count >= 6) {
471 Leaf leaf;
472 leaf.nr_points_ = static_cast<int>(cell_count);
473
474 Eigen::Vector3d eigen_point(Eigen::Vector3d::Zero());
475 eigen_point(0) = left_top_corner[0] + map_x * resolution +
476 it->second.centroid_[0];
477 eigen_point(1) = left_top_corner[1] + map_y * resolution +
478 it->second.centroid_[1];
479 eigen_point(2) =
480 resolution_z * it->first + it->second.centroid_[2];
481 leaf.mean_ = (eigen_point + R_inv_t);
482 if (it->second.is_icov_available_ == 1) {
483 leaf.icov_ = it->second.centroid_icov_.cast<double>();
484 } else {
485 leaf.nr_points_ = -1;
486 }
487
488 cell_map_.push_back(leaf);
489 }
490 }
491 }
492 }
493 }
494 }
495 }
496 }
497
498 timer.
End(
"Compose map cells.");
499}
int64_t End(const std::string &msg)
unsigned int map_node_size_y_
The map node size in pixels.
unsigned int map_node_size_x_
The map node size in pixels.
BaseMapNode * GetMapNodeSafe(const MapNodeIndex &index)
Return the map node, if it's not in the cache, safely load it.
const BaseMapConfig & GetMapConfig() const
Get the map config.
bool IsMapNodeExist(const MapNodeIndex &index)
Check if the map node in the cache.
static MapNodeIndex GetMapNodeIndex(const BaseMapConfig &option, const Eigen::Vector3d &coordinate, unsigned int resolution_id, int zone_id)
Construct a map node index, given a global coordinate, eigen version.
apollo::localization::msf::pyramid_map::NdtMapCells NdtMapCells
apollo::localization::msf::pyramid_map::MapNodeIndex MapNodeIndex
apollo::localization::msf::pyramid_map::NdtMapMatrix NdtMapMatrix
apollo::localization::msf::pyramid_map::NdtMapNode NdtMapNode