126 Eigen::Vector3d trans_diff =
127 pose.translation() - pre_input_location_.translation();
128 Eigen::Vector3d trans_pre_local =
129 pre_estimate_location_.translation() + trans_diff;
130 Eigen::Quaterniond quatd(pose.linear());
131 Eigen::Translation3d transd(trans_pre_local);
132 Eigen::Affine3d center_pose = transd * quatd;
134 Eigen::Quaterniond pose_qbn(pose.linear());
135 AINFO <<
"original pose: " << std::setprecision(15) << pose.translation()[0]
136 <<
", " << pose.translation()[1] <<
", " << pose.translation()[2]
137 <<
", " << pose_qbn.x() <<
", " << pose_qbn.y() <<
", " << pose_qbn.z()
138 <<
", " << pose_qbn.w();
141 Eigen::Affine3d transform = center_pose * velodyne_extrinsic_;
142 predict_location_ = center_pose;
145#ifdef USE_PRELOAD_MAP_NODE
147 map_.
LoadMapArea(center_pose.translation(), resolution_id_, zone_id_,
148 filter_x_, filter_y_);
149 map_.
PreloadMapArea(center_pose.translation(), trans_diff, resolution_id_,
154 double lt_x = pose.translation()[0];
155 double lt_y = pose.translation()[1];
163 online_filtered_timer.
Start();
164 pcl::PointCloud<pcl::PointXYZ>::Ptr online_points(
165 new pcl::PointCloud<pcl::PointXYZ>());
166 for (
unsigned int i = 0; i < lidar_frame.
pt_xs.size(); ++i) {
167 pcl::PointXYZ p(lidar_frame.
pt_xs[i], lidar_frame.
pt_ys[i],
168 lidar_frame.
pt_zs[i]);
169 online_points->push_back(p);
173 AINFO <<
"Online point cloud leaf size: " << proj_reslution_;
174 pcl::PointCloud<pcl::PointXYZ>::Ptr online_points_filtered(
175 new pcl::PointCloud<pcl::PointXYZ>());
176 pcl::VoxelGrid<pcl::PointXYZ> sor;
177 sor.setInputCloud(online_points);
178 sor.setLeafSize(proj_reslution_, proj_reslution_, proj_reslution_);
179 sor.filter(*online_points_filtered);
180 AINFO <<
"Online Pointcloud size: " << online_points->size() <<
"/"
181 << online_points_filtered->size();
182 online_filtered_timer.
End(
"online point calc end.");
187 Eigen::Vector2d left_top_coord2d(lt_x, lt_y);
190 transform.inverse());
193 pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_map_point_cloud(
194 new pcl::PointCloud<pcl::PointXYZ>());
195 for (
unsigned int i = 0; i < cell_map_.size(); ++i) {
196 Leaf& le = cell_map_[i];
197 float mean_0 =
static_cast<float>(le.
mean_(0));
198 float mean_1 =
static_cast<float>(le.
mean_(1));
199 float mean_2 =
static_cast<float>(le.
mean_(2));
200 pcl_map_point_cloud->push_back(pcl::PointXYZ(mean_0, mean_1, mean_2));
202 map_timer.
End(
"Map create end.");
211 Eigen::Matrix3d inv_R = transform.inverse().linear();
212 Eigen::Matrix4d init_matrix = Eigen::Matrix4d::Identity();
213 init_matrix.block<3, 3>(0, 0) = inv_R.inverse();
215 pcl::PointCloud<pcl::PointXYZ>::Ptr output_cloud(
216 new pcl::PointCloud<pcl::PointXYZ>);
217 reg_.
Align(output_cloud, init_matrix.cast<
float>());
218 ndt_timer.
End(
"Ndt Align End.");
224 AINFO <<
"Ndt summary:";
225 AINFO <<
"Fitness Score: " << fitness_score_;
226 AINFO <<
"Has_converged: " << has_converged;
227 AINFO <<
"Iteration: %d: " << iteration;
228 AINFO <<
"Relative Ndt pose: " << ndt_pose(0, 3) <<
", " << ndt_pose(1, 3)
229 <<
", " << ndt_pose(2, 3);
232 Eigen::Affine3d lidar_location = Eigen::Affine3d::Identity();
233 lidar_location = transform.matrix() * init_matrix.inverse() * ndt_pose;
236 location_ = lidar_location * velodyne_extrinsic_.inverse();
237 pre_input_location_ = pose;
238 pre_estimate_location_ = location_;
239 pre_imu_height_ = location_.translation()(2);
260 const Eigen::Vector2d& left_top_coord2d,
int zone_id,
261 unsigned int resolution_id,
float map_pixel_resolution,
262 const Eigen::Affine3d& inverse_transform) {
268 unsigned int filter_size_x = filter_x_;
269 unsigned int filter_size_y = filter_y_;
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);
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);
286 std::vector<std::vector<int>> map_nodes_zones;
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);
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
306 int top_center_end_y =
static_cast<int>(map_node_size_y) - 1;
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);
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;
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);
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
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);
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;
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);
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;
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);
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;
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);
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;
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);
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;
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);
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;
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;
406 start_y_indices[1] + middle_center_end_y - middle_center_start_y + 1;
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]));
416 Eigen::Vector2d coord2d_center =
417 map_node_lt->
GetCoordinate(map_node_size_x / 2, map_node_size_y / 2);
420 Eigen::Affine3d transform = inverse_transform.inverse();
421 Eigen::Vector3d R_inv_t = -transform.translation();
423 map_left_top_corner_ = Eigen::Vector3d::Zero();
425 map_left_top_corner_ += R_inv_t;
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) {
433 if (x == 0 && y == 0) {
434 map_node_ptr = map_node_lt;
436 Eigen::Vector2d coord2d_xy;
438 coord2d_center[0] +
static_cast<double>(x * map_node_size_x) *
439 static_cast<double>(map_pixel_resolution);
441 coord2d_center[1] +
static_cast<double>(y * map_node_size_y) *
442 static_cast<double>(map_pixel_resolution);
445 map_.
GetMapConfig(), coord2d_xy, resolution_id, zone_id);
449 map_node_ptr = map_node_xy;
457 const Eigen::Vector2d& left_top_corner =
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) {
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) {
472 leaf.
nr_points_ =
static_cast<int>(cell_count);
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];
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>();
488 cell_map_.push_back(leaf);
498 timer.
End(
"Compose map cells.");