// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma // de Barcelona (UAB). // // This work is licensed under the terms of the MIT license. // For a copy, see . #include "carla/trafficmanager/CachedSimpleWaypoint.h" namespace carla { namespace traffic_manager { using SimpleWaypointPtr = std::shared_ptr; CachedSimpleWaypoint::CachedSimpleWaypoint(const SimpleWaypointPtr& simple_waypoint) { this->waypoint_id = simple_waypoint->GetId(); this->road_id = simple_waypoint->GetWaypoint()->GetRoadId(); this->section_id = simple_waypoint->GetWaypoint()->GetSectionId(); this->lane_id = simple_waypoint->GetWaypoint()->GetLaneId(); this->s = static_cast(simple_waypoint->GetWaypoint()->GetDistance()); for (auto &wp : simple_waypoint->GetNextWaypoint()) { this->next_waypoints.push_back(wp->GetId()); } for (auto &wp : simple_waypoint->GetPreviousWaypoint()) { this->previous_waypoints.push_back(wp->GetId()); } if (simple_waypoint->GetLeftWaypoint() != nullptr) { this->next_left_waypoint = simple_waypoint->GetLeftWaypoint()->GetId(); } if (simple_waypoint->GetRightWaypoint() != nullptr) { this->next_right_waypoint = simple_waypoint->GetRightWaypoint()->GetId(); } this->geodesic_grid_id = simple_waypoint->GetGeodesicGridId(); this->is_junction = simple_waypoint->CheckJunction(); this->road_option = static_cast(simple_waypoint->GetRoadOption()); } void CachedSimpleWaypoint::Write(std::ofstream &out_file) { WriteValue(out_file, this->waypoint_id); // road_id, section_id, lane_id, s WriteValue(out_file, this->road_id); WriteValue(out_file, this->section_id); WriteValue(out_file, this->lane_id); WriteValue(out_file, this->s); // list_of_next uint16_t total_next = static_cast(this->next_waypoints.size()); WriteValue(out_file, total_next); for (auto &id : this->next_waypoints) { WriteValue(out_file, id); } // list_of_previous uint16_t total_previous = static_cast(this->previous_waypoints.size()); WriteValue(out_file, total_previous); for (auto &id : this->previous_waypoints) { WriteValue(out_file, id); } // left, right WriteValue(out_file, this->next_left_waypoint); WriteValue(out_file, this->next_right_waypoint); // geo_grid_id WriteValue(out_file, this->geodesic_grid_id); // is_junction WriteValue(out_file, this->is_junction); // road_option WriteValue(out_file, this->road_option); } void CachedSimpleWaypoint::Read(std::ifstream &in_file) { ReadValue(in_file, this->waypoint_id); // road_id, section_id, lane_id, s ReadValue(in_file, this->road_id); ReadValue(in_file, this->section_id); ReadValue(in_file, this->lane_id); ReadValue(in_file, this->s); // list_of_next uint16_t total_next; ReadValue(in_file, total_next); for (uint16_t i = 0; i < total_next; i++) { uint64_t id; ReadValue(in_file, id); this->next_waypoints.push_back(id); } // list_of_previous uint16_t total_previous; ReadValue(in_file, total_previous); for (uint16_t i = 0; i < total_previous; i++) { uint64_t id; ReadValue(in_file, id); this->previous_waypoints.push_back(id); } // left, right ReadValue(in_file, this->next_left_waypoint); ReadValue(in_file, this->next_right_waypoint); // geo_grid_id ReadValue(in_file, this->geodesic_grid_id); // is_junction ReadValue(in_file, this->is_junction); // road_option ReadValue(in_file, this->road_option); } void CachedSimpleWaypoint::Read(const std::vector& content, unsigned long& start) { ReadValue(content, start, this->waypoint_id); // road_id, section_id, lane_id, s ReadValue(content, start, this->road_id); ReadValue(content, start, this->section_id); ReadValue(content, start, this->lane_id); ReadValue(content, start, this->s); // list_of_next uint16_t total_next; ReadValue(content, start, total_next); for (uint16_t i = 0; i < total_next; i++) { uint64_t id; ReadValue(content, start, id); this->next_waypoints.push_back(id); } // list_of_previous uint16_t total_previous; ReadValue(content, start, total_previous); for (uint16_t i = 0; i < total_previous; i++) { uint64_t id; ReadValue(content, start, id); this->previous_waypoints.push_back(id); } // left, right ReadValue(content, start, this->next_left_waypoint); ReadValue(content, start, this->next_right_waypoint); // geo_grid_id ReadValue(content, start, this->geodesic_grid_id); // is_junction ReadValue(content, start, this->is_junction); // road_option ReadValue(content, start, this->road_option); } } // namespace traffic_manager } // namespace carla