From 1f6a6c5a7679cdf0fab52d69b924fd4c169dcd9e Mon Sep 17 00:00:00 2001 From: Ryuta Kambe Date: Tue, 21 May 2024 11:29:29 +0900 Subject: [PATCH] refactor(ground_segmentation): refactor based on cppcheck (#7060) * remove unread variabls Signed-off-by: Ryuta Kambe * remove unread variabls Signed-off-by: Ryuta Kambe * remove duplicateBranch Signed-off-by: Ryuta Kambe * style(pre-commit): autofix * fix Signed-off-by: veqcc --------- Signed-off-by: Ryuta Kambe Signed-off-by: veqcc Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../src/ransac_ground_filter_nodelet.cpp | 8 ++------ .../src/scan_ground_filter_nodelet.cpp | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/perception/ground_segmentation/src/ransac_ground_filter_nodelet.cpp b/perception/ground_segmentation/src/ransac_ground_filter_nodelet.cpp index 587db9c9e0dac..d7fa777dc58c9 100644 --- a/perception/ground_segmentation/src/ransac_ground_filter_nodelet.cpp +++ b/perception/ground_segmentation/src/ransac_ground_filter_nodelet.cpp @@ -102,9 +102,7 @@ RANSACGroundFilterComponent::RANSACGroundFilterComponent(const rclcpp::NodeOptio unit_vec_ = Eigen::Vector3d::UnitX(); } else if (unit_axis_ == "y") { unit_vec_ = Eigen::Vector3d::UnitY(); - } else if (unit_axis_ == "z") { - unit_vec_ = Eigen::Vector3d::UnitZ(); - } else { + } else { // including (unit_axis_ == "z") unit_vec_ = Eigen::Vector3d::UnitZ(); } @@ -384,9 +382,7 @@ rcl_interfaces::msg::SetParametersResult RANSACGroundFilterComponent::paramCallb unit_vec_ = Eigen::Vector3d::UnitX(); } else if (unit_axis_ == "y") { unit_vec_ = Eigen::Vector3d::UnitY(); - } else if (unit_axis_ == "z") { - unit_vec_ = Eigen::Vector3d::UnitZ(); - } else { + } else { // including (unit_axis_ == "z") unit_vec_ = Eigen::Vector3d::UnitZ(); } RCLCPP_DEBUG(get_logger(), "Setting unit_axis to: %s.", unit_axis_.c_str()); diff --git a/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp b/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp index 6399726740041..a63d218df62de 100644 --- a/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp +++ b/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp @@ -349,13 +349,12 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan( // check the first point in ray auto * p = &in_radial_ordered_clouds[i][0]; - auto * prev_p = &in_radial_ordered_clouds[i][0]; // for checking the distance to prev point bool initialized_first_gnd_grid = false; bool prev_list_init = false; pcl::PointXYZ p_orig_point, prev_p_orig_point; for (auto & point : in_radial_ordered_clouds[i]) { - prev_p = p; + auto * prev_p = p; // for checking the distance to prev point prev_p_orig_point = p_orig_point; p = &point; get_point_from_global_offset(in_cloud, p_orig_point, in_cloud->point_step * p->orig_index); @@ -469,7 +468,6 @@ void ScanGroundFilterComponent::classifyPointCloud( float prev_gnd_slope = 0.0f; float points_distance = 0.0f; PointsCentroid ground_cluster, non_ground_cluster; - float local_slope = 0.0f; PointLabel prev_point_label = PointLabel::INIT; pcl::PointXYZ prev_gnd_point(0, 0, 0), p_orig_point, prev_p_orig_point; // loop through each point in the radial div @@ -524,7 +522,7 @@ void ScanGroundFilterComponent::classifyPointCloud( } if (calculate_slope) { // far from the previous point - local_slope = std::atan2(height_from_gnd, radius_distance_from_gnd); + auto local_slope = std::atan2(height_from_gnd, radius_distance_from_gnd); if (local_slope - prev_gnd_slope > local_slope_max_angle) { // the point is outside of the local slope threshold p->point_state = PointLabel::NON_GROUND;