From e0e1c081e7902e971008a0c8ddca45f2290f03b8 Mon Sep 17 00:00:00 2001 From: Alexander Belyaev <32522095+pifon2a@users.noreply.github.com> Date: Mon, 26 Mar 2018 15:55:50 +0200 Subject: [PATCH] Do not use operator*= with Jets. (#1018) --- .../occupied_space_cost_function_2d.h | 4 +- .../internal/pose_graph/cost_helpers.h | 8 ++-- .../internal/pose_graph/cost_helpers_impl.h | 38 ++++++++++--------- cartographer/transform/transform.h | 8 ++-- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/cartographer/mapping/internal/2d/scan_matching/occupied_space_cost_function_2d.h b/cartographer/mapping/internal/2d/scan_matching/occupied_space_cost_function_2d.h index 7ca59f9..7f0fb8d 100644 --- a/cartographer/mapping/internal/2d/scan_matching/occupied_space_cost_function_2d.h +++ b/cartographer/mapping/internal/2d/scan_matching/occupied_space_cost_function_2d.h @@ -64,9 +64,9 @@ class OccupiedSpaceCostFunction2D { const Eigen::Matrix world = transform * point; interpolator.Evaluate( (limits.max().x() - world[0]) / limits.resolution() - 0.5 + - double(kPadding), + static_cast(kPadding), (limits.max().y() - world[1]) / limits.resolution() - 0.5 + - double(kPadding), + static_cast(kPadding), &residual[i]); residual[i] = scaling_factor_ * (1. - residual[i]); } diff --git a/cartographer/mapping/internal/pose_graph/cost_helpers.h b/cartographer/mapping/internal/pose_graph/cost_helpers.h index 7b93942..9329d4a 100644 --- a/cartographer/mapping/internal/pose_graph/cost_helpers.h +++ b/cartographer/mapping/internal/pose_graph/cost_helpers.h @@ -35,8 +35,8 @@ static std::array ComputeUnscaledError( const transform::Rigid2d& relative_pose, const T* const start, const T* const end); template -std::array ScaleError(std::array error, double translation_weight, - double rotation_weight); +std::array ScaleError(const std::array& error, + double translation_weight, double rotation_weight); // Computes the error between the given relative pose and the difference of // poses 'start' and 'end' which are both in an arbitrary common frame. @@ -50,8 +50,8 @@ static std::array ComputeUnscaledError( const T* const end_translation); template -std::array ScaleError(std::array error, double translation_weight, - double rotation_weight); +std::array ScaleError(const std::array& error, + double translation_weight, double rotation_weight); // Computes spherical linear interpolation of unit quaternions. // diff --git a/cartographer/mapping/internal/pose_graph/cost_helpers_impl.h b/cartographer/mapping/internal/pose_graph/cost_helpers_impl.h index e46c90b..6066ab2 100644 --- a/cartographer/mapping/internal/pose_graph/cost_helpers_impl.h +++ b/cartographer/mapping/internal/pose_graph/cost_helpers_impl.h @@ -39,13 +39,15 @@ static std::array ComputeUnscaledError( } template -std::array ScaleError(std::array error, double translation_weight, - double rotation_weight) { - std::array scaled_error(std::move(error)); - scaled_error[0] *= translation_weight; - scaled_error[1] *= translation_weight; - scaled_error[2] *= rotation_weight; - return scaled_error; +std::array ScaleError(const std::array& error, + double translation_weight, double rotation_weight) { + // clang-format off + return {{ + error[0] * translation_weight, + error[1] * translation_weight, + error[2] * rotation_weight + }}; + // clang-format on } template @@ -80,16 +82,18 @@ static std::array ComputeUnscaledError( } template -std::array ScaleError(std::array error, double translation_weight, - double rotation_weight) { - std::array scaled_error(std::move(error)); - scaled_error[0] *= translation_weight; - scaled_error[1] *= translation_weight; - scaled_error[2] *= translation_weight; - scaled_error[3] *= rotation_weight; - scaled_error[4] *= rotation_weight; - scaled_error[5] *= rotation_weight; - return scaled_error; +std::array ScaleError(const std::array& error, + double translation_weight, double rotation_weight) { + // clang-format off + return {{ + error[0] * translation_weight, + error[1] * translation_weight, + error[2] * translation_weight, + error[3] * rotation_weight, + error[4] * rotation_weight, + error[5] * rotation_weight + }}; + // clang-format on } // Eigen implementation of slerp is not compatible with Ceres on all supported diff --git a/cartographer/transform/transform.h b/cartographer/transform/transform.h index 3d4b4c0..8c69cec 100644 --- a/cartographer/transform/transform.h +++ b/cartographer/transform/transform.h @@ -64,10 +64,10 @@ Eigen::Matrix RotationQuaternionToAngleAxisVector( // angle that represents this orientation. if (normalized_quaternion.w() < 0.) { // Multiply by -1. http://eigen.tuxfamily.org/bz/show_bug.cgi?id=560 - normalized_quaternion.w() *= -1.; - normalized_quaternion.x() *= -1.; - normalized_quaternion.y() *= -1.; - normalized_quaternion.z() *= -1.; + normalized_quaternion.w() = -1.* normalized_quaternion.w(); + normalized_quaternion.x() = -1.* normalized_quaternion.x(); + normalized_quaternion.y() = -1.* normalized_quaternion.y(); + normalized_quaternion.z() = -1.* normalized_quaternion.z(); } // We convert the normalized_quaternion into a vector along the rotation axis // with length of the rotation angle.