Apollo 10.0
自动驾驶开放平台
i_ground.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#pragma once
17
18#include <utility>
19#include <vector>
20
25
26#include "Eigen/Core"
27#include "Eigen/Sparse"
28
29namespace apollo {
30namespace perception {
31namespace algorithm {
35 nr_support = 0;
36 is_detected = false;
37 is_from_self = 7;
38 invalid_status = 7;
39 }
40
42 ICopy4(pi.params, this->params);
43 this->nr_support = pi.GetNrSupport();
44 this->is_detected = pi.GetStatus();
45 this->is_from_self = pi.GetOrigin();
46 this->invalid_status = pi.GetInvalidStatus();
47 return (*this);
48 }
49
50 float GetDegreeNormalToX() const {
51 float normal[3];
52 ICopy3(params, normal);
53 if (normal[0] < 0) {
54 INeg3(normal);
55 }
56 // normalize:
57 IScale3(normal, IRec(ISqrt(ISquaresum3(normal))));
58 return IRadiansToDegree(IAcos(normal[0]));
59 }
60
61 float get_degree_normal_to_y() const {
62 float normal[3];
63 ICopy3(params, normal);
64 if (normal[1] < 0) {
65 INeg3(normal);
66 }
67 // normalize:
68 IScale3(normal, IRec(ISqrt(ISquaresum3(normal))));
69 return IRadiansToDegree(IAcos(normal[1]));
70 }
71
72 float GetDegreeNormalToZ() const {
73 float normal[3];
74 ICopy3(params, normal);
75 if (normal[2] < 0) {
76 INeg3(normal);
77 }
78 // normalize:
79 IScale3(normal, IRec(ISqrt(ISquaresum3(normal))));
80 return IRadiansToDegree(IAcos(normal[2]));
81 }
82
84 if (params[0] < 0) {
86 }
87 }
88
90 if (params[1] < 0) {
92 }
93 }
94
96 if (params[2] < 0) {
98 }
99 }
100
102 IZero4(params);
103 nr_support = 0;
104 }
105
107 float norm = IL2Norm3(params);
108 IScale4(params, IRec(norm));
109 }
110
111 bool IsValid() const {
112 if (nr_support && (params[0] != 0 || params[1] != 0 || params[2] != 0)) {
113 return true;
114 }
115 return false;
116 }
117
118 int GetNrSupport() const { return nr_support; }
119
120 void SetNrSupport(int nr) { nr_support = nr; }
121
122 bool GetStatus() const { return is_detected; }
123
124 void SetStatus(bool flag) { is_detected = flag; }
125
126 int GetOrigin() const { return is_from_self; }
127
128 void SetOrigin(int origin) { is_from_self = origin; }
129
130 int GetInvalidStatus() const { return invalid_status; }
131
132 void SetInvalidStatus(int flag) { invalid_status = flag; }
133
134 float params[4];
135
136 private:
137 bool is_detected;
138 int is_from_self; // 0: self, 1: neighbor
139 int invalid_status; //0: IsValid, 1: inliers small, 2: NormalToZ big
140 int nr_support;
141};
142
145 theta = phi = d = 0;
146 nr_support = 0;
147 is_detected = false;
148 }
149
151 this->theta = pi.theta;
152 this->phi = pi.phi;
153 this->d = pi.d;
154 this->nr_support = pi.GetNrSupport();
155 this->is_detected = pi.GetStatus();
156 return (*this);
157 }
158
159 bool IsValid() const { return (nr_support > 0); }
160
162 theta = phi = d = 0;
163 nr_support = 0;
164 }
165
166 int GetNrSupport() const { return nr_support; }
167
168 void SetNrSupport(int nr) { nr_support = nr; }
169
170 bool GetStatus() const { return is_detected; }
171
172 void SetStatus(bool flag) { is_detected = flag; }
173
174 float theta;
175 float phi;
176 float d;
177
178 private:
179 bool is_detected;
180 int nr_support;
181};
182
213
216 void Reserve(unsigned int size) { indices.reserve(size); }
217 void Clear() { indices.clear(); }
218 inline void PushIndex(int i) { indices.push_back(i); }
219 int Prune(unsigned int min_nr_samples, unsigned int max_nr_samples);
220 unsigned int Size() const {
221 return static_cast<unsigned int>(indices.size());
222 }
223 int &operator[](unsigned int i) {
224 assert(i >= 0 && i < indices.size());
225 return indices.at(i);
226 }
227 int &operator[](int i) {
228 assert(i >= 0 && i < static_cast<int>(indices.size()));
229 return indices.at(i);
230 }
231 const int &operator[](unsigned int i) const {
232 assert(i >= 0 && i < indices.size());
233 return indices.at(i);
234 }
235 const int &operator[](int i) const {
236 assert(i >= 0 && i < static_cast<int>(indices.size()));
237 return indices.at(i);
238 }
239 std::vector<int> indices;
241};
242
244
246
248 public:
249 // explicit BaseGroundDetector(const PlaneFitGroundDetectorParam &param)
250 // : param_(param) {}
252 : param_(param) {}
254 virtual bool Detect(const float *point_cloud, float *height_above_ground,
255 unsigned int nr_points,
256 unsigned int nr_point_elements) = 0;
257
258 protected:
259 // const PlaneFitGroundDetectorParam &param_;
261};
262
264 static const int dim_point_ = 3;
265
266 public:
267 // explicit PlaneFitGroundDetector(const PlaneFitGroundDetectorParam &param);
270 bool Init();
271 bool Detect(const float *point_cloud, float *height_above_ground,
272 unsigned int nr_points, unsigned int nr_point_elements);
273 void ResetParams(float ori_z_lower, float ori_z_upper);
274 void UpdateParams(float parsing_ground_z, float buffer, double timestamp);
275 const char *GetLabel() const;
276 const VoxelGridXY<float> *GetGrid() const;
277 const GroundPlaneLiDAR *GetGroundPlane(int r, int c) const;
278 unsigned int GetGridDimX() const;
279 unsigned int GetGridDimY() const;
280 float GetUnknownHeight();
281
282 void Pc2Voxel(float x, float y, float z, int *row, int *col);
283
285
286 protected:
287 void CleanUp();
288 void InitOrderTable(const VoxelGridXY<float> *vg, std::pair<int, int> *order);
289 int Fit();
290 int FitLine(unsigned int r);
291 int FitGrid(const float *point_cloud, PlaneFitPointCandIndices *candi,
292 GroundPlaneLiDAR *groundplane, unsigned int nr_points,
293 unsigned int nr_point_element, float dist_thre);
294 int FitInOrder();
295 int FilterCandidates(int r, int c, const float *point_cloud,
297 std::vector<std::pair<int, int>> *neighbors,
298 unsigned int nr_point_element);
299 int FitGridWithNeighbors(int r, int c, const float *point_cloud,
300 GroundPlaneLiDAR *groundplane,
301 unsigned int nr_points,
302 unsigned int nr_point_element, float dist_thre);
303 void GetNeighbors(int r, int c, int rows, int cols,
304 std::vector<std::pair<int, int>> *neighbors);
305 float CalculateAngleDist(const GroundPlaneLiDAR &plane,
306 const std::vector<std::pair<int, int>> &neighbors);
307 int Filter();
308 int FilterLine(unsigned int r);
309 int FilterGrid(const Voxel<float> &vg, const float *point_cloud,
310 PlaneFitPointCandIndices *candi, unsigned int nr_points,
311 unsigned int nr_point_element);
312 int Smooth();
313 int SmoothInOrder();
314 void GetInliers(int *inliers);
315 void Optimization();
316 void PlaneRefine();
317 void SetGroundPlaneSpherParams(float *params);
318 void GetGroundPlaneSpherParams(float *params);
319 void SmoothInMath();
320 int SmoothLine(unsigned int up, unsigned int r, unsigned int dn);
322 const GroundPlaneSpherical &rt,
323 const GroundPlaneSpherical &up,
326 const GroundPlaneSpherical &rt, const GroundPlaneSpherical &up,
328 int CompareZ(const float *point_cloud, const std::vector<int> &point_indices,
329 const float *z_values, PlaneFitPointCandIndices *candi,
330 unsigned int nr_points, unsigned int nr_point_element,
331 unsigned int nr_compares);
333 void ComputeSignedGroundHeight(const float *point_cloud,
334 float *height_above_ground,
335 unsigned int nr_points,
336 unsigned int nr_point_elements);
337 void ComputeSignedGroundHeightLine(const float *point_cloud,
338 const GroundPlaneLiDAR *up,
339 const GroundPlaneLiDAR *cn,
340 const GroundPlaneLiDAR *dn,
341 float *height_above_ground, unsigned int r,
342 unsigned int nr_points,
343 unsigned int nr_point_elements);
344
345 protected:
351 std::pair<float, bool> **ground_z_;
353 unsigned int *map_fine_to_coarse_;
354 char *labels_;
359 int age_ = 0;
360 std::pair<int, int> *order_table_;
361 double frame_timestamp_ = 0.0;
362
363 // global optimize
364 float **weight_buffer_ = nullptr;
365 int *inliers_ = nullptr;
366 float *sphe_params_ = nullptr;
367 std::vector<std::vector<unsigned int>> neighbors_;
368 Eigen::SparseMatrix<float> a_array_;
369 Eigen::SparseMatrix<float> b_array_;
370 Eigen::SimplicialLDLT<Eigen::SparseMatrix<float>> solver_;
371};
372
373} // namespace algorithm
374} // namespace perception
375} // namespace apollo
BaseGroundDetector(PlaneFitGroundDetectorParam &param)
Definition i_ground.h:251
virtual bool Detect(const float *point_cloud, float *height_above_ground, unsigned int nr_points, unsigned int nr_point_elements)=0
int FitGrid(const float *point_cloud, PlaneFitPointCandIndices *candi, GroundPlaneLiDAR *groundplane, unsigned int nr_points, unsigned int nr_point_element, float dist_thre)
Definition i_ground.cc:686
int SmoothLine(unsigned int up, unsigned int r, unsigned int dn)
Definition i_ground.cc:1196
float CalculateAngleDist(const GroundPlaneLiDAR &plane, const std::vector< std::pair< int, int > > &neighbors)
Definition i_ground.cc:1067
const GroundPlaneLiDAR * GetGroundPlane(int r, int c) const
Definition i_ground.cc:1694
void UpdateParams(float parsing_ground_z, float buffer, double timestamp)
Definition i_ground.cc:1589
bool Detect(const float *point_cloud, float *height_above_ground, unsigned int nr_points, unsigned int nr_point_elements)
Definition i_ground.cc:1599
int CompleteGrid(const GroundPlaneSpherical &lt, const GroundPlaneSpherical &rt, const GroundPlaneSpherical &up, const GroundPlaneSpherical &dn, GroundPlaneSpherical *gp)
Definition i_ground.cc:1251
void ResetParams(float ori_z_lower, float ori_z_upper)
Definition i_ground.cc:1582
int FilterGrid(const Voxel< float > &vg, const float *point_cloud, PlaneFitPointCandIndices *candi, unsigned int nr_points, unsigned int nr_point_element)
Definition i_ground.cc:614
void InitOrderTable(const VoxelGridXY< float > *vg, std::pair< int, int > *order)
Definition i_ground.cc:123
Eigen::SimplicialLDLT< Eigen::SparseMatrix< float > > solver_
Definition i_ground.h:370
void ComputeSignedGroundHeight(const float *point_cloud, float *height_above_ground, unsigned int nr_points, unsigned int nr_point_elements)
Definition i_ground.cc:459
int FitGridWithNeighbors(int r, int c, const float *point_cloud, GroundPlaneLiDAR *groundplane, unsigned int nr_points, unsigned int nr_point_element, float dist_thre)
Definition i_ground.cc:883
std::vector< std::vector< unsigned int > > neighbors_
Definition i_ground.h:367
void GetNeighbors(int r, int c, int rows, int cols, std::vector< std::pair< int, int > > *neighbors)
Definition i_ground.cc:1176
const VoxelGridXY< float > * GetGrid() const
Definition i_ground.cc:1690
int SmoothGrid(const GroundPlaneSpherical &g, const GroundPlaneSpherical &lt, const GroundPlaneSpherical &rt, const GroundPlaneSpherical &up, const GroundPlaneSpherical &dn, GroundPlaneSpherical *gp)
Definition i_ground.cc:1289
int FilterCandidates(int r, int c, const float *point_cloud, PlaneFitPointCandIndices *candi, std::vector< std::pair< int, int > > *neighbors, unsigned int nr_point_element)
Definition i_ground.cc:836
void ComputeSignedGroundHeightLine(const float *point_cloud, const GroundPlaneLiDAR *up, const GroundPlaneLiDAR *cn, const GroundPlaneLiDAR *dn, float *height_above_ground, unsigned int r, unsigned int nr_points, unsigned int nr_point_elements)
Definition i_ground.cc:482
int CompareZ(const float *point_cloud, const std::vector< int > &point_indices, const float *z_values, PlaneFitPointCandIndices *candi, unsigned int nr_points, unsigned int nr_point_element, unsigned int nr_compares)
Definition i_ground.cc:356
void Pc2Voxel(float x, float y, float z, int *row, int *col)
Definition i_ground.cc:1667
PlaneFitPointCandIndices ** GetCandis() const
Definition i_ground.cc:1713
float IRadiansToDegree(float r)
Definition i_basic.h:260
void ICopy3(const T src[3], T dst[3])
Definition i_blas.h:40
void IPlaneEucliToSpher(const GroundPlaneLiDAR &src, GroundPlaneSpherical *dst)
Definition i_ground.cc:1717
T ISquaresum3(const T x[3])
Definition i_blas.h:2536
void IScale3(T x[3], T sf)
Definition i_blas.h:1868
float IAcos(float alpha)
Definition i_basic.h:239
T IL2Norm3(const T x[3])
Definition i_blas.h:2812
void IPlaneSpherToEucli(const GroundPlaneSpherical &src, GroundPlaneLiDAR *dst)
Definition i_ground.cc:1734
void IScale4(T x[4], T sf)
Definition i_blas.h:1874
void ICopy4(const T src[4], T dst[4])
Definition i_blas.h:46
class register implement
Definition arena_queue.h:37
GroundPlaneLiDAR & operator=(const GroundPlaneLiDAR &pi)
Definition i_ground.h:41
GroundPlaneSpherical & operator=(const GroundPlaneSpherical &pi)
Definition i_ground.h:150
int Prune(unsigned int min_nr_samples, unsigned int max_nr_samples)
Definition i_ground.cc:67
const int & operator[](unsigned int i) const
Definition i_ground.h:231