Skip to content

Commit 9271b94

Browse files
style(pre-commit): autofix
1 parent 1b2c7a5 commit 9271b94

File tree

5 files changed

+71
-104
lines changed

5 files changed

+71
-104
lines changed

sensing/autoware_crop_box_filter/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ ament_auto_package(INSTALL_TO_SHARE
2626
launch
2727
config
2828
)
29-
30-

sensing/autoware_crop_box_filter/README.md

+22-23
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,40 @@ The `autoware_crop_box_filter` is implemented as a autoware core node that subsc
1212

1313
### Input
1414

15-
| Name | Type | Description |
16-
| ----------------- | ------------------------------- | ----------------- |
17-
| `~/input/points` | `sensor_msgs::msg::PointCloud2` | reference points |
15+
| Name | Type | Description |
16+
| ---------------- | ------------------------------- | ---------------- |
17+
| `~/input/points` | `sensor_msgs::msg::PointCloud2` | reference points |
1818

1919
### Output
2020

21-
| Name | Type | Description |
22-
| ----------------- | ------------------------------- | --------------- |
23-
| `~/output/points` | `sensor_msgs::msg::PointCloud2` | filtered points |
21+
| Name | Type | Description |
22+
| -------------------- | ------------------------------------ | -------------------- |
23+
| `~/output/points` | `sensor_msgs::msg::PointCloud2` | filtered points |
2424
| `~/crop_box_polygon` | `geometry_msgs::msg::PolygonStamped` | bounding box polygon |
2525

2626
## Parameters
2727

2828
### Launch file Parameters
2929

30-
| Name | Type | Default Value | Description |
31-
| ------------------ | ------ | ------------- | ------------------------------------- |
32-
| `input_frame` | string | " " | the frame id in which filtering is performed |
33-
| `output_frame` | string | " " | output frame id of the filtered points |
34-
| `input_pointcloud_frame` | string | " " | frame id of input pointcloud |
35-
| `max_queue_size` | int | 5 | max buffer size of input/output topics |
36-
| `crop_box_filter_param_file` | string | " " | path to the parameter file for the node |
37-
30+
| Name | Type | Default Value | Description |
31+
| ---------------------------- | ------ | ------------- | -------------------------------------------- |
32+
| `input_frame` | string | " " | the frame id in which filtering is performed |
33+
| `output_frame` | string | " " | output frame id of the filtered points |
34+
| `input_pointcloud_frame` | string | " " | frame id of input pointcloud |
35+
| `max_queue_size` | int | 5 | max buffer size of input/output topics |
36+
| `crop_box_filter_param_file` | string | " " | path to the parameter file for the node |
3837

3938
### Node Parameters
4039

41-
| Name | Type | Default Value | Description |
42-
| ------------------ | ------ | ------------- | ------------------------------------- |
43-
| `min_x` | double | -5.0 | minimum x value of the crop box |
44-
| `min_y` | double | -5.0 | minimum y value of the crop box |
45-
| `min_z` | double | -5.0 | minimum z value of the crop box |
46-
| `max_x` | double | 5.0 | maximum x value of the crop box |
47-
| `max_y` | double | 5.0 | maximum y value of the crop box |
48-
| `max_z` | double | 5.0 | maximum z value of the crop box |
49-
| `negative` | bool | true | if true, points inside the box are removed, otherwise points outside the box are removed |
40+
| Name | Type | Default Value | Description |
41+
| ---------- | ------ | ------------- | ---------------------------------------------------------------------------------------- |
42+
| `min_x` | double | -5.0 | minimum x value of the crop box |
43+
| `min_y` | double | -5.0 | minimum y value of the crop box |
44+
| `min_z` | double | -5.0 | minimum z value of the crop box |
45+
| `max_x` | double | 5.0 | maximum x value of the crop box |
46+
| `max_y` | double | 5.0 | maximum y value of the crop box |
47+
| `max_z` | double | 5.0 | maximum z value of the crop box |
48+
| `negative` | bool | true | if true, points inside the box are removed, otherwise points outside the box are removed |
5049

