Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(voxel_grid_downsample_filter): performance tuning #3679

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
639c070
perf(voxel_grid_downsample_filter): change to use faster_filter
Apr 22, 2023
d904b86
perf(voxel_grid_downsample_filter): changed to not use pcl library
Apr 25, 2023
4d2ea2c
Merge remote-tracking branch 'origin' into performance_tuning_for_vox…
May 11, 2023
5fdd477
refactor: split faster_filter() into a separate class
May 15, 2023
c1ee023
style(pre-commit): autofix
pre-commit-ci[bot] May 15, 2023
940f8ba
chore: restore old filter function
May 15, 2023
67918cd
chore: rename
May 15, 2023
57dd311
refactor: split filter into multiple functions
May 16, 2023
9f382d8
refactor: improve readability
May 16, 2023
ecd67ab
style(pre-commit): autofix
pre-commit-ci[bot] May 16, 2023
56d24bc
fix: pre-commit error
May 16, 2023
6451075
fix: copyright
May 27, 2023
29c88b2
fix: add const to calc_centroid()
May 27, 2023
baf4706
Merge branch 'autowarefoundation:main' into performance_tuning_for_vo…
atsushi421 May 28, 2023
6b859ec
refactor: define TransformInfo in separate file
May 28, 2023
0e6ef57
Merge branch 'performance_tuning_for_voxel_grid_downsample_filger' of…
May 28, 2023
897b9f0
style(pre-commit): autofix
pre-commit-ci[bot] May 28, 2023
bb67ac5
refactor: improve readability
May 29, 2023
9b5fc72
chore: fix copyright
May 29, 2023
d75ded9
chore: fix copyright
May 29, 2023
9f83551
Merge remote-tracking branch 'origin' into performance_tuning_for_vox…
May 29, 2023
e5d40f0
fix: typo
May 29, 2023
8742484
Merge branch 'main' into performance_tuning_for_voxel_grid_downsample…
atsushi421 Jun 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sensing/pointcloud_preprocessor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ ament_target_dependencies(pointcloud_preprocessor_filter_base
pcl_ros
)

add_library(faster_voxel_grid_downsample_filter SHARED
src/downsample_filter/faster_voxel_grid_downsample_filter.cpp
)

target_include_directories(faster_voxel_grid_downsample_filter PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)

ament_target_dependencies(faster_voxel_grid_downsample_filter
pcl_conversions
rclcpp
sensor_msgs
)

