52
52
*/
53
53
54
54
#include " autoware/crop_box_filter/crop_box_filter_node.hpp"
55
+
55
56
#include < memory>
56
- #include < vector>
57
57
#include < string>
58
58
#include < utility>
59
+ #include < vector>
59
60
60
61
namespace autoware ::crop_box_filter
61
62
{
@@ -78,60 +79,47 @@ CropBoxFilter::CropBoxFilter(const rclcpp::NodeOptions & node_options)
78
79
79
80
// get transform info for pointcloud
80
81
{
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" ));
83
84
tf_input_frame_ = static_cast <std::string>(declare_parameter (" input_frame" , " base_link" ));
84
85
tf_output_frame_ = static_cast <std::string>(declare_parameter (" output_frame" , " base_link" ));
85
86
86
87
// Always consider static TF if in & out frames are same
87
88
bool has_static_tf_only = false ;
88
89
if (tf_input_frame_ == tf_output_frame_) {
89
-
90
90
RCLCPP_INFO (
91
91
this ->get_logger (),
92
92
" Input and output frames are the same. Overriding has_static_tf_only to true." );
93
-
93
+
94
94
has_static_tf_only = true ;
95
95
}
96
96
managed_tf_buffer_ =
97
97
std::make_unique<autoware_utils::ManagedTransformBuffer>(this , has_static_tf_only);
98
98
99
-
100
- if (tf_input_orig_frame_ == tf_input_frame_)
101
- {
99
+ if (tf_input_orig_frame_ == tf_input_frame_) {
102
100
need_preprocess_transform_ = false ;
103
101
eigen_transform_preprocess_ = Eigen::Matrix4f::Identity (4 , 4 );
104
- }
105
- else
106
- {
102
+ } else {
107
103
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_)) {
110
105
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 {
116
109
need_preprocess_transform_ = true ;
117
110
}
118
111
}
119
112
120
- if (tf_input_frame_ == tf_output_frame_)
121
- {
113
+ if (tf_input_frame_ == tf_output_frame_) {
122
114
need_postprocess_transform_ = false ;
123
115
eigen_transform_postprocess_ = Eigen::Matrix4f::Identity (4 , 4 );
124
- }else
125
- {
116
+ } else {
126
117
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_)) {
129
119
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 {
135
123
need_postprocess_transform_ = true ;
136
124
}
137
125
}
@@ -170,31 +158,26 @@ CropBoxFilter::CropBoxFilter(const rclcpp::NodeOptions & node_options)
170
158
// set parameter service callback
171
159
{
172
160
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));
175
163
}
176
164
177
165
// set input pointcloud callback
178
166
{
179
167
sub_input_ = this ->create_subscription <PointCloud2>(
180
- " input" , rclcpp::SensorDataQoS ().keep_last (max_queue_size_),
168
+ " input" , rclcpp::SensorDataQoS ().keep_last (max_queue_size_),
181
169
std::bind (&CropBoxFilter::pointcloud_callback, this , std::placeholders::_1));
182
170
}
183
171
184
-
185
172
RCLCPP_DEBUG (this ->get_logger (), " [Filter Constructor] successfully created." );
186
173
}
187
174
188
-
189
-
190
-
191
175
void CropBoxFilter::pointcloud_callback (const PointCloud2ConstPtr cloud)
192
176
{
193
177
// check whether the pointcloud is valid
194
178
if (
195
179
!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)) {
198
181
RCLCPP_ERROR (
199
182
get_logger (),
200
183
" The pointcloud layout is not compatible with PointXYZIRCAEDT or PointXYZIRC. Aborting" );
@@ -227,14 +210,13 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
227
210
" received." ,
228
211
cloud->width * cloud->height , cloud->header .frame_id .c_str ());
229
212
// pointcloud check finished
230
-
213
+
231
214
// pointcloud processing
232
215
auto output = PointCloud2 ();
233
216
234
217
std::scoped_lock lock (mutex_);
235
218
stop_watch_ptr_->toc (" processing_time" , true );
236
219
237
-
238
220
int x_offset = cloud->fields [pcl::getFieldIndex (*cloud, " x" )].offset ;
239
221
int y_offset = cloud->fields [pcl::getFieldIndex (*cloud, " y" )].offset ;
240
222
int z_offset = cloud->fields [pcl::getFieldIndex (*cloud, " z" )].offset ;
@@ -246,8 +228,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
246
228
247
229
// pointcloud processing loop
248
230
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 ) {
251
232
Eigen::Vector4f point;
252
233
Eigen::Vector4f point_preprocessed;
253
234
std::memcpy (&point[0 ], &cloud->data [global_offset + x_offset], sizeof (float ));
@@ -270,22 +251,18 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
270
251
point[1 ] > param_.min_y && point[1 ] < param_.max_y &&
271
252
point[0 ] > param_.min_x && point[0 ] < param_.max_x ;
272
253
if ((!param_.negative && point_is_inside) || (param_.negative && !point_is_inside)) {
273
-
274
254
// 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_) {
279
257
Eigen::Vector4f point_postprocessed = eigen_transform_postprocess_ * point_preprocessed;
280
258
281
259
memcpy (&output.data [output_size], &cloud->data [global_offset], cloud->point_step );
282
260
283
261
std::memcpy (&output.data [output_size + x_offset], &point_postprocessed[0 ], sizeof (float ));
284
262
std::memcpy (&output.data [output_size + y_offset], &point_postprocessed[1 ], sizeof (float ));
285
263
std::memcpy (&output.data [output_size + z_offset], &point_postprocessed[2 ], sizeof (float ));
286
-
287
- }else
288
- {
264
+
265
+ } else {
289
266
Eigen::Vector4f point_postprocessed = eigen_transform_postprocess_ * point;
290
267
291
268
memcpy (&output.data [output_size], &cloud->data [global_offset], cloud->point_step );
@@ -294,9 +271,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
294
271
std::memcpy (&output.data [output_size + y_offset], &point_postprocessed[1 ], sizeof (float ));
295
272
std::memcpy (&output.data [output_size + z_offset], &point_postprocessed[2 ], sizeof (float ));
296
273
}
297
- }
298
- else
299
- {
274
+ } else {
300
275
memcpy (&output.data [output_size], &cloud->data [global_offset], cloud->point_step );
301
276
302
277
if (need_preprocess_transform_) {
@@ -329,8 +304,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
329
304
output.row_step = static_cast <uint32_t >(output.data .size () / output.height );
330
305
331
306
// 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 ) {
334
308
publish_crop_box_polygon ();
335
309
}
336
310
@@ -423,7 +397,8 @@ rcl_interfaces::msg::SetParametersResult CropBoxFilter::param_callback(
423
397
new_param.max_x = get_param (p, " max_x" , new_param.max_x ) ? new_param.max_x : param_.max_x ;
424
398
new_param.max_y = get_param (p, " max_y" , new_param.max_y ) ? new_param.max_y : param_.max_y ;
425
399
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 ;
427
402
428
403
param_ = new_param;
429
404
@@ -624,7 +599,7 @@ bool CropBoxFilter::is_data_layout_compatible_with_point_xyzircaedt(const PointC
624
599
return same_layout;
625
600
}
626
601
627
- bool CropBoxFilter::is_valid ( const PointCloud2ConstPtr & cloud)
602
+ bool CropBoxFilter::is_valid (const PointCloud2ConstPtr & cloud)
628
603
{
629
604
if (cloud->width * cloud->height * cloud->point_step != cloud->data .size ()) {
630
605
RCLCPP_WARN (
0 commit comments