5150
## Usage
5251

sensing/autoware_crop_box_filter/include/autoware/crop_box_filter/crop_box_filter_node.hpp

+16-20
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,33 @@
5555
#ifndef AUTOWARE__CROP_BOX_FILTER__CROP_BOX_FILTER_NODE_HPP_
5656
#define AUTOWARE__CROP_BOX_FILTER__CROP_BOX_FILTER_NODE_HPP_
5757

58-
#include <geometry_msgs/msg/polygon_stamped.hpp>
59-
#include <sensor_msgs/msg/point_cloud2.hpp>
60-
#include <sensor_msgs/point_cloud2_iterator.hpp>
61-
58+
#include <autoware/point_types/types.hpp>
6259
#include <autoware_utils/ros/debug_publisher.hpp>
6360
#include <autoware_utils/ros/managed_transform_buffer.hpp>
6461
#include <autoware_utils/ros/published_time_publisher.hpp>
6562
#include <autoware_utils/system/stop_watch.hpp>
6663

67-
#include <autoware/point_types/types.hpp>
64+
#include <geometry_msgs/msg/polygon_stamped.hpp>
65+
#include <sensor_msgs/msg/point_cloud2.hpp>
66+
#include <sensor_msgs/point_cloud2_iterator.hpp>
6867

6968
#include <memory>
70-
#include <vector>
7169
#include <string>
7270
#include <utility>
71+
#include <vector>
7372

7473
namespace autoware::crop_box_filter
7574
{
7675
class CropBoxFilter : public rclcpp::Node
7776
{
77+
using PointCloud2 = sensor_msgs::msg::PointCloud2;
78+
using PointCloud2ConstPtr = sensor_msgs::msg::PointCloud2::ConstSharedPtr;
7879

79-
using PointCloud2 = sensor_msgs::msg::PointCloud2;
80-
using PointCloud2ConstPtr = sensor_msgs::msg::PointCloud2::ConstSharedPtr;
81-
82-
using PointCloud = pcl::PointCloud<pcl::PointXYZ>;
83-
using PointCloudPtr = PointCloud::Ptr;
84-
using PointCloudConstPtr = PointCloud::ConstPtr;
80+
using PointCloud = pcl::PointCloud<pcl::PointXYZ>;
81+
using PointCloudPtr = PointCloud::Ptr;
82+
using PointCloudConstPtr = PointCloud::ConstPtr;
8583

8684
private:
87-
8885
// member variable declaration & definitions *************************************
8986

9087
/** \brief The managed transform buffer. */
@@ -141,16 +138,16 @@ using PointCloudConstPtr = PointCloud::ConstPtr;
141138
std::unique_ptr<autoware_utils::PublishedTimePublisher> published_time_publisher_;
142139

143140
// function declaration *************************************
144-
141+
145142
void publish_crop_box_polygon();
146-
143+
147144
void pointcloud_callback(const PointCloud2ConstPtr cloud);
148145

149146
/** \brief Parameter service callback */
150147
rcl_interfaces::msg::SetParametersResult param_callback(const std::vector<rclcpp::Parameter> & p);
151148

152-
/** \brief Return whether the input PointCloud2 data has the same layout than PointXYZI. That is to
153-
* say whether you can memcpy from the PointCloud2 data buffer to a PointXYZI */
149+
/** \brief Return whether the input PointCloud2 data has the same layout than PointXYZI. That is
150+
* to say whether you can memcpy from the PointCloud2 data buffer to a PointXYZI */
154151
bool is_data_layout_compatible_with_point_xyzi(const PointCloud2 & input);
155152

156153
/** \brief Return whether the input PointCloud2 data has the same layout than PointXYZIRC. That is
@@ -161,8 +158,8 @@ using PointCloudConstPtr = PointCloud::ConstPtr;
161158
* is to say whether you can memcpy from the PointCloud2 data buffer to a PointXYZIRADRT */
162159
bool is_data_layout_compatible_with_point_xyziradrt(const PointCloud2 & input);
163160

164-
/** \brief Return whether the input PointCloud2 data has the same layout than PointXYZIRCAEDT. That
165-
* is to say whether you can memcpy from the PointCloud2 data buffer to a PointXYZIRCAEDT */
161+
/** \brief Return whether the input PointCloud2 data has the same layout than PointXYZIRCAEDT.
162+
* That is to say whether you can memcpy from the PointCloud2 data buffer to a PointXYZIRCAEDT */
166163
bool is_data_layout_compatible_with_point_xyzircaedt(const PointCloud2 & input);
167164

168165
bool is_valid(const PointCloud2ConstPtr & cloud);
@@ -180,7 +177,6 @@ using PointCloudConstPtr = PointCloud::ConstPtr;
180177
}
181178
return false;
182179
}
183-
184180

