-
Notifications
You must be signed in to change notification settings - Fork 672
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
atsushi421
merged 23 commits into
autowarefoundation:main
from
atsushi421:performance_tuning_for_voxel_grid_downsample_filger
Jun 23, 2023
Merged
Changes from 21 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
d904b86
perf(voxel_grid_downsample_filter): changed to not use pcl library
4d2ea2c
Merge remote-tracking branch 'origin' into performance_tuning_for_vox…
5fdd477
refactor: split faster_filter() into a separate class
c1ee023
style(pre-commit): autofix
pre-commit-ci[bot] 940f8ba
chore: restore old filter function
67918cd
chore: rename
57dd311
refactor: split filter into multiple functions
9f382d8
refactor: improve readability
ecd67ab
style(pre-commit): autofix
pre-commit-ci[bot] 56d24bc
fix: pre-commit error
6451075
fix: copyright
29c88b2
fix: add const to calc_centroid()
baf4706
Merge branch 'autowarefoundation:main' into performance_tuning_for_vo…
atsushi421 6b859ec
refactor: define TransformInfo in separate file
0e6ef57
Merge branch 'performance_tuning_for_voxel_grid_downsample_filger' of…
897b9f0
style(pre-commit): autofix
pre-commit-ci[bot] bb67ac5
refactor: improve readability
9b5fc72
chore: fix copyright
d75ded9
chore: fix copyright
9f83551
Merge remote-tracking branch 'origin' into performance_tuning_for_vox…
e5d40f0
fix: typo
8742484
Merge branch 'main' into performance_tuning_for_voxel_grid_downsample…
atsushi421 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...include/pointcloud_preprocessor/downsample_filter/faster_voxel_grid_dowmsample_filter.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
sensing/pointcloud_preprocessor/include/pointcloud_preprocessor/transform_info.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in filename: dowNsample