23 #include "cyber/common/log.h" 29 namespace perception {
35 template <
typename Po
intT>
37 const PointT& center_pt,
float radius,
float neighbour_dist,
40 for (
size_t c = 0; c < cloud->width(); ++c) {
41 for (
size_t r = 0; r < cloud->height(); ++r) {
43 if (cloud->height() > 1) {
44 const PointT* tmp_pt_ptr = cloud->at(c, r);
45 if (tmp_pt_ptr ==
nullptr) {
48 tmp_pt = *(tmp_pt_ptr);
50 tmp_pt = cloud->at(c);
52 if (CalculateEuclidenDist<PointT>(tmp_pt, center_pt) < radius) {
53 if (down_cloud->size() == 0) {
54 down_cloud->push_back(tmp_pt);
56 if (CalculateEuclidenDist<PointT>(
57 tmp_pt, down_cloud->at(down_cloud->size() - 1)) >=
59 down_cloud->push_back(tmp_pt);
71 template <
typename Po
intT>
73 const PointT& center_pt,
int smp_ratio,
float radius,
int velodyne_model,
76 int smp_step = smp_ratio * velodyne_model;
77 down_cloud->resize(cloud->size() / smp_ratio + 1);
79 for (
size_t ori_ii = 0; ori_ii < cloud->size(); ori_ii += smp_step) {
80 for (
size_t jj = ori_ii;
81 jj < cloud->size() && (jj - ori_ii) < velodyne_model; ++jj) {
82 const PointT& p = cloud->at(jj);
83 if (std::isnan(p.x) || std::isnan(p.y) || std::isnan(p.z)) {
86 float r = CalculateEuclidenDist2DXY<PointT>(center_pt, p);
90 down_cloud->at(jj).x = cloud->at(jj).x;
91 down_cloud->at(jj).y = cloud->at(jj).y;
92 down_cloud->at(jj).z = cloud->at(jj).z;
96 down_cloud->resize(ii);
102 template <
typename Po
intT>
104 const PointT& center_pt,
int org_num,
int smp_ratio,
float radius,
108 std::vector<std::pair<int, int>>* all_org_idx_ptr) {
109 int smp_height =
static_cast<int>(cloud->height()) / smp_ratio;
110 int smp_width = org_num;
111 if (smp_width < 1 || smp_width >= velodyne_model) {
112 AERROR <<
"org_num error!";
116 down_cloud->resize(smp_height * smp_width);
117 all_org_idx_ptr->resize(smp_height * smp_width);
118 for (
size_t hh = 0; hh < smp_height; ++hh) {
119 for (
size_t ww = 0; ww < smp_width; ++ww) {
120 int ori_hh =
static_cast<int>(hh) * smp_ratio;
121 const PointT* p_ptr = cloud->at(ww, ori_hh);
122 if (p_ptr ==
nullptr) {
125 const PointT& p = *(p_ptr);
126 if (std::isnan(p.x) || std::isnan(p.y) || std::isnan(p.z)) {
129 float r = CalculateEuclidenDist2DXY<PointT>(center_pt, p);
133 down_cloud->at(ii) = p;
134 all_org_idx_ptr->at(ii).first =
static_cast<int>(hh);
135 all_org_idx_ptr->at(ii).second =
static_cast<int>(ww);
140 down_cloud->resize(ii);
141 all_org_idx_ptr->resize(ii);
146 template <
typename Po
intT>
148 int org_num,
int smp_ratio,
float front_range,
float side_range,
152 std::vector<std::pair<int, int>>* all_org_idx_ptr) {
153 int smp_height =
static_cast<int>(cloud->height()) / smp_ratio;
154 int smp_width = org_num;
155 if (smp_width < 1 || smp_width >= velodyne_model) {
156 AERROR <<
"org_num error!";
160 down_cloud->resize(smp_height * smp_width);
161 all_org_idx_ptr->resize(smp_height * smp_width);
162 for (
size_t hh = 0; hh < smp_height; ++hh) {
163 for (
size_t ww = 0; ww < smp_width; ++ww) {
164 int ori_hh =
static_cast<int>(hh) * smp_ratio;
165 const PointT* p_ptr = cloud->at(ww, ori_hh);
166 if (p_ptr ==
nullptr) {
169 const PointT& p = *(p_ptr);
170 if (std::isnan(p.x) || std::isnan((p.y) || std::isnan(p.z))) {
173 if (fabs(p.x) > front_range || fabs(p.y) > side_range) {
176 down_cloud->at(ii) = p;
177 all_org_idx_ptr->at(ii).first =
static_cast<int>(hh);
178 all_org_idx_ptr->at(ii).second =
static_cast<int>(ww);
183 down_cloud->resize(ii);
184 all_org_idx_ptr->resize(ii);
189 template <
typename Po
intT>
191 float front_range,
float side_range,
double max_nei,
int velo_model,
194 if (cloud->width() != velo_model) {
195 AERROR <<
"cloud->width (" << cloud->width() <<
") does not match " 196 <<
"velo_model (" << velo_model <<
")";
199 down_cloud->resize(cloud->size());
201 for (
int ww = 0; ww < cloud->width(); ++ww) {
206 for (
int hh = 0; hh < cloud->height(); ++hh) {
207 const PointT* p_ptr = cloud->at(ww, hh);
208 if (p_ptr ==
nullptr) {
211 const PointT& p = *(p_ptr);
212 if (std::isnan(p.x) || std::isnan(p.y) || std::isnan(p.z)) {
215 if (fabs(p.x) > front_range || fabs(p.y) > side_range) {
218 if (fabs(p.x - nei_pt.x) > max_nei || fabs(p.y - nei_pt.y) > max_nei) {
220 down_cloud->at(pt_num++) = p;
224 down_cloud->resize(pt_num);
void DownsamplingCircularOrgPartial(const PointT ¢er_pt, int org_num, int smp_ratio, float radius, int velodyne_model, const typename std::shared_ptr< const base::PointCloud< PointT >> cloud, typename std::shared_ptr< base::PointCloud< PointT >> down_cloud, std::vector< std::pair< int, int >> *all_org_idx_ptr)
Definition: downsampling.h:103
void DownsamplingCircular(const PointT ¢er_pt, float radius, float neighbour_dist, typename std::shared_ptr< const base::PointCloud< PointT >> cloud, typename std::shared_ptr< base::PointCloud< PointT >> down_cloud)
Definition: downsampling.h:36
Definition: point_cloud.h:33
void DownsamplingRectangleOrgPartial(int org_num, int smp_ratio, float front_range, float side_range, int velodyne_model, typename std::shared_ptr< const base::PointCloud< PointT >> cloud, typename std::shared_ptr< base::PointCloud< PointT >> down_cloud, std::vector< std::pair< int, int >> *all_org_idx_ptr)
Definition: downsampling.h:147
void DownsamplingCircularOrgAll(const PointT ¢er_pt, int smp_ratio, float radius, int velodyne_model, typename std::shared_ptr< const base::PointCloud< PointT >> cloud, typename std::shared_ptr< base::PointCloud< PointT >> down_cloud)
Definition: downsampling.h:72
void DownsamplingRectangleNeighbour(float front_range, float side_range, double max_nei, int velo_model, typename std::shared_ptr< const base::PointCloud< PointT >> cloud, typename std::shared_ptr< base::PointCloud< PointT >> down_cloud)
Definition: downsampling.h:190