Skip to content

Commit e7b452b

Browse files
takanotaigapre-commit-ci[bot]YoshiRi
authored and
j4tfwm6z
committed
perf(occupancy_grid_map_outlier_filter): improve performance (autowarefoundation#5980)
* improve perfomance Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> * style(pre-commit): autofix Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> * fixed the bug and corrected the spelling mistake. Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> * style(pre-commit): autofix Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> * fix bug Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> * style(pre-commit): autofix Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> * change filter Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> --------- Signed-off-by: Taiga Takano <ttttghghnb554z@outlook.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Yoshi Ri <yoshiyoshidetteiu@gmail.com>
1 parent 4d4bd9e commit e7b452b

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

perception/occupancy_grid_map_outlier_filter/src/occupancy_grid_map_outlier_filter_nodelet.cpp

+32-9
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,42 @@ OccupancyGridMapOutlierFilterComponent::OccupancyGridMapOutlierFilterComponent(
239239
void OccupancyGridMapOutlierFilterComponent::splitPointCloudFrontBack(
240240
const PointCloud2::ConstSharedPtr & input_pc, PointCloud2 & front_pc, PointCloud2 & behind_pc)
241241
{
242-
PclPointCloud tmp_behind_pc;
243-
PclPointCloud tmp_front_pc;
244-
for (sensor_msgs::PointCloud2ConstIterator<float> x(*input_pc, "x"), y(*input_pc, "y"),
245-
z(*input_pc, "z");
246-
x != x.end(); ++x, ++y, ++z) {
242+
size_t front_count = 0;
243+
size_t behind_count = 0;
244+
245+
for (sensor_msgs::PointCloud2ConstIterator<float> x(*input_pc, "x"); x != x.end(); ++x) {
247246
if (*x < 0.0) {
248-
tmp_behind_pc.push_back(pcl::PointXYZ(*x, *y, *z));
247+
behind_count++;
249248
} else {
250-
tmp_front_pc.push_back(pcl::PointXYZ(*x, *y, *z));
249+
front_count++;
251250
}
252251
}
253-
pcl::toROSMsg(tmp_front_pc, front_pc);
254-
pcl::toROSMsg(tmp_behind_pc, behind_pc);
252+
253+
sensor_msgs::PointCloud2Modifier front_pc_modifier(front_pc);
254+
sensor_msgs::PointCloud2Modifier behind_pc_modifier(behind_pc);
255+
front_pc_modifier.setPointCloud2FieldsByString(1, "xyz");
256+
behind_pc_modifier.setPointCloud2FieldsByString(1, "xyz");
257+
front_pc_modifier.resize(front_count);
258+
behind_pc_modifier.resize(behind_count);
259+
260+
sensor_msgs::PointCloud2Iterator<float> fr_iter(front_pc, "x");
261+
sensor_msgs::PointCloud2Iterator<float> be_iter(behind_pc, "x");
262+
263+
for (sensor_msgs::PointCloud2ConstIterator<float> in_iter(*input_pc, "x");
264+
in_iter != in_iter.end(); ++in_iter) {
265+
if (*in_iter < 0.0) {
266+
*be_iter = in_iter[0];
267+
be_iter[1] = in_iter[1];
268+
be_iter[2] = in_iter[2];
269+
++be_iter;
270+
} else {
271+
*fr_iter = in_iter[0];
272+
fr_iter[1] = in_iter[1];
273+
fr_iter[2] = in_iter[2];
274+
++fr_iter;
275+
}
276+
}
277+
255278
front_pc.header = input_pc->header;
256279
behind_pc.header = input_pc->header;
257280
}

0 commit comments

Comments
 (0)