Skip to content

Commit

Permalink
feat(autoware_pointcloud_preprocessor): add roi excluded downsample
Browse files Browse the repository at this point in the history
Signed-off-by: Kaan Çolak <kaancolak95@gmail.com>
  • Loading branch information
kaancolak committed Mar 5, 2025
1 parent 4649cf6 commit 1982bc7
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 1 deletion.
29 changes: 29 additions & 0 deletions sensing/autoware_pointcloud_preprocessor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ ament_target_dependencies(faster_voxel_grid_downsample_filter
sensor_msgs
)

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

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

ament_target_dependencies(roi_excluded_faster_voxel_grid_downsample_filter
pcl_conversions
rclcpp
sensor_msgs
)

ament_auto_add_library(pointcloud_preprocessor_filter SHARED
src/concatenate_data/concatenate_and_time_sync_node.cpp
src/concatenate_data/combine_cloud_handler.cpp
Expand All @@ -75,6 +90,7 @@ ament_auto_add_library(pointcloud_preprocessor_filter SHARED
src/downsample_filter/random_downsample_filter_node.cpp
src/downsample_filter/approximate_downsample_filter_node.cpp
src/downsample_filter/pickup_based_voxel_grid_downsample_filter_node.cpp
src/downsample_filter/roi_excluded_voxel_grid_downsample_filter_node.cpp
src/outlier_filter/ring_outlier_filter_node.cpp
src/outlier_filter/radius_search_2d_outlier_filter_node.cpp
src/outlier_filter/voxel_grid_outlier_filter_node.cpp
Expand All @@ -95,6 +111,7 @@ ament_auto_add_library(pointcloud_preprocessor_filter SHARED
target_link_libraries(pointcloud_preprocessor_filter
pointcloud_preprocessor_filter_base
faster_voxel_grid_downsample_filter
roi_excluded_faster_voxel_grid_downsample_filter
${Boost_LIBRARIES}
${OpenCV_LIBRARIES}
${Sophus_LIBRARIES}
Expand Down Expand Up @@ -141,6 +158,11 @@ rclcpp_components_register_node(pointcloud_preprocessor_filter
PLUGIN "autoware::pointcloud_preprocessor::ApproximateDownsampleFilterComponent"
EXECUTABLE approximate_downsample_filter_node)

# -- ROI Excluded Voxel Grid Downsample Filter --
rclcpp_components_register_node(pointcloud_preprocessor_filter
PLUGIN "autoware::pointcloud_preprocessor::RoiExcludedVoxelGridDownsampleFilterComponent"
EXECUTABLE roi_excluded_voxel_grid_downsample_filter_node)

# ========== Outlier Filter ==========
# -- Ring Outlier Filter --
rclcpp_components_register_node(pointcloud_preprocessor_filter
Expand Down Expand Up @@ -220,6 +242,13 @@ install(
RUNTIME DESTINATION bin
)

install(
TARGETS roi_excluded_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
13 changes: 13 additions & 0 deletions sensing/autoware_pointcloud_preprocessor/docs/downsample-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ The `downsample_filter` is a node that reduces the number of points.

This algorithm samples a single actual point existing within the voxel, not the centroid. The computation cost is low compared to Centroid Based Voxel Grid Filter.

### ROI Excluded Voxel Grid Downsample Filter

This filter provides selective downsampling that preserves detailed point data in critical regions while reducing overall point cloud density:

1. Points are classified based on their position relative to a defined Region of Interest (ROI)
2. Points inside the ROI are preserved at their original density (no downsampling)
3. Points outside the ROI undergo standard voxel grid downsampling
4. The final output combines both sets of points

## Inputs / Outputs

These implementations inherit `autoware::pointcloud_preprocessor::Filter` class, please refer [README](../README.md).
Expand Down Expand Up @@ -50,6 +59,10 @@ These implementations inherit `autoware::pointcloud_preprocessor::Filter` class,

{{ json_to_markdown("sensing/autoware_pointcloud_preprocessor/schema/pickup_based_voxel_grid_downsample_filter_node.schema.json") }}

### ROI Excluded Voxel Grid Downsample Filter

{{ json_to_markdown("sensing/autoware_pointcloud_preprocessor/schema/roi_excluded_voxel_grid_downsample_filter_node.schema.json") }}

## Assumptions / Known limits

<!-- cspell: ignore martinus -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2025 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 "autoware/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>
#include <limits>
#include <cfloat>
#include <cmath>
#include <Eigen/Core>

namespace autoware::pointcloud_preprocessor
{

class RoiExcludedFasterVoxelGridDownsampleFilter // renamed class
{
using PointCloud2 = sensor_msgs::msg::PointCloud2;
using PointCloud2ConstPtr = sensor_msgs::msg::PointCloud2::ConstSharedPtr;

public:
RoiExcludedFasterVoxelGridDownsampleFilter(); // renamed constructor
void set_voxel_size(float voxel_size_x, float voxel_size_y, float voxel_size_z);
void set_field_offsets(const PointCloud2ConstPtr & input, const rclcpp::Logger & logger);
void set_roi(float x_min, float x_max, float y_min, float y_max);
void filter(
const PointCloud2ConstPtr & input, PointCloud2 & output,
const TransformInfo & transform_info, const rclcpp::Logger & logger);

private:
struct Centroid
{
float x;
float y;
float z;
float intensity;
uint32_t point_count_;
Centroid() : x(0), y(0), z(0), intensity(0), point_count_(0) {}
Centroid(float _x, float _y, float _z, float _intensity)
: x(_x), y(_y), z(_z), intensity(_intensity), point_count_(1) {}
void add_point(float _x, float _y, float _z, float _intensity)
{
x += _x; y += _y; z += _z; intensity += _intensity;
point_count_++;
}
Eigen::Vector4f calc_centroid() const
{
return Eigen::Vector4f(x/point_count_, y/point_count_, z/point_count_, intensity/point_count_);
}
};

Eigen::Vector3f inverse_voxel_size_;
int x_offset_;
int y_offset_;
int z_offset_;
int intensity_index_;
int intensity_offset_;
bool offset_initialized_;
float roi_x_min_;
float roi_x_max_;
float roi_y_min_;
float roi_y_max_;

Eigen::Vector4f 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
@@ -0,0 +1,57 @@
// Copyright 2025 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.

#ifndef AUTOWARE__POINTCLOUD_PREPROCESSOR__DOWNSAMPLE_FILTER__ROI_EXCLUDED_VOXEL_GRID_DOWNSAMPLE_FILTER_NODELET_HPP_
#define AUTOWARE__POINTCLOUD_PREPROCESSOR__DOWNSAMPLE_FILTER__ROI_EXCLUDED_VOXEL_GRID_DOWNSAMPLE_FILTER_NODELET_HPP_

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

#include <rclcpp/rclcpp.hpp>
#include <rcl_interfaces/msg/set_parameters_result.hpp>

#include <mutex>
#include <vector>

namespace autoware::pointcloud_preprocessor
{
class RoiExcludedVoxelGridDownsampleFilterComponent : public Filter
{
public:
explicit RoiExcludedVoxelGridDownsampleFilterComponent(const rclcpp::NodeOptions & options);

protected:
void filter(
const PointCloud2ConstPtr & input, const IndicesPtr & indices, PointCloud2 & output) override;
void faster_filter(
const PointCloud2ConstPtr & input, const IndicesPtr & indices,
PointCloud2 & output, const TransformInfo & transform_info) override;

private:
float voxel_size_x_;
float voxel_size_y_;
float voxel_size_z_;
float roi_x_min_;
float roi_x_max_;
float roi_y_min_;
float roi_y_max_;
OnSetParametersCallbackHandle::SharedPtr set_param_res_;

rcl_interfaces::msg::SetParametersResult paramCallback(
const std::vector<rclcpp::Parameter> & parameters);
};

} // namespace pointcloud_preprocessor

#endif // AUTOWARE__POINTCLOUD_PREPROCESSOR__DOWNSAMPLE_FILTER__ROI_EXCLUDED_VOXEL_GRID_DOWNSAMPLE_FILTER_NODELET_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<launch>
<arg name="input_topic" default="/sensing/lidar/concatenated/pointcloud"/>
<arg name="output_topic" default="/sensing/lidar/pointcloud/roi_excluded_downsampled"/>
<arg name="voxel_size_x" default="0.3"/>
<arg name="voxel_size_y" default="0.3"/>
<arg name="voxel_size_z" default="0.1"/>
<arg name="roi_x_min" default="-10.0"/>
<arg name="roi_x_max" default="10.0"/>
<arg name="roi_y_min" default="-10.0"/>
<arg name="roi_y_max" default="10.0"/>

<node pkg="autoware_pointcloud_preprocessor" exec="roi_excluded_voxel_grid_downsample_filter_node" name="roi_excluded_voxel_grid_downsample_filter_node" output="screen">
<remap from="input" to="$(var input_topic)"/>
<remap from="output" to="$(var output_topic)"/>
<param name="voxel_size_x" value="$(var voxel_size_x)"/>
<param name="voxel_size_y" value="$(var voxel_size_y)"/>
<param name="voxel_size_z" value="$(var voxel_size_z)"/>
<param name="roi_x_min" value="$(var roi_x_min)"/>
<param name="roi_x_max" value="$(var roi_x_max)"/>
<param name="roi_y_min" value="$(var roi_y_min)"/>
<param name="roi_y_max" value="$(var roi_y_max)"/>
</node>
</launch>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Parameters for ROI Excluded Voxel Grid Downsample Filter",
"type": "object",
"definitions": {
"roi_excluded_voxel_grid_downsample_filter": {
"type": "object",
"properties": {
"voxel_size_x": {
"type": "number",
"description": "The size of a voxel (in meters) in X dimension",
"default": 0.3,
"minimum": 0.01
},
"voxel_size_y": {
"type": "number",
"description": "The size of a voxel (in meters) in Y dimension",
"default": 0.3,
"minimum": 0.01
},
"voxel_size_z": {
"type": "number",
"description": "The size of a voxel (in meters) in Z dimension",
"default": 0.1,
"minimum": 0.01
},
"roi_x_min": {
"type": "number",
"description": "Minimum X value of the Region of Interest (in meters)",
"default": -10.0
},
"roi_x_max": {
"type": "number",
"description": "Maximum X value of the Region of Interest (in meters)",
"default": 10.0
},
"roi_y_min": {
"type": "number",
"description": "Minimum Y value of the Region of Interest (in meters)",
"default": -10.0
},
"roi_y_max": {
"type": "number",
"description": "Maximum Y value of the Region of Interest (in meters)",
"default": 10.0
}
},
"required": [
"voxel_size_x",
"voxel_size_y",
"voxel_size_z",
"roi_x_min",
"roi_x_max",
"roi_y_min",
"roi_y_max"
],
"additionalProperties": false
}
},
"properties": {
"/**": {
"type": "object",
"properties": {
"ros__parameters": {
"$ref": "#/definitions/roi_excluded_voxel_grid_downsample_filter"
}
},
"required": ["ros__parameters"],
"additionalProperties": false
}
},
"required": ["/**"],
"additionalProperties": false
}
Loading

0 comments on commit 1982bc7

Please sign in to comment.