39void LoadPcds(
const std::string& file_path,
const unsigned int frame_index,
40 const Eigen::Affine3d& pose,
42 std::vector<unsigned char>* intensities,
bool is_global) {
43 Eigen::Affine3d pose_inv = pose.inverse();
44 pcl::PointCloud<PointXYZIT>::Ptr cloud(
new pcl::PointCloud<PointXYZIT>);
45 if (pcl::io::loadPCDFile(file_path, *cloud) >= 0) {
46 if (cloud->height == 1 || cloud->width == 1) {
47 AINFO <<
"Un-organized-point-cloud";
48 for (
unsigned int i = 0; i < cloud->size(); ++i) {
50 pt3d[0] = (*cloud)[i].x;
51 pt3d[1] = (*cloud)[i].y;
52 pt3d[2] = (*cloud)[i].z;
54 if (pt3d[0] == pt3d[0] && pt3d[1] == pt3d[1] && pt3d[2] == pt3d[2]) {
55 Eigen::Vector3d pt3d_local;
57 pt3d_local = pose_inv * pt3d;
61 unsigned char intensity =
62 static_cast<unsigned char>((*cloud)[i].intensity);
63 pt3ds->push_back(pt3d_local);
64 intensities->push_back(intensity);
68 for (
unsigned int h = 0; h < cloud->height; ++h) {
69 for (
unsigned int w = 0; w < cloud->width; ++w) {
70 double x = cloud->at(w, h).x;
71 double y = cloud->at(w, h).y;
72 double z = cloud->at(w, h).z;
73 Eigen::Vector3d pt3d(x, y, z);
74 if (pt3d[0] == pt3d[0] && pt3d[1] == pt3d[1] && pt3d[2] == pt3d[2]) {
75 Eigen::Vector3d pt3d_local;
77 pt3d_local = pose_inv * pt3d;
81 unsigned char intensity =
82 static_cast<unsigned char>(cloud->at(w, h).intensity);
83 pt3ds->push_back(pt3d_local);
84 intensities->push_back(intensity);
90 AERROR <<
"Failed to load PCD file: " << file_path;
103 std::vector<double>* timestamps,
104 std::vector<unsigned int>* pcd_indices) {
107 pcd_indices->clear();
109 FILE* file = fopen(file_path.c_str(),
"r");
114 double qx, qy, qz, qr;
115 static constexpr int kSize = 9;
116 while (fscanf(file,
"%u %lf %lf %lf %lf %lf %lf %lf %lf\n", &index,
117 ×tamp, &x, &y, &z, &qx, &qy, &qz, &qr) == kSize) {
118 Eigen::Translation3d trans(Eigen::Vector3d(x, y, z));
119 Eigen::Quaterniond quat(qr, qx, qy, qz);
120 poses->push_back(trans * quat);
121 timestamps->push_back(timestamp);
122 pcd_indices->push_back(index);
126 AERROR <<
"Can't open file to read: " << file_path;
133 std::vector<double>* timestamps) {
138 FILE* file = fopen(file_path.c_str(),
"r");
143 double qx, qy, qz, qr;
144 double std_x, std_y, std_z;
145 static constexpr int kSize = 12;
146 while (fscanf(file,
"%u %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
147 &index, ×tamp, &x, &y, &z, &qx, &qy, &qz, &qr, &std_x,
148 &std_y, &std_z) == kSize) {
149 Eigen::Translation3d trans(Eigen::Vector3d(x, y, z));
150 Eigen::Quaterniond quat(qr, qx, qy, qz);
151 poses->push_back(trans * quat);
152 timestamps->push_back(timestamp);
155 std << std_x, std_y, std_z;
156 stds->push_back(
std);
160 AERROR <<
"Can't open file to read: " << file_path;
164bool LoadExtrinsic(
const std::string& file_path, Eigen::Affine3d* extrinsic) {
165 YAML::Node config = YAML::LoadFile(file_path);
166 if (config[
"transform"]) {
167 if (config[
"transform"][
"translation"]) {
168 extrinsic->translation()(0) =
169 config[
"transform"][
"translation"][
"x"].as<double>();
170 extrinsic->translation()(1) =
171 config[
"transform"][
"translation"][
"y"].as<double>();
172 extrinsic->translation()(2) =
173 config[
"transform"][
"translation"][
"z"].as<double>();
174 if (config[
"transform"][
"rotation"]) {
175 double qx = config[
"transform"][
"rotation"][
"x"].as<
double>();
176 double qy = config[
"transform"][
"rotation"][
"y"].as<
double>();
177 double qz = config[
"transform"][
"rotation"][
"z"].as<
double>();
178 double qw = config[
"transform"][
"rotation"][
"w"].as<
double>();
179 extrinsic->linear() =
180 Eigen::Quaterniond(qw, qx, qy, qz).toRotationMatrix();
void LoadPosesAndStds(const std::string &file_path, ::apollo::common::EigenAffine3dVec *poses, ::apollo::common::EigenVector3dVec *stds, std::vector< double > *timestamps)
Load poses and stds their timestamps.