Skip to content

Draft: feat: add mapapi map in data wrapper

This draft pull request presents a proposed solution to bridge the gap between mapapi and gtgenmap for reference lines, logical lanes, and logical lane boundaries. The primary idea is to introduce a unique pointer to map_api::Map within map_api_data_wrapper.h.

Note: This PR is a work in progress. APIs in map_api_data_wrapper will need modifications, and corresponding tests will need updates if these changes are applied.

Motivation: Current Process Issues: Without this proposed solution, converting logical lanes and logical lane boundaries requires moving them into an internal data structure. The LogicalLaneBoundary class in map_api contains:

ReferenceLine* reference_line;
std::vector<RefWrapper<LaneBoundary>> physical_boundaries;

During the move operation, the original reference_line and physical_boundaries pointers become invalid. To resolve this, we refresh the pointer addresses during conversion, as shown below:

// Convert reference lines
for (const auto& reference_line : data_.reference_lines) {
    gtgen_map_.Add(*reference_line);
}

// Convert logical lane boundaries
for (const auto& logical_lane_boundary : data_.logical_lane_boundaries) {
    // Renew the address of reference lines and physical boundaries
    const auto reference_line_id = logical_lane_boundary->reference_line->id;
    logical_lane_boundary->reference_line = &(gtgen_map_.Get<map_api::ReferenceLine>(reference_line_id));
    
    for (size_t i = 0; i < logical_lane_boundary->physical_boundaries.size(); ++i) {
        const auto physical_boundary_id = logical_lane_boundary->physical_boundaries[i].get().id;
        std::cout << "Actual physical_boundary_id: " << physical_boundary_id << std::endl;
        logical_lane_boundary->physical_boundaries[i] = std::ref(gtgen_map_.Get<map_api::LaneBoundary>(physical_boundary_id));
    }

    gtgen_map_.Add(*logical_lane_boundary);
}

However, reassigning these addresses is potentially unsafe.

Proposed Solution: Introducing a std::unique_ptr to map_api::Map will eliminate the need to handle the internal conversion logic manually. It could be considered as a step wise to prepare replacement of GTGenMap uisng MAPAPI.

Edited by Ziqi Zhou

Merge request reports