| 129 | } |
| 130 | |
| 131 | LinearSystem BuildLinearSystem(const Vector3dVector &points) { |
| 132 | auto compute_jacobian_and_residual = |
| 133 | [](const Eigen::Vector3d &point) -> std::pair<Eigen::Matrix<double, 1, 3>, double> { |
| 134 | return {Eigen::Matrix<double, 1, 3>(1.0, point.y(), -point.x()), point.z()}; |
| 135 | }; |
| 136 | |
| 137 | auto sum_linear_systems = [](LinearSystem a, const LinearSystem &b) -> LinearSystem { |
| 138 | a.first += b.first; |
| 139 | a.second += b.second; |
| 140 | return a; |
| 141 | }; |
| 142 | |
| 143 | const auto linear_system = |
| 144 | std::transform_reduce(points.cbegin(), points.cend(), |
| 145 | LinearSystem(Eigen::Matrix3d::Zero(), Eigen::Vector3d::Zero()), |
| 146 | sum_linear_systems, [&](const Eigen::Vector3d &point) { |
| 147 | const auto [J, residual] = compute_jacobian_and_residual(point); |
| 148 | const double w = std::exp(-1.0 * residual * residual); |
| 149 | return LinearSystem(J.transpose() * w * J, // JTJ |
| 150 | J.transpose() * w * residual); // JTr |
| 151 | }); |
| 152 | return linear_system; |
| 153 | } |
| 154 | } // namespace |
| 155 | |
| 156 | namespace map_closures { |
no test coverage detected