Apollo 11.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 = "unknown";
38 invalid_status = "invalid";
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 std::string GetOrigin() const { return is_from_self; }
127
128 void SetOrigin(std::string origin) { is_from_self = origin; }
129
130 std::string GetInvalidStatus() const { return invalid_status; }
131
132 void SetInvalidStatus(std::string flag) { invalid_status = flag; }
133
134 float params[4];
135
136 private:
137 bool is_detected;
138 std::string is_from_self; // 0: self, 1: neighbor
139 std::string 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
215
218 void Reserve(unsigned int size) { indices.reserve(size); }
219 void Clear() { indices.clear(); }
220 inline void PushIndex(int i) { indices.push_back(i); }
221 int Prune(unsigned int min_nr_samples, unsigned int max_nr_samples);
222 unsigned int Size() const {
223 return static_cast<unsigned int>(indices.size());
224 }
225 int &operator[](unsigned int i) {
226 assert(i >= 0 && i < indices.size());
227 return indices.at(i);
228 }
229 int &operator[](int i) {
230 assert(i >= 0 && i < static_cast<int>(indices.size()));
231 return indices.at(i);
232 }
233 const int &operator[](unsigned int i) const {
234 assert(i >= 0 && i < indices.size());
235 return indices.at(i);
236 }
237 const int &operator[](int i) const {
238 assert(i >= 0 && i < static_cast<int>(indices.size()));
239 return indices.at(i);
240 }
241 std::vector<int> indices;
243};
244
246 void Reserve(int size) {
247 visited.reserve(size);
248 }
249 void Resize(int size, bool flag) {
250 visited.resize(size, flag);
251 indices_size = size;
252 }
253 void Clear() {
254 visited.clear();
255 ground_height = 0.0;
256 ground_count = 0;
257 ground_flag = false;
258 valid_height = 0.0;
259 valid_count = 0.0;
260 valid_flag = false;
261 indices_size = 0;
262 }
264 return indices_size;
265 }
266 bool GetIndicesVisitedFlag(int indice) {
267 return visited.at(indice);
268 }
269 void SetVisitedTrue(int index) {
270 assert(index < indices_size);
271 visited[index] = true;
272 }
273 void SetGroundHeight(float value) {
274 ground_height = value;
275 }
277 return ground_height;
278 }
279 void SetGroundCount(int value) {
280 ground_count = value;
281 }
283 return ground_count;
284 }
285 void SetGroundFlag(bool flag) {
286 ground_flag = flag;
287 }
289 return ground_flag;
290 }
291 void SetValidHeight(float value) {
292 valid_height = value;
293 }
295 return valid_height;
296 }
297 void SetValidCount(int value) {
298 valid_count = value;
299 }
301 return valid_count;
302 }
303 void SetValidFlag(bool flag) {
304 valid_flag = flag;
305 }
307 return valid_flag;
308 }
309 std::vector<bool> visited;
310 float ground_height = 0.0;
312 bool ground_flag = false;
313 float valid_height = 0.0;
314 int valid_count = 0;
315 bool valid_flag = false;
317};
318
320
322
324 public:
325 // explicit BaseGroundDetector(const PlaneFitGroundDetectorParam &param)
326 // : param_(param) {}
328 : param_(param) {}
330 virtual bool Detect(const float *point_cloud, const int* semantic_value,
331 float *height_above_ground, unsigned int nr_points,
332 unsigned int nr_point_elements) = 0;
333
334 protected:
335 // const PlaneFitGroundDetectorParam &param_;
337};
338
340 static const int dim_point_ = 3;
341
342 public:
343 // explicit PlaneFitGroundDetector(const PlaneFitGroundDetectorParam &param);
346 bool Init();
347 bool Detect(const float *point_cloud, const int* semantic_value,
348 float *height_above_ground,
349 unsigned int nr_points, unsigned int nr_point_elements);
350 void ResetParams(float ori_z_lower, float ori_z_upper);
351 void UpdateParams(float parsing_ground_z, float buffer, double timestamp);
352 const char *GetLabel() const;
353 const VoxelGridXY<float> *GetGrid() const;
354 const GroundPlaneLiDAR *GetGroundPlane(int r, int c) const;
355 unsigned int GetGridDimX() const;
356 unsigned int GetGridDimY() const;
357 float GetUnknownHeight();
358
359 void Pc2Voxel(float x, float y, float z, int *row, int *col);
360
362
363 protected:
364 void CleanUp();
365 void InitOrderTable(const VoxelGridXY<float> *vg, std::pair<int, int> *order);
366 int Fit();
367 int FitLine(unsigned int r);
368 int FitGrid(const float *point_cloud, PlaneFitPointCandIndices *candi,
369 GroundPlaneLiDAR *groundplane, unsigned int nr_points,
370 unsigned int nr_point_element, float dist_thre);
371 int FitInOrder();
372 int FilterCandidates(int r, int c, const float *point_cloud,
374 std::vector<std::pair<int, int>> *neighbors,
375 unsigned int nr_point_element);
376 int FitGridWithNeighbors(int r, int c, const float *point_cloud,
377 GroundPlaneLiDAR *groundplane,
378 unsigned int nr_points,
379 unsigned int nr_point_element, float dist_thre);
380 void GetNeighbors(int r, int c, int rows, int cols,
381 std::vector<std::pair<int, int>> *neighbors);
382 float CalculateAngleDist(const GroundPlaneLiDAR &plane,
383 const std::vector<std::pair<int, int>> &neighbors);
384 void SelectGroundCandidate(const float *point_cloud,
385 const int *semantic_list, const std::vector<int> &indices,
387 unsigned int nr_point_element);
388 int NeighborGroundCandidate(int row, int col, const float *point_cloud,
389 const int *semantic_list, const std::vector<int> &indices,
390 PlaneFitPointCandIndices *candi, unsigned int nr_point_element);
391 void SelectCandidates();
392 int Filter();
393 int FilterLine(unsigned int r);
394 int FilterGrid(const Voxel<float> &vg, const float *point_cloud,
395 PlaneFitPointCandIndices *candi, unsigned int nr_points,
396 unsigned int nr_point_element);
397 int Smooth();
398 int SmoothInOrder();
399 void GetInliers(int *inliers);
400 void Optimization();
401 void PlaneRefine();
402 void SetGroundPlaneSpherParams(float *params);
403 void GetGroundPlaneSpherParams(float *params);
404 void SmoothInMath();
405 int SmoothLine(unsigned int up, unsigned int r, unsigned int dn);
407 const GroundPlaneSpherical &rt,
408 const GroundPlaneSpherical &up,
411 const GroundPlaneSpherical &rt, const GroundPlaneSpherical &up,
413 int CompareZ(const float *point_cloud, const std::vector<int> &point_indices,
414 const float *z_values, PlaneFitPointCandIndices *candi,
415 unsigned int nr_points, unsigned int nr_point_element,
416 unsigned int nr_compares);
418 void ComputeSignedGroundHeight(const float *point_cloud,
419 float *height_above_ground,
420 unsigned int nr_points,
421 unsigned int nr_point_elements);
422 void ComputeSignedGroundHeightLine(const float *point_cloud,
423 const GroundPlaneLiDAR *up,
424 const GroundPlaneLiDAR *cn,
425 const GroundPlaneLiDAR *dn,
426 float *height_above_ground, unsigned int r,
427 unsigned int nr_points,
428 unsigned int nr_point_elements);
429
430 protected:
437 std::pair<float, bool> **ground_z_;
439 unsigned int *map_fine_to_coarse_;
440 char *labels_;
445 int age_ = 0;
446 std::pair<int, int> *order_table_;
447 double frame_timestamp_ = 0.0;
448
449 // global optimize
450 float **weight_buffer_ = nullptr;
451 int *inliers_ = nullptr;
452 float *sphe_params_ = nullptr;
453 std::vector<std::vector<unsigned int>> neighbors_;
454 Eigen::SparseMatrix<float> a_array_;
455 Eigen::SparseMatrix<float> b_array_;
456 Eigen::SimplicialLDLT<Eigen::SparseMatrix<float>> solver_;
457};
458
459} // namespace algorithm
460} // namespace perception
461} // namespace apollo
BaseGroundDetector(PlaneFitGroundDetectorParam &param)
Definition i_ground.h:327
virtual bool Detect(const float *point_cloud, const int *semantic_value, 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:986
int SmoothLine(unsigned int up, unsigned int r, unsigned int dn)
Definition i_ground.cc:1496
void SelectGroundCandidate(const float *point_cloud, const int *semantic_list, const std::vector< int > &indices, PlaneFitPointCandIndices *candi, GroundCandidateIndices *ground_candi, unsigned int nr_point_element)
Definition i_ground.cc:695
float CalculateAngleDist(const GroundPlaneLiDAR &plane, const std::vector< std::pair< int, int > > &neighbors)
Definition i_ground.cc:1367
const GroundPlaneLiDAR * GetGroundPlane(int r, int c) const
Definition i_ground.cc:2000
void UpdateParams(float parsing_ground_z, float buffer, double timestamp)
Definition i_ground.cc:1889
bool Detect(const float *point_cloud, const int *semantic_value, float *height_above_ground, unsigned int nr_points, unsigned int nr_point_elements)
Definition i_ground.cc:1899
int CompleteGrid(const GroundPlaneSpherical &lt, const GroundPlaneSpherical &rt, const GroundPlaneSpherical &up, const GroundPlaneSpherical &dn, GroundPlaneSpherical *gp)
Definition i_ground.cc:1551
void ResetParams(float ori_z_lower, float ori_z_upper)
Definition i_ground.cc:1882
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:623
void InitOrderTable(const VoxelGridXY< float > *vg, std::pair< int, int > *order)
Definition i_ground.cc:125
Eigen::SimplicialLDLT< Eigen::SparseMatrix< float > > solver_
Definition i_ground.h:456
void ComputeSignedGroundHeight(const float *point_cloud, float *height_above_ground, unsigned int nr_points, unsigned int nr_point_elements)
Definition i_ground.cc:468
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:1183
std::vector< std::vector< unsigned int > > neighbors_
Definition i_ground.h:453
void GetNeighbors(int r, int c, int rows, int cols, std::vector< std::pair< int, int > > *neighbors)
Definition i_ground.cc:1476
const VoxelGridXY< float > * GetGrid() const
Definition i_ground.cc:1996
int SmoothGrid(const GroundPlaneSpherical &g, const GroundPlaneSpherical &lt, const GroundPlaneSpherical &rt, const GroundPlaneSpherical &up, const GroundPlaneSpherical &dn, GroundPlaneSpherical *gp)
Definition i_ground.cc:1589
int NeighborGroundCandidate(int row, int col, const float *point_cloud, const int *semantic_list, const std::vector< int > &indices, PlaneFitPointCandIndices *candi, unsigned int nr_point_element)
Definition i_ground.cc:764
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:1136
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:491
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:365
void Pc2Voxel(float x, float y, float z, int *row, int *col)
Definition i_ground.cc:1973
PlaneFitPointCandIndices ** GetCandis() const
Definition i_ground.cc:2019
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:2023
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:2040
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:69
const int & operator[](unsigned int i) const
Definition i_ground.h:233