185181
public:
186182
PCL_MAKE_ALIGNED_OPERATOR_NEW

sensing/autoware_crop_box_filter/package.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<maintainer email="lxg19892021@gmail.com">Xingang Liu</maintainer>
1818
<license>Apache License 2.0</license>
1919

20-
2120
<!-- Original authors -->
2221
<author>Open Perception</author>
2322
<author email="julius@kammerl.de">Julius Kammerl</author>
@@ -28,10 +27,10 @@
2827

2928
<depend>autoware_point_types</depend>
3029
<depend>autoware_utils</depend>
30+
<depend>geometry_msgs</depend>
3131
<depend>rclcpp</depend>
3232
<depend>rclcpp_components</depend>
3333
<depend>sensor_msgs</depend>
34-
<depend>geometry_msgs</depend>
3534

3635
<test_depend>ament_lint_auto</test_depend>
3736
<test_depend>autoware_lint_common</test_depend>

sensing/autoware_crop_box_filter/src/crop_box_filter_node.cpp

+32-57
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@
5252
*/
5353

5454
#include "autoware/crop_box_filter/crop_box_filter_node.hpp"
55+
5556
#include <memory>
56-
#include <vector>
5757
#include <string>
5858
#include <utility>
59+
#include <vector>
5960

6061
namespace autoware::crop_box_filter
6162
{
@@ -78,60 +79,47 @@ CropBoxFilter::CropBoxFilter(const rclcpp::NodeOptions & node_options)
7879

7980
// get transform info for pointcloud
8081
{
81-
82-
tf_input_orig_frame_ = static_cast<std::string>(declare_parameter("input_pointcloud_frame", "base_link"));
82+
tf_input_orig_frame_ =
83+
static_cast<std::string>(declare_parameter("input_pointcloud_frame", "base_link"));
8384
tf_input_frame_ = static_cast<std::string>(declare_parameter("input_frame", "base_link"));
8485
tf_output_frame_ = static_cast<std::string>(declare_parameter("output_frame", "base_link"));
8586

8687
// Always consider static TF if in & out frames are same
8788
bool has_static_tf_only = false;
8889
if (tf_input_frame_ == tf_output_frame_) {
89-
9090
RCLCPP_INFO(
9191
this->get_logger(),
9292
"Input and output frames are the same. Overriding has_static_tf_only to true.");
93-
93+
9494
has_static_tf_only = true;
9595
}
9696
managed_tf_buffer_ =
9797
std::make_unique<autoware_utils::ManagedTransformBuffer>(this, has_static_tf_only);
9898

99-
100-
if (tf_input_orig_frame_ == tf_input_frame_)
101-
{
99+
if (tf_input_orig_frame_ == tf_input_frame_) {
102100
need_preprocess_transform_ = false;
103101
eigen_transform_preprocess_ = Eigen::Matrix4f::Identity(4, 4);
104-
}
105-
else
106-
{
102+
} else {
107103
if (!managed_tf_buffer_->get_transform(
108-
tf_input_frame_, tf_input_orig_frame_, eigen_transform_preprocess_))
109-
{
104+
tf_input_frame_, tf_input_orig_frame_, eigen_transform_preprocess_)) {
110105
RCLCPP_ERROR(
111-
this->get_logger(),
112-
"Cannot get transform from %s to %s. Please check your TF tree.",tf_input_orig_frame_.c_str() , tf_input_frame_.c_str());
113-
}
114-
else
115-
{
106+
this->get_logger(), "Cannot get transform from %s to %s. Please check your TF tree.",
107+
tf_input_orig_frame_.c_str(), tf_input_frame_.c_str());
108+
} else {
116109
need_preprocess_transform_ = true;
117110
}
118111
}
119112

120-
if (tf_input_frame_ == tf_output_frame_)
121-
{
113+
if (tf_input_frame_ == tf_output_frame_) {
122114
need_postprocess_transform_ = false;
123115
eigen_transform_postprocess_ = Eigen::Matrix4f::Identity(4, 4);
124-
}else
125-
{
116+
} else {
126117
if (!managed_tf_buffer_->get_transform(
127-
tf_output_frame_, tf_input_frame_, eigen_transform_postprocess_))
128-
{
118+
tf_output_frame_, tf_input_frame_, eigen_transform_postprocess_)) {
129119
RCLCPP_ERROR(
130-
this->get_logger(),
131-
"Cannot get transform from %s to %s. Please check your TF tree.",tf_input_frame_.c_str() , tf_output_frame_.c_str());
132-
}
133-
else
134-
{
120+
this->get_logger(), "Cannot get transform from %s to %s. Please check your TF tree.",
121+
tf_input_frame_.c_str(), tf_output_frame_.c_str());
122+
} else {
135123
need_postprocess_transform_ = true;
136124
}
137125
}
@@ -170,31 +158,26 @@ CropBoxFilter::CropBoxFilter(const rclcpp::NodeOptions & node_options)
170158
// set parameter service callback
171159
{
172160
using std::placeholders::_1;
173-
set_param_res_ = this->add_on_set_parameters_callback(
174-
std::bind(&CropBoxFilter::param_callback, this, _1));
161+
set_param_res_ =
162+
this->add_on_set_parameters_callback(std::bind(&CropBoxFilter::param_callback, this, _1));
175163
}
176164

