| 69 | } |
| 70 | |
| 71 | void Trajectory::OutputPathToPointcloud(const std::string& path) { |
| 72 | if (!common::FileExist(path)) { |
| 73 | LOG(WARNING) << "Path does not exist. do not output any thing."; |
| 74 | return; |
| 75 | } |
| 76 | int path_point_index = 0; |
| 77 | std::ofstream path_text_file(path + "/path.csv"); |
| 78 | std::string path_content; |
| 79 | bool write_to_text = path_text_file.is_open(); |
| 80 | pcl::PointCloud<pcl::_PointXYZI>::Ptr path_cloud( |
| 81 | new pcl::PointCloud<pcl::_PointXYZI>); |
| 82 | pcl::PointCloud<pcl::PointXYZI> enu_path_cloud; |
| 83 | pcl::PointCloud<pcl::PointXYZI> odom_path_cloud; |
| 84 | enu_path_cloud.points.reserve(this->size()); |
| 85 | for (const auto& submap : *this) { |
| 86 | // enu path |
| 87 | if (submap->HasGps()) { |
| 88 | pcl::PointXYZI enu_point; |
| 89 | const Eigen::Vector3d enu = submap->GetRelatedGpsInENU(); |
| 90 | enu_point.x = enu[0]; |
| 91 | enu_point.y = enu[1]; |
| 92 | enu_point.z = enu[2]; |
| 93 | enu_point.intensity = 0.; |
| 94 | enu_path_cloud.push_back(enu_point); |
| 95 | } |
| 96 | // odom path |
| 97 | if (submap->HasOdom()) { |
| 98 | pcl::PointXYZI odom_point; |
| 99 | const Eigen::Vector3d odom = |
| 100 | common::Translation(submap->GetRelatedOdom()); |
| 101 | odom_point.x = odom[0]; |
| 102 | odom_point.y = odom[1]; |
| 103 | odom_point.z = odom[2]; |
| 104 | odom_point.intensity = 0.; |
| 105 | odom_path_cloud.push_back(odom_point); |
| 106 | } |
| 107 | // map path |
| 108 | for (auto& frame : submap->GetFrames()) { |
| 109 | pcl::_PointXYZI path_point; |
| 110 | Eigen::Matrix4d pose = frame->GlobalPose(); |
| 111 | Eigen::Vector6<double> global_pose_6d = common::TransformToVector6(pose); |
| 112 | path_point.x = global_pose_6d[0]; |
| 113 | path_point.y = global_pose_6d[1]; |
| 114 | path_point.z = global_pose_6d[2]; |
| 115 | path_point.intensity = path_point_index; |
| 116 | |
| 117 | path_cloud->push_back(path_point); |
| 118 | if (write_to_text) { |
| 119 | path_content += (std::to_string(path_point_index) + ", "); |
| 120 | path_content += (std::to_string(global_pose_6d[0]) + ", "); |
| 121 | path_content += (std::to_string(global_pose_6d[1]) + ", "); |
| 122 | path_content += (std::to_string(global_pose_6d[2]) + ", "); |
| 123 | path_content += (std::to_string(global_pose_6d[3]) + ", "); |
| 124 | path_content += (std::to_string(global_pose_6d[4]) + ", "); |
| 125 | path_content += (std::to_string(global_pose_6d[5]) + " \n"); |
| 126 | } |
| 127 | path_point_index++; |
| 128 | } |
no test coverage detected