@@ -120,16 +120,18 @@ void RadiusSearch2dFilter::filter(
120
120
{
121
121
const auto & xyz_cloud = input;
122
122
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) {
125
126
xy_cloud->points [i].x = xyz_cloud.points [i].x ;
126
127
xy_cloud->points [i].y = xyz_cloud.points [i].y ;
127
128
}
128
129
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);
131
133
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) {
133
135
const float distance =
134
136
std::hypot (xy_cloud->points [i].x - pose.position .x , xy_cloud->points [i].y - pose.position .y );
135
137
const int min_points_threshold = std::min (
@@ -150,17 +152,18 @@ void RadiusSearch2dFilter::filter(
150
152
const PclPointCloud & high_conf_input, const PclPointCloud & low_conf_input, const Pose & pose,
151
153
PclPointCloud & output, PclPointCloud & outlier)
152
154
{
155
+ auto low_conf_input_points_size = low_conf_input.points .size ();
153
156
// 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_) {
155
158
RCLCPP_WARN (
156
159
rclcpp::get_logger (" OccupancyGridMapOutlierFilterComponent" ),
157
160
" Skip outlier filter since too much low_confidence pointcloud!" );
158
161
return ;
159
162
}
160
163
161
164
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) {
164
167
low_conf_xy_cloud->points [i].x = low_conf_input.points [i].x ;
165
168
low_conf_xy_cloud->points [i].y = low_conf_input.points [i].y ;
166
169
}
@@ -169,7 +172,7 @@ void RadiusSearch2dFilter::filter(
169
172
std::vector<int > k_indices_low (low_conf_xy_cloud->points .size ());
170
173
std::vector<float > k_distances_low (low_conf_xy_cloud->points .size ());
171
174
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) {
173
176
const float distance = std::hypot (
174
177
low_conf_xy_cloud->points [i].x - pose.position .x ,
175
178
low_conf_xy_cloud->points [i].y - pose.position .y );
@@ -184,9 +187,9 @@ void RadiusSearch2dFilter::filter(
184
187
outlier.points .push_back (low_conf_input.points .at (i));
185
188
}
186
189
}
187
-
190
+ auto outlier_points_size = outlier. points . size ();
188
191
// High conf cloud check
189
- if (outlier. points . size () == 0 ) {
192
+ if (outlier_points_size == 0 ) {
190
193
return ;
191
194
}
192
195
@@ -200,7 +203,7 @@ void RadiusSearch2dFilter::filter(
200
203
std::vector<int > k_indices_high (high_conf_xy_cloud->points .size ());
201
204
std::vector<float > k_distances_high (high_conf_xy_cloud->points .size ());
202
205
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) {
204
207
const float distance = std::hypot (
205
208
high_conf_xy_cloud->points [i].x - pose.position .x ,
206
209
high_conf_xy_cloud->points [i].y - pose.position .y );
@@ -212,10 +215,11 @@ void RadiusSearch2dFilter::filter(
212
215
213
216
if (min_points_threshold <= points_num) {
214
217
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));
217
219
}
218
220
}
221
+
222
+ outlier.points .erase (outlier.points .begin (),outlier.points .begin () + outlier_points_size);
219
223
}
220
224
221
225
OccupancyGridMapOutlierFilterComponent::OccupancyGridMapOutlierFilterComponent (
@@ -277,12 +281,12 @@ void OccupancyGridMapOutlierFilterComponent::splitPointCloudFrontBack(
277
281
}
278
282
}
279
283
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);
286
290
287
291
sensor_msgs::PointCloud2Iterator<float > fr_iter (front_pc, " x" );
288
292
sensor_msgs::PointCloud2Iterator<float > be_iter (behind_pc, " x" );
0 commit comments