@@ -74,60 +74,47 @@ CropBoxFilter::CropBoxFilter(const rclcpp::NodeOptions & node_options)
74
74
75
75
// get transform info for pointcloud
76
76
{
77
-
78
- tf_input_orig_frame_ = static_cast <std::string>(declare_parameter (" input_pointcloud_frame" , " base_link" ));
77
+ tf_input_orig_frame_ =
78
+ static_cast <std::string>(declare_parameter (" input_pointcloud_frame" , " base_link" ));
79
79
tf_input_frame_ = static_cast <std::string>(declare_parameter (" input_frame" , " base_link" ));
80
80
tf_output_frame_ = static_cast <std::string>(declare_parameter (" output_frame" , " base_link" ));
81
81
82
82
// Always consider static TF if in & out frames are same
83
83
bool has_static_tf_only = false ;
84
84
if (tf_input_frame_ == tf_output_frame_) {
85
-
86
85
RCLCPP_INFO (
87
86
this ->get_logger (),
88
87
" Input and output frames are the same. Overriding has_static_tf_only to true." );
89
-
88
+
90
89
has_static_tf_only = true ;
91
90
}
92
91
managed_tf_buffer_ =
93
92
std::make_unique<autoware_utils::ManagedTransformBuffer>(this , has_static_tf_only);
94
93
95
-
96
- if (tf_input_orig_frame_ == tf_input_frame_)
97
- {
94
+ if (tf_input_orig_frame_ == tf_input_frame_) {
98
95
need_preprocess_transform_ = false ;
99
96
eigen_transform_preprocess_ = Eigen::Matrix4f::Identity (4 , 4 );
100
- }
101
- else
102
- {
97
+ } else {
103
98
if (!managed_tf_buffer_->get_transform (
104
- tf_input_frame_, tf_input_orig_frame_, eigen_transform_preprocess_))
105
- {
99
+ tf_input_frame_, tf_input_orig_frame_, eigen_transform_preprocess_)) {
106
100
RCLCPP_ERROR (
107
- this ->get_logger (),
108
- " Cannot get transform from %s to %s. Please check your TF tree." ,tf_input_orig_frame_.c_str () , tf_input_frame_.c_str ());
109
- }
110
- else
111
- {
101
+ this ->get_logger (), " Cannot get transform from %s to %s. Please check your TF tree." ,
102
+ tf_input_orig_frame_.c_str (), tf_input_frame_.c_str ());
103
+ } else {
112
104
need_preprocess_transform_ = true ;
113
105
}
114
106
}
115
107
116
- if (tf_input_frame_ == tf_output_frame_)
117
- {
108
+ if (tf_input_frame_ == tf_output_frame_) {
118
109
need_postprocess_transform_ = false ;
119
110
eigen_transform_postprocess_ = Eigen::Matrix4f::Identity (4 , 4 );
120
- }else
121
- {
111
+ } else {
122
112
if (!managed_tf_buffer_->get_transform (
123
- tf_output_frame_, tf_input_frame_, eigen_transform_postprocess_))
124
- {
113
+ tf_output_frame_, tf_input_frame_, eigen_transform_postprocess_)) {
125
114
RCLCPP_ERROR (
126
- this ->get_logger (),
127
- " Cannot get transform from %s to %s. Please check your TF tree." ,tf_input_frame_.c_str () , tf_output_frame_.c_str ());
128
- }
129
- else
130
- {
115
+ this ->get_logger (), " Cannot get transform from %s to %s. Please check your TF tree." ,
116
+ tf_input_frame_.c_str (), tf_output_frame_.c_str ());
117
+ } else {
131
118
need_postprocess_transform_ = true ;
132
119
}
133
120
}
@@ -166,31 +153,26 @@ CropBoxFilter::CropBoxFilter(const rclcpp::NodeOptions & node_options)
166
153
// set parameter service callback
167
154
{
168
155
using std::placeholders::_1;
169
- set_param_res_ = this -> add_on_set_parameters_callback (
170
- std::bind (&CropBoxFilter::param_callback, this , _1));
156
+ set_param_res_ =
157
+ this -> add_on_set_parameters_callback ( std::bind (&CropBoxFilter::param_callback, this , _1));
171
158
}
172
159
173
160
// set input pointcloud callback
174
161
{
175
162
sub_input_ = this ->create_subscription <PointCloud2>(
176
- " input" , rclcpp::SensorDataQoS ().keep_last (max_queue_size_),
163
+ " input" , rclcpp::SensorDataQoS ().keep_last (max_queue_size_),
177
164
std::bind (&CropBoxFilter::pointcloud_callback, this , std::placeholders::_1));
178
165
}
179
166
180
-
181
167
RCLCPP_DEBUG (this ->get_logger (), " [Filter Constructor] successfully created." );
182
168
}
183
169
184
-
185
-
186
-
187
170
void CropBoxFilter::pointcloud_callback (const PointCloud2ConstPtr cloud)
188
171
{
189
172
// check whether the pointcloud is valid
190
173
if (
191
174
!is_data_layout_compatible_with_point_xyzircaedt (*cloud) &&
192
- !is_data_layout_compatible_with_point_xyzirc (*cloud))
193
- {
175
+ !is_data_layout_compatible_with_point_xyzirc (*cloud)) {
194
176
RCLCPP_ERROR (
195
177
get_logger (),
196
178
" The pointcloud layout is not compatible with PointXYZIRCAEDT or PointXYZIRC. Aborting" );
@@ -223,14 +205,13 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
223
205
" received." ,
224
206
cloud->width * cloud->height , cloud->header .frame_id .c_str ());
225
207
// pointcloud check finished
226
-
208
+
227
209
// pointcloud processing
228
210
auto output = PointCloud2 ();
229
211
230
212
std::scoped_lock lock (mutex_);
231
213
stop_watch_ptr_->toc (" processing_time" , true );
232
214
233
-
234
215
int x_offset = cloud->fields [pcl::getFieldIndex (*cloud, " x" )].offset ;
235
216
int y_offset = cloud->fields [pcl::getFieldIndex (*cloud, " y" )].offset ;
236
217
int z_offset = cloud->fields [pcl::getFieldIndex (*cloud, " z" )].offset ;
@@ -242,8 +223,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
242
223
243
224
// pointcloud processing loop
244
225
for (size_t global_offset = 0 ; global_offset + cloud->point_step <= cloud->data .size ();
245
- global_offset += cloud->point_step )
246
- {
226
+ global_offset += cloud->point_step ) {
247
227
Eigen::Vector4f point;
248
228
Eigen::Vector4f point_preprocessed;
249
229
std::memcpy (&point[0 ], &cloud->data [global_offset + x_offset], sizeof (float ));
@@ -266,22 +246,18 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
266
246
point[1 ] > param_.min_y && point[1 ] < param_.max_y &&
267
247
point[0 ] > param_.min_x && point[0 ] < param_.max_x ;
268
248
if ((!param_.negative && point_is_inside) || (param_.negative && !point_is_inside)) {
269
-
270
249
// apply post-transform if needed
271
- if (need_postprocess_transform_)
272
- {
273
- if (need_preprocess_transform_)
274
- {
250
+ if (need_postprocess_transform_) {
251
+ if (need_preprocess_transform_) {
275
252
Eigen::Vector4f point_postprocessed = eigen_transform_postprocess_ * point_preprocessed;
276
253
277
254
memcpy (&output.data [output_size], &cloud->data [global_offset], cloud->point_step );
278
255
279
256
std::memcpy (&output.data [output_size + x_offset], &point_postprocessed[0 ], sizeof (float ));
280
257
std::memcpy (&output.data [output_size + y_offset], &point_postprocessed[1 ], sizeof (float ));
281
258
std::memcpy (&output.data [output_size + z_offset], &point_postprocessed[2 ], sizeof (float ));
282
-
283
- }else
284
- {
259
+
260
+ } else {
285
261
Eigen::Vector4f point_postprocessed = eigen_transform_postprocess_ * point;
286
262
287
263
memcpy (&output.data [output_size], &cloud->data [global_offset], cloud->point_step );
@@ -290,9 +266,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
290
266
std::memcpy (&output.data [output_size + y_offset], &point_postprocessed[1 ], sizeof (float ));
291
267
std::memcpy (&output.data [output_size + z_offset], &point_postprocessed[2 ], sizeof (float ));
292
268
}
293
- }
294
- else
295
- {
269
+ } else {
296
270
memcpy (&output.data [output_size], &cloud->data [global_offset], cloud->point_step );
297
271
298
272
if (need_preprocess_transform_) {
@@ -325,8 +299,7 @@ void CropBoxFilter::pointcloud_callback(const PointCloud2ConstPtr cloud)
325
299
output.row_step = static_cast <uint32_t >(output.data .size () / output.height );
326
300
327
301
// publish polygon if subscribers exist
328
- if (crop_box_polygon_pub_->get_subscription_count () > 0 )
329
- {
302
+ if (crop_box_polygon_pub_->get_subscription_count () > 0 ) {
330
303
publish_crop_box_polygon ();
331
304
}
332
305
@@ -419,7 +392,8 @@ rcl_interfaces::msg::SetParametersResult CropBoxFilter::param_callback(
419
392
new_param.max_x = get_param (p, " max_x" , new_param.max_x ) ? new_param.max_x : param_.max_x ;
420
393
new_param.max_y = get_param (p, " max_y" , new_param.max_y ) ? new_param.max_y : param_.max_y ;
421
394
new_param.max_z = get_param (p, " max_z" , new_param.max_z ) ? new_param.max_z : param_.max_z ;
422
- new_param.negative = get_param (p, " negative" , new_param.negative ) ? new_param.negative : param_.negative ;
395
+ new_param.negative =
396
+ get_param (p, " negative" , new_param.negative ) ? new_param.negative : param_.negative ;
423
397
424
398
param_ = new_param;
425
399
@@ -620,7 +594,7 @@ bool CropBoxFilter::is_data_layout_compatible_with_point_xyzircaedt(const PointC
620
594
return same_layout;
621
595
}
622
596
623
- bool CropBoxFilter::is_valid ( const PointCloud2ConstPtr & cloud)
597
+ bool CropBoxFilter::is_valid (const PointCloud2ConstPtr & cloud)
624
598
{
625
599
if (cloud->width * cloud->height * cloud->point_step != cloud->data .size ()) {
626
600
RCLCPP_WARN (
0 commit comments