21#include "modules/perception/pointcloud_preprocess/preprocessor/proto/pointcloud_preprocessor_config.pb.h"
32const float PointCloudPreprocessor::kPointInfThreshold = 1e3;
36 std::string config_file =
53 const std::shared_ptr<apollo::drivers::PointCloud const>& message,
55 if (frame ==
nullptr) {
58 if (frame->
cloud ==
nullptr) {
59 frame->
cloud = base::PointFCloudPool::Instance().Get();
62 frame->
world_cloud = base::PointDCloudPool::Instance().Get();
65 frame->
cloud->set_timestamp(message->measurement_time());
66 if (message->point_size() > 0) {
67 frame->
cloud->reserve(message->point_size());
69 for (
int i = 0; i < message->point_size(); ++i) {
71 if (filter_naninf_points_) {
72 if (std::isnan(pt.
x()) || std::isnan(pt.
y()) || std::isnan(pt.
z())) {
75 if (fabs(pt.
x()) > kPointInfThreshold ||
76 fabs(pt.
y()) > kPointInfThreshold ||
77 fabs(pt.
z()) > kPointInfThreshold) {
81 Eigen::Vector3d vec3d_lidar(pt.
x(), pt.
y(), pt.
z());
84 Eigen::Vector3d vec3d_novatel = vec3d_lidar;
85 if (filter_nearby_box_points_ && vec3d_novatel[0] < box_forward_x_ &&
86 vec3d_novatel[0] > box_backward_x_ &&
87 vec3d_novatel[1] < box_forward_y_ &&
88 vec3d_novatel[1] > box_backward_y_) {
91 if (filter_high_z_points_ && pt.
z() > z_threshold_) {
98 frame->
cloud->push_back(point,
static_cast<double>(pt.
timestamp()) * 1e-9,
99 std::numeric_limits<float>::max(), i, 0);
109 if (frame ==
nullptr || frame->
cloud ==
nullptr) {
113 frame->
world_cloud = base::PointDCloudPool::Instance().Get();
115 if (frame->
cloud->size() > 0) {
116 size_t size = frame->
cloud->size();
119 auto& pt = frame->
cloud->at(i);
120 if (filter_naninf_points_) {
121 if (std::isnan(pt.x) || std::isnan(pt.y) || std::isnan(pt.z)) {
122 frame->
cloud->SwapPoint(i, size--);
125 if (fabs(pt.x) > kPointInfThreshold ||
126 fabs(pt.y) > kPointInfThreshold ||
127 fabs(pt.z) > kPointInfThreshold) {
128 frame->
cloud->SwapPoint(i, size--);
132 Eigen::Vector3d vec3d_lidar(pt.x, pt.y, pt.z);
135 Eigen::Vector3d vec3d_novatel = vec3d_lidar;
136 if (filter_nearby_box_points_ && vec3d_novatel[0] < box_forward_x_ &&
137 vec3d_novatel[0] > box_backward_x_ &&
138 vec3d_novatel[1] < box_forward_y_ &&
139 vec3d_novatel[1] > box_backward_y_) {
140 frame->
cloud->SwapPoint(i, size--);
143 if (filter_high_z_points_ && pt.z > z_threshold_) {
144 frame->
cloud->SwapPoint(i, size--);
149 frame->
cloud->resize(i);
151 AINFO <<
"Preprocessor filter points: " << size <<
" to " << i;
156bool PointCloudPreprocessor::TransformCloud(
159 if (local_cloud ==
nullptr) {
162 world_cloud->clear();
163 world_cloud->reserve(local_cloud->size());
164 for (
size_t i = 0; i < local_cloud->size(); ++i) {
165 auto& pt = local_cloud->at(i);
166 Eigen::Vector3d trans_point(pt.x, pt.y, pt.z);
167 trans_point = pose * trans_point;
169 world_point.
x = trans_point(0);
170 world_point.
y = trans_point(1);
171 world_point.
z = trans_point(2);
173 world_cloud->push_back(world_point, local_cloud->points_timestamp(i),
174 std::numeric_limits<float>::max(),
175 local_cloud->points_beam_id()[i], 0);
#define PERCEPTION_REGISTER_POINTCLOUDPREPROCESSOR(name)
bool Preprocess(const PointCloudPreprocessorOptions &options, const std::shared_ptr< apollo::drivers::PointCloud const > &message, LidarFrame *frame) const
Ireprocess point cloud
bool Init(const PointCloudPreprocessorInitOptions &options=PointCloudPreprocessorInitOptions())
Init pointcloud preprocessor
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
std::shared_ptr< PointDCloud > PointDCloudPtr
std::shared_ptr< PointFCloud > PointFCloudPtr
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
optional uint32 intensity
optional uint64 timestamp
Eigen::Affine3d lidar2world_pose
std::shared_ptr< base::AttributePointCloud< base::PointD > > world_cloud
std::shared_ptr< base::AttributePointCloud< base::PointF > > cloud
optional bool filter_naninf_points
optional float z_threshold
optional bool filter_nearby_box_points
optional float box_backward_y
optional float box_forward_y
optional float box_backward_x
optional bool filter_high_z_points
optional float box_forward_x