Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1366727

Browse files
committedFeb 18, 2024
fixed the bug and corrected the spelling mistake.
Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp>
1 parent a4b1560 commit 1366727

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed
 

‎perception/occupancy_grid_map_outlier_filter/src/occupancy_grid_map_outlier_filter_nodelet.cpp

+24-20
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,18 @@ void RadiusSearch2dFilter::filter(
120120
{
121121
const auto & xyz_cloud = input;
122122
pcl::PointCloud<pcl::PointXY>::Ptr xy_cloud(new pcl::PointCloud<pcl::PointXY>);
123-
xy_cloud->points.resize(xyz_cloud.points.size());
124-
for (size_t i = 0; i < xyz_cloud.points.size(); ++i) {
123+
auto xyz_cloud_points_size = xyz_cloud.points.size();
124+
xy_cloud->points.resize(xyz_cloud_points_size);
125+
for (size_t i = 0; i < xyz_cloud_points_size; ++i) {
125126
xy_cloud->points[i].x = xyz_cloud.points[i].x;
126127
xy_cloud->points[i].y = xyz_cloud.points[i].y;
127128
}
128129

129-
std::vector<int> k_indices(xy_cloud->points.size());
130-
std::vector<float> k_distances(xy_cloud->points.size());
130+
auto xy_cloud_points_size = xy_cloud->points.size();
131+
std::vector<int> k_indices(xy_cloud_points_size);
132+
std::vector<float> k_distances(xy_cloud_points_size);
131133
kd_tree_->setInputCloud(xy_cloud);
132-
for (size_t i = 0; i < xy_cloud->points.size(); ++i) {
134+
for (size_t i = 0; i < xy_cloud_points_size; ++i) {
133135
const float distance =
134136
std::hypot(xy_cloud->points[i].x - pose.position.x, xy_cloud->points[i].y - pose.position.y);
135137
const int min_points_threshold = std::min(
@@ -150,17 +152,18 @@ void RadiusSearch2dFilter::filter(
150152
const PclPointCloud & high_conf_input, const PclPointCloud & low_conf_input, const Pose & pose,
151153
PclPointCloud & output, PclPointCloud & outlier)
152154
{
155+
auto low_conf_input_points_size = low_conf_input.points.size();
153156
// check the limit points number
154-
if (low_conf_input.points.size() > max_filter_points_nb_) {
157+
if (low_conf_input_points_size > max_filter_points_nb_) {
155158
RCLCPP_WARN(
156159
rclcpp::get_logger("OccupancyGridMapOutlierFilterComponent"),
157160
"Skip outlier filter since too much low_confidence pointcloud!");
158161
return;
159162
}
160163

161164
pcl::PointCloud<pcl::PointXY>::Ptr low_conf_xy_cloud(new pcl::PointCloud<pcl::PointXY>);
162-
low_conf_xy_cloud->points.resize(low_conf_input.points.size());
163-
for (size_t i = 0; i < low_conf_input.points.size(); ++i) {
165+
low_conf_xy_cloud->points.resize(low_conf_input_points_size);
166+
for (size_t i = 0; i < low_conf_input_points_size; ++i) {
164167
low_conf_xy_cloud->points[i].x = low_conf_input.points[i].x;
165168
low_conf_xy_cloud->points[i].y = low_conf_input.points[i].y;
166169
}
@@ -169,7 +172,7 @@ void RadiusSearch2dFilter::filter(
169172
std::vector<int> k_indices_low(low_conf_xy_cloud->points.size());
170173
std::vector<float> k_distances_low(low_conf_xy_cloud->points.size());
171174
kd_tree_->setInputCloud(low_conf_xy_cloud);
172-
for (size_t i = 0; i < low_conf_input.points.size(); ++i) {
175+
for (size_t i = 0; i < low_conf_input_points_size; ++i) {
173176
const float distance = std::hypot(
174177
low_conf_xy_cloud->points[i].x - pose.position.x,
175178
low_conf_xy_cloud->points[i].y - pose.position.y);
@@ -184,9 +187,9 @@ void RadiusSearch2dFilter::filter(
184187
outlier.points.push_back(low_conf_input.points.at(i));
185188
}
186189
}
187-
190+
auto outlier_points_size = outlier.points.size();
188191
// High conf cloud check
189-
if (outlier.points.size() == 0) {
192+
if (outlier_points_size == 0) {
190193
return;
191194
}
192195

@@ -200,7 +203,7 @@ void RadiusSearch2dFilter::filter(
200203
std::vector<int> k_indices_high(high_conf_xy_cloud->points.size());
201204
std::vector<float> k_distances_high(high_conf_xy_cloud->points.size());
202205
kd_tree_->setInputCloud(high_conf_xy_cloud);
203-
for (size_t i = 0; i < outlier.points.size(); ++i) {
206+
for (size_t i = 0; i < outlier_points_size; ++i) {
204207
const float distance = std::hypot(
205208
high_conf_xy_cloud->points[i].x - pose.position.x,
206209
high_conf_xy_cloud->points[i].y - pose.position.y);
@@ -212,10 +215,11 @@ void RadiusSearch2dFilter::filter(
212215

213216
if (min_points_threshold <= points_num) {
214217
output.points.push_back(outlier.points.at(i));
215-
} else {
216-
outlier.points.erase(outlier.points.begin() + i);
218+
outlier.points.push_back(outlier.points.at(i));
217219
}
218220
}
221+
222+
outlier.points.erase(outlier.points.begin(),outlier.points.begin() + outlier_points_size);
219223
}
220224

221225
OccupancyGridMapOutlierFilterComponent::OccupancyGridMapOutlierFilterComponent(
@@ -277,12 +281,12 @@ void OccupancyGridMapOutlierFilterComponent::splitPointCloudFrontBack(
277281
}
278282
}
279283

280-
sensor_msgs::PointCloud2Modifier front_pc_modfier(front_pc);
281-
sensor_msgs::PointCloud2Modifier behind_pc_modfier(behind_pc);
282-
front_pc_modfier.setPointCloud2FieldsByString(1, "xyz");
283-
behind_pc_modfier.setPointCloud2FieldsByString(1, "xyz");
284-
front_pc_modfier.resize(front_count);
285-
behind_pc_modfier.resize(behind_count);
284+
sensor_msgs::PointCloud2Modifier front_pc_modifier(front_pc);
285+
sensor_msgs::PointCloud2Modifier behind_pc_modifier(behind_pc);
286+
front_pc_modifier.setPointCloud2FieldsByString(1, "xyz");
287+
behind_pc_modifier.setPointCloud2FieldsByString(1, "xyz");
288+
front_pc_modifier.resize(front_count);
289+
behind_pc_modifier.resize(behind_count);
286290

287291
sensor_msgs::PointCloud2Iterator<float> fr_iter(front_pc, "x");
288292
sensor_msgs::PointCloud2Iterator<float> be_iter(behind_pc, "x");

0 commit comments

Comments
 (0)
Please sign in to comment.