Skip to content

Commit

Permalink
Merge pull request #843 from tier4/feat/perception_update
Browse files Browse the repository at this point in the history
feat(voxel_grid_downsample_filter): cherry-pick and revert
  • Loading branch information
tkimura4 authored Sep 16, 2023
2 parents 5a8c980 + f7322de commit 38ea8bf
Show file tree
Hide file tree
Showing 16 changed files with 472 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<arg name="input_pointcloud" value="$(var clustering/input/pointcloud)"/>
<arg name="output_clusters" value="euclidean_cluster/clusters"/>
<arg name="use_pointcloud_map" value="false"/>
<arg name="use_downsample_pointcloud" value="$(var use_downsample_pointcloud)"/>
</include>
</group>

Expand Down Expand Up @@ -331,22 +332,11 @@
</include>
</group>

<group>
<include file="$(find-pkg-share object_merger)/launch/object_association_merger.launch.xml">
<arg name="input/object0" value="$(var lidar_detection_model)_roi_cluster_fusion/objects"/>
<arg name="input/object1" value="roi_pointcloud_fusion/objects"/>
<arg name="output/object" value="$(var lidar_detection_model)_roi_fusion/objects"/>
<arg name="priority_mode" value="0"/>
<arg name="data_association_matrix_path" value="$(var object_recognition_detection_object_merger_data_association_matrix_param_path)"/>
<arg name="distance_threshold_list_path" value="$(var object_recognition_detection_object_merger_distance_threshold_list_path)"/>
</include>
</group>

<group>
<let name="merger/output/objects" value="objects_before_filter" if="$(var use_object_filter)"/>
<let name="merger/output/objects" value="$(var output/objects)" unless="$(var use_object_filter)"/>
<include file="$(find-pkg-share object_merger)/launch/object_association_merger.launch.xml">
<arg name="input/object0" value="$(var lidar_detection_model)_roi_fusion/objects"/>
<arg name="input/object0" value="$(var lidar_detection_model)_roi_cluster_fusion/objects"/>
<arg name="input/object1" value="detection_by_tracker/objects"/>
<arg name="priority_mode" value="0"/>
<arg name="output/object" value="$(var merger/output/objects)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<arg name="score_threshold" default="0.35"/>

<arg name="use_pointcloud_map" default="true" description="use pointcloud map in detection"/>
<arg name="use_downsample_pointcloud" default="true" description="use downsample pointcloud in perception"/>
<arg name="use_object_filter" default="true" description="use object filter"/>
<arg name="use_pointcloud_container" default="false" description="use pointcloud container for detection preprocessor"/>
<arg name="use_validator" default="true" description="use obstacle_pointcloud based validator"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<arg name="output/objects" default="objects"/>
<arg name="lidar_detection_model" default="centerpoint" description="options: `centerpoint`, `apollo`, `clustering`"/>
<arg name="use_pointcloud_map" default="true" description="use pointcloud map in detection"/>
<arg name="use_downsample_pointcloud" default="true" description="use downsample pointcloud in perception"/>
<arg name="use_object_filter" default="true" description="use object filter"/>
<arg name="use_pointcloud_container" default="false" description="use pointcloud container for detection preprocessor"/>
<arg name="container_name" default="pointcloud_container"/>
Expand Down Expand Up @@ -33,6 +34,7 @@
<arg name="input_pointcloud" value="$(var clustering/input/pointcloud)"/>
<arg name="output_clusters" value="clusters"/>
<arg name="use_pointcloud_map" value="false"/>
<arg name="use_downsample_pointcloud" value="$(var use_downsample_pointcloud)"/>
</include>
</group>

Expand Down
2 changes: 2 additions & 0 deletions launch/tier4_perception_launch/launch/perception.launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<arg name="image_number" default="6" description="choose image raw number(1-8)"/>
<arg name="use_vector_map" default="true" description="use vector map in prediction"/>
<arg name="use_pointcloud_map" default="true" description="use pointcloud map in detection"/>
<arg name="use_downsample_pointcloud" default="false" description="use downsample pointcloud in perception"/>
<arg name="use_object_filter" default="true" description="use object filter"/>
<arg
name="use_empty_dynamic_object_publisher"
Expand Down Expand Up @@ -145,6 +146,7 @@
<arg name="voxel_grid_param_path" value="$(var object_recognition_detection_voxel_grid_based_euclidean_param_path)"/>
<arg name="voxel_grid_based_euclidean_param_path" value="$(var object_recognition_detection_voxel_grid_based_euclidean_cluster_param_path)"/>
<arg name="use_pointcloud_map" value="$(var use_pointcloud_map)"/>
<arg name="use_downsample_pointcloud" value="$(var use_downsample_pointcloud)"/>
<arg name="use_object_filter" value="$(var use_object_filter)"/>
<arg name="use_pointcloud_container" value="$(var use_pointcloud_container)"/>
<arg name="container_name" value="$(var pointcloud_container_name)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
from launch.actions import DeclareLaunchArgument
from launch.actions import OpaqueFunction
from launch.conditions import IfCondition
from launch.conditions import UnlessCondition
from launch.substitutions import AndSubstitution
from launch.substitutions import AnonName
from launch.substitutions import LaunchConfiguration
from launch.substitutions import NotSubstitution
from launch_ros.actions import ComposableNodeContainer
from launch_ros.actions import LoadComposableNodes
from launch_ros.descriptions import ComposableNode
Expand Down Expand Up @@ -164,7 +165,7 @@ def load_composable_node_param(param_path):
)

