Skip to content

Commit 1f6a6c5

Browse files
refactor(ground_segmentation): refactor based on cppcheck (#7060)
* remove unread variabls Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp> * remove unread variabls Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp> * remove duplicateBranch Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp> * style(pre-commit): autofix * fix Signed-off-by: veqcc <ryuta.kambe@tier4.jp> --------- Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp> Signed-off-by: veqcc <ryuta.kambe@tier4.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2f2925d commit 1f6a6c5

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

perception/ground_segmentation/src/ransac_ground_filter_nodelet.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ RANSACGroundFilterComponent::RANSACGroundFilterComponent(const rclcpp::NodeOptio
102102
unit_vec_ = Eigen::Vector3d::UnitX();
103103
} else if (unit_axis_ == "y") {
104104
unit_vec_ = Eigen::Vector3d::UnitY();
105-
} else if (unit_axis_ == "z") {
106-
unit_vec_ = Eigen::Vector3d::UnitZ();
107-
} else {
105+
} else { // including (unit_axis_ == "z")
108106
unit_vec_ = Eigen::Vector3d::UnitZ();
109107
}
110108

@@ -384,9 +382,7 @@ rcl_interfaces::msg::SetParametersResult RANSACGroundFilterComponent::paramCallb
384382
unit_vec_ = Eigen::Vector3d::UnitX();
385383
} else if (unit_axis_ == "y") {
386384
unit_vec_ = Eigen::Vector3d::UnitY();
387-
} else if (unit_axis_ == "z") {
388-
unit_vec_ = Eigen::Vector3d::UnitZ();
389-
} else {
385+
} else { // including (unit_axis_ == "z")
390386
unit_vec_ = Eigen::Vector3d::UnitZ();
391387
}
392388
RCLCPP_DEBUG(get_logger(), "Setting unit_axis to: %s.", unit_axis_.c_str());

perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,12 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
349349

350350
// check the first point in ray
351351
auto * p = &in_radial_ordered_clouds[i][0];
352-
auto * prev_p = &in_radial_ordered_clouds[i][0]; // for checking the distance to prev point
353352

354353
bool initialized_first_gnd_grid = false;
355354
bool prev_list_init = false;
356355
pcl::PointXYZ p_orig_point, prev_p_orig_point;
357356
for (auto & point : in_radial_ordered_clouds[i]) {
358-
prev_p = p;
357+
auto * prev_p = p; // for checking the distance to prev point
359358
prev_p_orig_point = p_orig_point;
360359
p = &point;
361360
get_point_from_global_offset(in_cloud, p_orig_point, in_cloud->point_step * p->orig_index);
@@ -469,7 +468,6 @@ void ScanGroundFilterComponent::classifyPointCloud(
469468
float prev_gnd_slope = 0.0f;
470469
float points_distance = 0.0f;
471470
PointsCentroid ground_cluster, non_ground_cluster;
472-
float local_slope = 0.0f;
473471
PointLabel prev_point_label = PointLabel::INIT;
474472
pcl::PointXYZ prev_gnd_point(0, 0, 0), p_orig_point, prev_p_orig_point;
475473
// loop through each point in the radial div
@@ -524,7 +522,7 @@ void ScanGroundFilterComponent::classifyPointCloud(
524522
}
525523
if (calculate_slope) {
526524
// far from the previous point
527-
local_slope = std::atan2(height_from_gnd, radius_distance_from_gnd);
525+
auto local_slope = std::atan2(height_from_gnd, radius_distance_from_gnd);
528526
if (local_slope - prev_gnd_slope > local_slope_max_angle) {
529527
// the point is outside of the local slope threshold
530528
p->point_state = PointLabel::NON_GROUND;

0 commit comments

Comments
 (0)