| 172 | } |
| 173 | |
| 174 | bool sloam::OptimizePose(const SE3 &poseEstimate, |
| 175 | const std::vector<ObjectMatch<Cylinder>> &allTMatch, |
| 176 | const std::vector<ObjectMatch<Plane>> &allGMatch, |
| 177 | SE3 &tf) |
| 178 | { |
| 179 | |
| 180 | ceres::LossFunction *loss = NULL; |
| 181 | loss = new ceres::HuberLoss(0.1); |
| 182 | ceres::Problem::Options problem_options; |
| 183 | ceres::Problem problem(problem_options); |
| 184 | |
| 185 | auto t = poseEstimate.translation(); |
| 186 | auto q = poseEstimate.unit_quaternion(); |
| 187 | double para_t[3] = {t[0], t[1], t[2]}; |
| 188 | double para_q[4] = {q.x(), q.y(), q.z(), q.w()}; |
| 189 | ceres::LocalParameterization *q_parameterization = |
| 190 | new ceres::EigenQuaternionParameterization(); |
| 191 | |
| 192 | problem.AddParameterBlock(para_q, 4, q_parameterization); |
| 193 | problem.AddParameterBlock(para_t, 3); |
| 194 | |
| 195 | for (auto tMatch : allTMatch) |
| 196 | { |
| 197 | Vector3 root = tMatch.object.model.root; |
| 198 | Vector3 ray = tMatch.object.model.ray; |
| 199 | double radius = (double)tMatch.object.model.radius; |
| 200 | double weight = 1.0; |
| 201 | ceres::CostFunction *cost = |
| 202 | new ceres::AutoDiffCostFunction<CylinderCost, 1, 3, 4>( |
| 203 | new CylinderCost(tMatch.feature, root, ray, radius, weight)); |
| 204 | problem.AddResidualBlock(cost, loss, para_t, para_q); |
| 205 | } |
| 206 | |
| 207 | std::vector<ceres::ResidualBlockId> residual_block_ids; |
| 208 | for (auto gMatch : allGMatch) |
| 209 | { |
| 210 | double weight = 1.0; |
| 211 | // auto norm_feature = -(gMatch.feature - gMatch.object.model.centroid); |
| 212 | auto norm_feature = gMatch.feature; |
| 213 | ceres::CostFunction *cost = |
| 214 | new ceres::AutoDiffCostFunction<PlaneCost, 1, 3, 4>( |
| 215 | new PlaneCost(norm_feature, gMatch.object.model.plane, weight)); |
| 216 | auto rbid = problem.AddResidualBlock(cost, loss, para_t, para_q); |
| 217 | residual_block_ids.push_back(rbid); |
| 218 | } |
| 219 | |
| 220 | // SOLVE |
| 221 | ceres::Solver::Options options; |
| 222 | options.max_num_iterations = 50; |
| 223 | |
| 224 | options.linear_solver_type = ceres::DENSE_QR; |
| 225 | options.logging_type = ceres::SILENT; |
| 226 | ceres::Solver::Summary summary; |
| 227 | ceres::Solve(options, &problem, &summary); |
| 228 | |
| 229 | // ceres::Problem::EvaluateOptions evoptions; |
| 230 | // evoptions.residual_blocks = residual_block_ids; |
| 231 | // double total_cost = 0.0; |
nothing calls this directly
no outgoing calls
no test coverage detected