ament_auto_add_library(pointcloud_preprocessor_filter SHARED
src/utility/utilities.cpp
src/concatenate_data/concatenate_data_nodelet.cpp
Expand All @@ -65,6 +80,7 @@ ament_auto_add_library(pointcloud_preprocessor_filter SHARED

target_link_libraries(pointcloud_preprocessor_filter
pointcloud_preprocessor_filter_base
faster_voxel_grid_downsample_filter
${Boost_LIBRARIES}
${OpenCV_LIBRARIES}
${PCL_LIBRARIES}
Expand Down Expand Up @@ -167,6 +183,13 @@ install(
RUNTIME DESTINATION bin
)

install(
TARGETS faster_voxel_grid_downsample_filter EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(
DIRECTORY include/
DESTINATION include/${PROJECT_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define POINTCLOUD_PREPROCESSOR__CROP_BOX_FILTER__CROP_BOX_FILTER_NODELET_HPP_

#include "pointcloud_preprocessor/filter.hpp"
#include "pointcloud_preprocessor/transform_info.hpp"

#include <geometry_msgs/msg/polygon_stamped.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2023 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "pointcloud_preprocessor/transform_info.hpp"

#include <pcl/filters/voxel_grid.h>
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/msg/point_cloud2.h>

#include <unordered_map>
#include <vector>

namespace pointcloud_preprocessor
{

class FasterVoxelGridDownsampleFilter
{
using PointCloud2 = sensor_msgs::msg::PointCloud2;
using PointCloud2ConstPtr = sensor_msgs::msg::PointCloud2::ConstSharedPtr;

public:
FasterVoxelGridDownsampleFilter();
void set_voxel_size(float voxel_size_x, float voxel_size_y, float voxel_size_z);
void set_field_offsets(const PointCloud2ConstPtr & input);
void filter(
const PointCloud2ConstPtr & input, PointCloud2 & output, const TransformInfo & transform_info,
const rclcpp::Logger & logger);

private:
struct Centroid
{
float x;
float y;
float z;
uint32_t point_count_;

Centroid() : x(0), y(0), z(0) {}
Centroid(float _x, float _y, float _z) : x(_x), y(_y), z(_z) { this->point_count_ = 1; }

void add_point(float _x, float _y, float _z)
{
this->x += _x;
this->y += _y;
this->z += _z;
this->point_count_++;
}

Eigen::Vector4f calc_centroid() const
{
Eigen::Vector4f centroid(
(this->x / this->point_count_), (this->y / this->point_count_),
(this->z / this->point_count_), 1.0f);
return centroid;
}
};

Eigen::Vector3f inverse_voxel_size_;
std::vector<pcl::PCLPointField> xyz_fields_;
int x_offset_;
int y_offset_;
int z_offset_;
int intensity_offset_;
bool offset_initialized_;

Eigen::Vector3f get_point_from_global_offset(
const PointCloud2ConstPtr & input, size_t global_offset);

bool get_min_max_voxel(
const PointCloud2ConstPtr & input, Eigen::Vector3i & min_voxel, Eigen::Vector3i & max_voxel);

std::unordered_map<uint32_t, Centroid> calc_centroids_each_voxel(
const PointCloud2ConstPtr & input, const Eigen::Vector3i & max_voxel,
const Eigen::Vector3i & min_voxel);

void copy_centroids_to_output(
std::unordered_map<uint32_t, Centroid> & voxel_centroid_map, PointCloud2 & output,
const TransformInfo & transform_info);
};

} // namespace pointcloud_preprocessor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tier IV, Inc.
// Copyright 2023 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,6 +52,7 @@
#define POINTCLOUD_PREPROCESSOR__DOWNSAMPLE_FILTER__VOXEL_GRID_DOWNSAMPLE_FILTER_NODELET_HPP_

#include "pointcloud_preprocessor/filter.hpp"
#include "pointcloud_preprocessor/transform_info.hpp"

#include <pcl/filters/voxel_grid.h>
#include <pcl/search/pcl_search.h>
Expand All @@ -66,10 +67,16 @@ class VoxelGridDownsampleFilterComponent : public pointcloud_preprocessor::Filte
void filter(
const PointCloud2ConstPtr & input, const IndicesPtr & indices, PointCloud2 & output) override;

// TODO(atsushi421): Temporary Implementation: Remove this interface when all the filter nodes
// conform to new API
virtual void faster_filter(
const PointCloud2ConstPtr & input, const IndicesPtr & indices, PointCloud2 & output,
const TransformInfo & transform_info);

private:
double voxel_size_x_;
double voxel_size_y_;
double voxel_size_z_;
float voxel_size_x_;
float voxel_size_y_;
float voxel_size_z_;

/** \brief Parameter service callback result : needed to be hold */
OnSetParametersCallbackHandle::SharedPtr set_param_res_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#ifndef POINTCLOUD_PREPROCESSOR__FILTER_HPP_
#define POINTCLOUD_PREPROCESSOR__FILTER_HPP_

#include "pointcloud_preprocessor/transform_info.hpp"

#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -134,18 +136,6 @@ class Filter : public rclcpp::Node
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());

protected:
struct TransformInfo
{
TransformInfo()
{
eigen_transform = Eigen::Matrix4f::Identity(4, 4);
need_transform = false;
}

Eigen::Matrix4f eigen_transform;
bool need_transform;
};

/** \brief The input PointCloud2 subscriber. */
rclcpp::Subscription<PointCloud2>::SharedPtr sub_input_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "autoware_point_types/types.hpp"
#include "pointcloud_preprocessor/filter.hpp"
#include "pointcloud_preprocessor/transform_info.hpp"

#include <point_cloud_msg_wrapper/point_cloud_msg_wrapper.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <Eigen/Eigen>

namespace pointcloud_preprocessor
{

/**
* This holds the coordinate transformation information of the point cloud.
* Usage example:
* \code
* if (transform_info.need_transform) {
* point = transform_info.eigen_transform * point;
* }
* \endcode
*/
struct TransformInfo
{
TransformInfo()
{
eigen_transform = Eigen::Matrix4f::Identity(4, 4);
need_transform = false;
}

Eigen::Matrix4f eigen_transform;
bool need_transform;
};

} // namespace pointcloud_preprocessor
Loading