| 114 | } |
| 115 | |
| 116 | void sloam::OptimizeZRollPitch(const SE3 &poseEstimate, const bool optimize, const std::vector<ObjectMatch<Plane>> &allGMatch, double* out) |
| 117 | { |
| 118 | |
| 119 | auto t = poseEstimate.translation(); |
| 120 | auto q = poseEstimate.unit_quaternion(); |
| 121 | double quat[4] = {q.w(), q.x(), q.y(), q.z()}; |
| 122 | double rpy[3]; |
| 123 | ceres::QuaternionToAngleAxis(quat, rpy); |
| 124 | double params[6] = {t[0], t[1], t[2], rpy[0], rpy[1], rpy[2]}; |
| 125 | |
| 126 | bool success = true; |
| 127 | if(optimize) |
| 128 | { |
| 129 | ceres::LossFunction *loss = NULL; |
| 130 | loss = new ceres::HuberLoss(0.1); |
| 131 | ceres::Problem::Options problem_options; |
| 132 | ceres::Problem problem(problem_options); |
| 133 | |
| 134 | problem.AddParameterBlock(params, 6); |
| 135 | // setting x, y and yaw as constant |
| 136 | ceres::SubsetParameterization *subset_parameterization = |
| 137 | new ceres::SubsetParameterization(6, {0, 1, 5}); |
| 138 | problem.SetParameterization(params, subset_parameterization); |
| 139 | |
| 140 | for (auto gMatch : allGMatch) |
| 141 | { |
| 142 | double weight = 1.0; |
| 143 | ceres::CostFunction *cost = |
| 144 | new ceres::AutoDiffCostFunction<ZRollPitchPlaneCost, 1, 6>( |
| 145 | new ZRollPitchPlaneCost(gMatch.feature, gMatch.object.model.plane, weight)); |
| 146 | auto rbid = problem.AddResidualBlock(cost, loss, params); |
| 147 | } |
| 148 | |
| 149 | ceres::Solver::Options options; |
| 150 | options.max_num_iterations = 50; |
| 151 | |
| 152 | options.linear_solver_type = ceres::DENSE_QR; |
| 153 | options.logging_type = ceres::SILENT; |
| 154 | ceres::Solver::Summary summary; |
| 155 | ceres::Solve(options, &problem, &summary); |
| 156 | // if converged |
| 157 | success = summary.termination_type == 0; |
| 158 | } |
| 159 | |
| 160 | double output[3]; |
| 161 | if (optimize && success) |
| 162 | { |
| 163 | out[0] = params[2]; |
| 164 | out[1] = params[3]; |
| 165 | out[2] = params[4]; |
| 166 | } else |
| 167 | { |
| 168 | out[0] = t[2]; |
| 169 | out[1] = rpy[0]; |
| 170 | out[2] = rpy[1]; |
| 171 | } |
| 172 | } |
| 173 |
nothing calls this directly
no outgoing calls
no test coverage detected