Skip to content

Commit 9d43c49

Browse files
committed
Revert "fix(ground_segmentation): add intensity field (autowarefoundation#6791)"
This reverts commit 729eec0.
1 parent 6bb900d commit 9d43c49

File tree

4 files changed

+32
-78
lines changed

4 files changed

+32
-78
lines changed

perception/ground_segmentation/include/ground_segmentation/ray_ground_filter_nodelet.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,15 @@ class RayGroundFilterComponent : public pointcloud_preprocessor::Filter
186186
* @param out_removed_indices_cloud_ptr Resulting PointCloud with the indices removed
187187
*/
188188
void ExtractPointsIndices(
189-
const PointCloud2::ConstSharedPtr in_cloud_ptr, pcl::PointIndices & in_indices,
190-
PointCloud2::SharedPtr out_only_indices_cloud_ptr,
191-
PointCloud2::SharedPtr out_removed_indices_cloud_ptr);
189+
const pcl::PointCloud<PointType_>::Ptr in_cloud_ptr, const pcl::PointIndices & in_indices,
190+
pcl::PointCloud<PointType_>::Ptr out_only_indices_cloud_ptr,
191+
pcl::PointCloud<PointType_>::Ptr out_removed_indices_cloud_ptr);
192192

193193
boost::optional<float> calcPointVehicleIntersection(const Point & point);
194194

195195
void setVehicleFootprint(
196196
const double min_x, const double max_x, const double min_y, const double max_y);
197-
void initializePointCloud2(
198-
const PointCloud2::ConstSharedPtr & in_cloud_ptr, PointCloud2::SharedPtr & out_cloud_msg_ptr);
197+
199198
/** \brief Parameter service callback result : needed to be hold */
200199
OnSetParametersCallbackHandle::SharedPtr set_param_res_;
201200

perception/ground_segmentation/src/ransac_ground_filter_nodelet.cpp