# set euclidean cluster as a component
euclidean_cluster_component = ComposableNode(
use_downsample_euclidean_cluster_component = ComposableNode(
package=pkg,
namespace=ns,
plugin="euclidean_cluster::VoxelGridBasedEuclideanClusterNode",
Expand All @@ -176,40 +177,108 @@ def load_composable_node_param(param_path):
parameters=[load_composable_node_param("voxel_grid_based_euclidean_param_path")],
)

use_map_disuse_downsample_euclidean_component = ComposableNode(
package=pkg,
namespace=ns,
plugin="euclidean_cluster::VoxelGridBasedEuclideanClusterNode",
name="euclidean_cluster",
remappings=[
("input", "map_filter/pointcloud"),
("output", LaunchConfiguration("output_clusters")),
],
parameters=[load_composable_node_param("voxel_grid_based_euclidean_param_path")],
)
disuse_map_disuse_downsample_euclidean_component = ComposableNode(
package=pkg,
namespace=ns,
plugin="euclidean_cluster::VoxelGridBasedEuclideanClusterNode",
name="euclidean_cluster",
remappings=[
("input", LaunchConfiguration("input_pointcloud")),
("output", LaunchConfiguration("output_clusters")),
],
parameters=[load_composable_node_param("voxel_grid_based_euclidean_param_path")],
)

container = ComposableNodeContainer(
name="euclidean_cluster_container",
package="rclcpp_components",
namespace=ns,
executable="component_container",
composable_node_descriptions=[
voxel_grid_filter_component,
outlier_filter_component,
downsample_concat_component,
euclidean_cluster_component,
],
composable_node_descriptions=[],
output="screen",
)

use_map_loader = LoadComposableNodes(
use_map_use_downsample_loader = LoadComposableNodes(
composable_node_descriptions=[
compare_map_filter_component,
use_map_short_range_crop_box_filter_component,
use_map_long_range_crop_box_filter_component,
voxel_grid_filter_component,
outlier_filter_component,
downsample_concat_component,
use_downsample_euclidean_cluster_component,
],
target_container=container,
condition=IfCondition(LaunchConfiguration("use_pointcloud_map")),
condition=IfCondition(
AndSubstitution(
LaunchConfiguration("use_pointcloud_map"),
LaunchConfiguration("use_downsample_pointcloud"),
)
),
)

disuse_map_loader = LoadComposableNodes(
disuse_map_use_downsample_loader = LoadComposableNodes(
composable_node_descriptions=[
disuse_map_short_range_crop_box_filter_component,
disuse_map_long_range_crop_box_filter_component,
voxel_grid_filter_component,
outlier_filter_component,
downsample_concat_component,
use_downsample_euclidean_cluster_component,
],
target_container=container,
condition=UnlessCondition(LaunchConfiguration("use_pointcloud_map")),
condition=IfCondition(
AndSubstitution(
NotSubstitution(LaunchConfiguration("use_pointcloud_map")),
LaunchConfiguration("use_downsample_pointcloud"),
)
),
)

return [container, use_map_loader, disuse_map_loader]
use_map_disuse_downsample_loader = LoadComposableNodes(
composable_node_descriptions=[
compare_map_filter_component,
use_map_disuse_downsample_euclidean_component,
],
target_container=container,
condition=IfCondition(
AndSubstitution(
(LaunchConfiguration("use_pointcloud_map")),
NotSubstitution(LaunchConfiguration("use_downsample_pointcloud")),
)
),
)

disuse_map_disuse_downsample_loader = LoadComposableNodes(
composable_node_descriptions=[
disuse_map_disuse_downsample_euclidean_component,
],
target_container=container,
condition=IfCondition(
AndSubstitution(
NotSubstitution(LaunchConfiguration("use_pointcloud_map")),
NotSubstitution(LaunchConfiguration("use_downsample_pointcloud")),
)
),
)
return [
container,
use_map_use_downsample_loader,
disuse_map_use_downsample_loader,
use_map_disuse_downsample_loader,
disuse_map_disuse_downsample_loader,
]


def generate_launch_description():
Expand All @@ -222,6 +291,7 @@ def add_launch_arg(name: str, default_value=None):
add_launch_arg("input_map", "/map/pointcloud_map"),
add_launch_arg("output_clusters", "clusters"),
add_launch_arg("use_pointcloud_map", "false"),
add_launch_arg("use_downsample_pointcloud", "false"),
add_launch_arg(
"voxel_grid_param_path",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<arg name="input_map" default="/map/pointcloud_map"/>
<arg name="output_clusters" default="clusters"/>
<arg name="use_pointcloud_map" default="false"/>
<arg name="use_downsample_pointcloud" default="false"/>
<arg name="voxel_grid_param_path" default="$(find-pkg-share euclidean_cluster)/config/voxel_grid.param.yaml"/>
<arg name="compare_map_param_path" default="$(find-pkg-share euclidean_cluster)/config/compare_map.param.yaml"/>
<arg name="outlier_param_path" default="$(find-pkg-share euclidean_cluster)/config/outlier.param.yaml"/>
Expand All @@ -14,6 +15,7 @@
<arg name="input_map" value="$(var input_map)"/>
<arg name="output_clusters" value="$(var output_clusters)"/>
<arg name="use_pointcloud_map" value="$(var use_pointcloud_map)"/>
<arg name="use_downsample_pointcloud" value="$(var use_downsample_pointcloud)"/>
<arg name="voxel_grid_param_path" value="$(var voxel_grid_param_path)"/>
<arg name="compare_map_param_path" value="$(var compare_map_param_path)"/>
<arg name="outlier_param_path" value="$(var outlier_param_path)"/>
Expand Down
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_and_time_sync_nodelet.cpp
Expand All @@ -67,6 +82,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 @@ -179,6 +195,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
Loading

0 comments on commit 38ea8bf

Please sign in to comment.