| 401 | } |
| 402 | |
| 403 | void PoseGraph::optimize4DoF() |
| 404 | { |
| 405 | while(true) |
| 406 | { |
| 407 | int cur_index = -1; |
| 408 | int first_looped_index = -1; |
| 409 | m_optimize_buf.lock(); |
| 410 | while(!optimize_buf.empty()) |
| 411 | { |
| 412 | cur_index = optimize_buf.front(); |
| 413 | first_looped_index = earliest_loop_index; |
| 414 | optimize_buf.pop(); |
| 415 | } |
| 416 | m_optimize_buf.unlock(); |
| 417 | if (cur_index != -1) |
| 418 | { |
| 419 | printf("optimize pose graph \n"); |
| 420 | TicToc tmp_t; |
| 421 | m_keyframelist.lock(); |
| 422 | KeyFrame* cur_kf = getKeyFrame(cur_index); |
| 423 | |
| 424 | int max_length = cur_index + 1; |
| 425 | |
| 426 | // w^t_i w^q_i |
| 427 | double t_array[max_length][3]; |
| 428 | Quaterniond q_array[max_length]; |
| 429 | double euler_array[max_length][3]; |
| 430 | double sequence_array[max_length]; |
| 431 | |
| 432 | ceres::Problem problem; |
| 433 | ceres::Solver::Options options; |
| 434 | options.linear_solver_type = ceres::SPARSE_NORMAL_CHOLESKY; |
| 435 | //options.minimizer_progress_to_stdout = true; |
| 436 | //options.max_solver_time_in_seconds = SOLVER_TIME * 3; |
| 437 | options.max_num_iterations = 5; |
| 438 | ceres::Solver::Summary summary; |
| 439 | ceres::LossFunction *loss_function; |
| 440 | loss_function = new ceres::HuberLoss(0.1); |
| 441 | //loss_function = new ceres::CauchyLoss(1.0); |
| 442 | ceres::LocalParameterization* angle_local_parameterization = |
| 443 | AngleLocalParameterization::Create(); |
| 444 | |
| 445 | list<KeyFrame*>::iterator it; |
| 446 | |
| 447 | int i = 0; |
| 448 | for (it = keyframelist.begin(); it != keyframelist.end(); it++) |
| 449 | { |
| 450 | if ((*it)->index < first_looped_index) |
| 451 | continue; |
| 452 | (*it)->local_index = i; |
| 453 | Quaterniond tmp_q; |
| 454 | Matrix3d tmp_r; |
| 455 | Vector3d tmp_t; |
| 456 | (*it)->getVioPose(tmp_t, tmp_r); |
| 457 | tmp_q = tmp_r; |
| 458 | t_array[i][0] = tmp_t(0); |
| 459 | t_array[i][1] = tmp_t(1); |
| 460 | t_array[i][2] = tmp_t(2); |
nothing calls this directly
no test coverage detected