+8-25
Original file line numberDiff line numberDiff line change
@@ -284,36 +284,19 @@ void RANSACGroundFilterComponent::filter(
284284
const Eigen::Affine3d plane_affine = getPlaneAffine(*segment_ground_cloud_ptr, plane_normal);
285285
pcl::PointCloud<PointType>::Ptr no_ground_cloud_ptr(new pcl::PointCloud<PointType>);
286286

287-
int x_offset = input->fields[pcl::getFieldIndex(*input, "x")].offset;
288-
int y_offset = input->fields[pcl::getFieldIndex(*input, "y")].offset;
289-
int z_offset = input->fields[pcl::getFieldIndex(*input, "z")].offset;
290-
int point_step = input->point_step;
291-
292-
sensor_msgs::msg::PointCloud2::SharedPtr no_ground_cloud_msg_ptr(
293-
new sensor_msgs::msg::PointCloud2);
294-
no_ground_cloud_msg_ptr->header = input->header;
295-
no_ground_cloud_msg_ptr->fields = input->fields;
296-
no_ground_cloud_msg_ptr->point_step = point_step;
297-
size_t output_size = 0;
298287
// use not downsampled pointcloud for extract pointcloud that higher than height threshold
299-
for (size_t global_size = 0; global_size < input->data.size(); global_size += point_step) {
300-
float x = *reinterpret_cast<float *>(input->data[global_size + x_offset]);
301-
float y = *reinterpret_cast<float *>(input->data[global_size + y_offset]);
302-
float z = *reinterpret_cast<float *>(input->data[global_size + z_offset]);
303-
const Eigen::Vector3d transformed_point = plane_affine.inverse() * Eigen::Vector3d(x, y, z);
288+
for (const auto & p : current_sensor_cloud_ptr->points) {
289+
const Eigen::Vector3d transformed_point =
290+
plane_affine.inverse() * Eigen::Vector3d(p.x, p.y, p.z);
304291
if (std::abs(transformed_point.z()) > height_threshold_) {
305-
std::memcpy(
306-
&no_ground_cloud_msg_ptr->data[output_size], &input->data[global_size], point_step);
307-
output_size += point_step;
292+
no_ground_cloud_ptr->points.push_back(p);
308293
}
309294
}
310-
no_ground_cloud_msg_ptr->data.resize(output_size);
311-
no_ground_cloud_msg_ptr->height = input->height;
312-
no_ground_cloud_msg_ptr->width = output_size / point_step / input->height;
313-
no_ground_cloud_msg_ptr->row_step = output_size / input->height;
314-
no_ground_cloud_msg_ptr->is_dense = input->is_dense;
315-
no_ground_cloud_msg_ptr->is_bigendian = input->is_bigendian;
316295

296+
sensor_msgs::msg::PointCloud2::SharedPtr no_ground_cloud_msg_ptr(
297+
new sensor_msgs::msg::PointCloud2);
298+
pcl::toROSMsg(*no_ground_cloud_ptr, *no_ground_cloud_msg_ptr);
299+
no_ground_cloud_msg_ptr->header = input->header;
317300
sensor_msgs::msg::PointCloud2::SharedPtr no_ground_cloud_transformed_msg_ptr(
318301
new sensor_msgs::msg::PointCloud2);
319302
if (!transformPointCloud(

perception/ground_segmentation/src/ray_ground_filter_nodelet.cpp

+17-47
Original file line numberDiff line numberDiff line change
@@ -257,53 +257,20 @@ void RayGroundFilterComponent::ClassifyPointCloud(
257257
// return (true);
258258
// }
259259

260-
void RayGroundFilterComponent::initializePointCloud2(
261-
const PointCloud2::ConstSharedPtr & in_cloud_ptr, PointCloud2::SharedPtr & out_cloud_msg_ptr)
262-
{
263-
out_cloud_msg_ptr->header = in_cloud_ptr->header;
264-
out_cloud_msg_ptr->height = in_cloud_ptr->height;
265-
out_cloud_msg_ptr->fields = in_cloud_ptr->fields;
266-
out_cloud_msg_ptr->is_bigendian = in_cloud_ptr->is_bigendian;
267-
out_cloud_msg_ptr->point_step = in_cloud_ptr->point_step;
268-
out_cloud_msg_ptr->is_dense = in_cloud_ptr->is_dense;
269-
out_cloud_msg_ptr->data.resize(in_cloud_ptr->data.size());
270-
}
271-
272260
void RayGroundFilterComponent::ExtractPointsIndices(
273-
const PointCloud2::ConstSharedPtr in_cloud_ptr, pcl::PointIndices & in_indices,
274-
PointCloud2::SharedPtr ground_cloud_msg_ptr, PointCloud2::SharedPtr no_ground_cloud_msg_ptr)
261+
const pcl::PointCloud<PointType_>::Ptr in_cloud_ptr, const pcl::PointIndices & in_indices,
262+
pcl::PointCloud<PointType_>::Ptr out_only_indices_cloud_ptr,
263+
pcl::PointCloud<PointType_>::Ptr out_removed_indices_cloud_ptr)
275264
{
276-
initializePointCloud2(in_cloud_ptr, ground_cloud_msg_ptr);
277-
initializePointCloud2(in_cloud_ptr, no_ground_cloud_msg_ptr);
278-
int point_step = in_cloud_ptr->point_step;
279-
size_t ground_count = 0;
280-
size_t no_ground_count = 0;
281-
std::vector<bool> is_ground_idx(in_cloud_ptr->width, false);
282-
for (const auto & idx : in_indices.indices) {
283-
if (std::size_t(idx) >= is_ground_idx.size()) {
284-
continue;
285-
}
286-
is_ground_idx[idx] = true;
287-
}
288-
for (size_t i = 0; i < is_ground_idx.size(); ++i) {
289-
if (is_ground_idx[i]) {
290-
std::memcpy(
291-
&ground_cloud_msg_ptr->data[ground_count * point_step], &in_cloud_ptr->data[i * point_step],
292-
point_step);
293-
ground_count++;
294-
} else {
295-
std::memcpy(
296-
&no_ground_cloud_msg_ptr->data[no_ground_count * point_step],
297-
&in_cloud_ptr->data[i * point_step], point_step);
298-
no_ground_count++;
299-
}
300-
}
301-
ground_cloud_msg_ptr->data.resize(ground_count * point_step);
302-
no_ground_cloud_msg_ptr->data.resize(no_ground_count * point_step);
303-
ground_cloud_msg_ptr->width = ground_count;
304-
no_ground_cloud_msg_ptr->width = no_ground_count;
305-
ground_cloud_msg_ptr->row_step = ground_count * point_step;
306-
no_ground_cloud_msg_ptr->row_step = no_ground_count * point_step;
265+
pcl::ExtractIndices<PointType_> extract_ground;
266+
extract_ground.setInputCloud(in_cloud_ptr);
267+
extract_ground.setIndices(pcl::make_shared<pcl::PointIndices>(in_indices));
268+
269+
extract_ground.setNegative(false); // true removes the indices, false leaves only the indices
270+
extract_ground.filter(*out_only_indices_cloud_ptr);
271+
272+
extract_ground.setNegative(true); // true removes the indices, false leaves only the indices
273+
extract_ground.filter(*out_removed_indices_cloud_ptr);
307274
}
308275

309276
void RayGroundFilterComponent::filter(
@@ -332,11 +299,14 @@ void RayGroundFilterComponent::filter(
332299
pcl::PointCloud<PointType_>::Ptr no_ground_cloud_ptr(new pcl::PointCloud<PointType_>);
333300
pcl::PointCloud<pcl::PointXYZRGB>::Ptr radials_cloud_ptr(new pcl::PointCloud<pcl::PointXYZRGB>);
334301

302+
ExtractPointsIndices(
303+
current_sensor_cloud_ptr, ground_indices, ground_cloud_ptr, no_ground_cloud_ptr);
304+
335305
sensor_msgs::msg::PointCloud2::SharedPtr no_ground_cloud_msg_ptr(
336306
new sensor_msgs::msg::PointCloud2);
337-
sensor_msgs::msg::PointCloud2::SharedPtr ground_cloud_msg_ptr(new sensor_msgs::msg::PointCloud2);
307+
pcl::toROSMsg(*no_ground_cloud_ptr, *no_ground_cloud_msg_ptr);
308+
no_ground_cloud_msg_ptr->header = input->header;
338309

339-
ExtractPointsIndices(input, ground_indices, ground_cloud_msg_ptr, no_ground_cloud_msg_ptr);
340310
output = *no_ground_cloud_msg_ptr;
341311
}
342312

perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ void ScanGroundFilterComponent::extractObjectPoints(
575575
std::memcpy(
576576
&out_object_cloud.data[output_data_size], &in_cloud_ptr->data[i * in_cloud_ptr->point_step],
577577
in_cloud_ptr->point_step * sizeof(uint8_t));
578+
*reinterpret_cast<float *>(&out_object_cloud.data[output_data_size + intensity_offset_]) =
579+
1; // set intensity to 1
578580
output_data_size += in_cloud_ptr->point_step;
579581
}
580582
}
@@ -604,7 +606,7 @@ void ScanGroundFilterComponent::faster_filter(
604606
output.row_step = no_ground_indices.indices.size() * input->point_step;
605607
output.data.resize(output.row_step);
606608
output.width = no_ground_indices.indices.size();
607-
output.fields = input->fields;
609+
output.fields.assign(input->fields.begin(), input->fields.begin() + 3);
608610
output.is_dense = true;
609611
output.height = input->height;
610612
output.is_bigendian = input->is_bigendian;

0 commit comments

Comments
 (0)