177165
// set input pointcloud callback
178166
{
179167
sub_input_ = this->create_subscription<PointCloud2>(
180-
"input", rclcpp::SensorDataQoS().keep_last(max_queue_size_),
168+
"input", rclcpp::SensorDataQoS().keep_last(max_queue_size_),
181169
std::bind(&CropBoxFilter::pointcloud_callback, this, std::placeholders::_1));
182170
}
183171

184-
185172
RCLCPP_DEBUG(this->get_logger(), "[Filter Constructor] successfully created.");
186173
}
187174

188-
189-
190-
191175
void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
192176
{
193177
// check whether the pointcloud is valid
194178
if (
195179
!is_data_layout_compatible_with_point_xyzircaedt(*cloud) &&
196-
!is_data_layout_compatible_with_point_xyzirc(*cloud))
197-
{
180+
!is_data_layout_compatible_with_point_xyzirc(*cloud)) {
198181
RCLCPP_ERROR(
199182
get_logger(),
200183
"The pointcloud layout is not compatible with PointXYZIRCAEDT or PointXYZIRC. Aborting");
@@ -227,14 +210,13 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
227210
"received.",
228211
cloud->width * cloud->height, cloud->header.frame_id.c_str());
229212
// pointcloud check finished
230-
213+
231214
// pointcloud processing
232215
auto output = PointCloud2();
233216

234217
std::scoped_lock lock(mutex_);
235218
stop_watch_ptr_->toc("processing_time", true);
236219

237-
238220
int x_offset = cloud->fields[pcl::getFieldIndex(*cloud, "x")].offset;
239221
int y_offset = cloud->fields[pcl::getFieldIndex(*cloud, "y")].offset;
240222
int z_offset = cloud->fields[pcl::getFieldIndex(*cloud, "z")].offset;
@@ -246,8 +228,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
246228

247229
// pointcloud processing loop
248230
for (size_t global_offset = 0; global_offset + cloud->point_step <= cloud->data.size();
249-
global_offset += cloud->point_step)
250-
{
231+
global_offset += cloud->point_step) {
251232
Eigen::Vector4f point;
252233
Eigen::Vector4f point_preprocessed;
253234
std::memcpy(&point[0], &cloud->data[global_offset + x_offset], sizeof(float));
@@ -270,22 +251,18 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
270251
point[1] > param_.min_y && point[1] < param_.max_y &&
271252
point[0] > param_.min_x && point[0] < param_.max_x;
272253
if ((!param_.negative && point_is_inside) || (param_.negative && !point_is_inside)) {
273-
274254
// apply post-transform if needed
275-
if(need_postprocess_transform_)
276-
{
277-
if(need_preprocess_transform_)
278-
{
255+
if (need_postprocess_transform_) {
256+
if (need_preprocess_transform_) {
279257
Eigen::Vector4f point_postprocessed = eigen_transform_postprocess_ * point_preprocessed;
280258

281259
memcpy(&output.data[output_size], &cloud->data[global_offset], cloud->point_step);
282260

283261
std::memcpy(&output.data[output_size + x_offset], &point_postprocessed[0], sizeof(float));
284262
std::memcpy(&output.data[output_size + y_offset], &point_postprocessed[1], sizeof(float));
285263
std::memcpy(&output.data[output_size + z_offset], &point_postprocessed[2], sizeof(float));
286-
287-
}else
288-
{
264+
265+
} else {
289266
Eigen::Vector4f point_postprocessed = eigen_transform_postprocess_ * point;
290267

291268
memcpy(&output.data[output_size], &cloud->data[global_offset], cloud->point_step);
@@ -294,9 +271,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
294271
std::memcpy(&output.data[output_size + y_offset], &point_postprocessed[1], sizeof(float));
295272
std::memcpy(&output.data[output_size + z_offset], &point_postprocessed[2], sizeof(float));
296273
}
297-
}
298-
else
299-
{
274+
} else {
300275
memcpy(&output.data[output_size], &cloud->data[global_offset], cloud->point_step);
301276

302277
if (need_preprocess_transform_) {
@@ -329,8 +304,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
329304
output.row_step = static_cast<uint32_t>(output.data.size() / output.height);
330305

331306
// publish polygon if subscribers exist
332-
if(crop_box_polygon_pub_->get_subscription_count() > 0)
333-
{
307+
if (crop_box_polygon_pub_->get_subscription_count() > 0) {
334308
publish_crop_box_polygon();
335309
}
336310

@@ -423,7 +397,8 @@ rcl_interfaces::msg::SetParametersResult CropBoxFilter::param_callback(
423397
new_param.max_x = get_param(p, "max_x", new_param.max_x) ? new_param.max_x : param_.max_x;
424398
new_param.max_y = get_param(p, "max_y", new_param.max_y) ? new_param.max_y : param_.max_y;
425399
new_param.max_z = get_param(p, "max_z", new_param.max_z) ? new_param.max_z : param_.max_z;
426-
new_param.negative = get_param(p, "negative", new_param.negative) ? new_param.negative : param_.negative;
400+
new_param.negative =
401+
get_param(p, "negative", new_param.negative) ? new_param.negative : param_.negative;
427402

428403
param_ = new_param;
429404

@@ -624,7 +599,7 @@ bool CropBoxFilter::is_data_layout_compatible_with_point_xyzircaedt(const PointC
624599
return same_layout;
625600
}
626601

627-
bool CropBoxFilter::is_valid( const PointCloud2ConstPtr & cloud)
602+
bool CropBoxFilter::is_valid(const PointCloud2ConstPtr & cloud)
628603
{
629604
if (cloud->width * cloud->height * cloud->point_step != cloud->data.size()) {
630605
RCLCPP_WARN(

0 commit comments

Comments
 (0)