Apollo 11.0
自动驾驶开放平台
roi_filter.cc
浏览该文件的文档.
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 *****************************************************************************/
17
18#include <limits>
19
20#include "Eigen/Dense"
21
25
26namespace apollo {
27namespace perception {
28namespace algorithm {
29
31 std::shared_ptr<const apollo::perception::base::HdmapStruct>;
33using ObjectConstPtr = std::shared_ptr<const apollo::perception::base::Object>;
34using ObjectPtr = std::shared_ptr<apollo::perception::base::Object>;
36
37bool IsPtInRoi(const HdmapStructConstPtr roi, const PointD pt) {
38 for (std::size_t j = 0; j < roi->road_polygons.size(); j++) {
39 if (IsPointXYInPolygon2DXY(pt, roi->road_polygons[j])) {
40 return true;
41 }
42 }
43 for (std::size_t j = 0; j < roi->junction_polygons.size(); j++) {
44 if (IsPointXYInPolygon2DXY(pt, roi->junction_polygons[j])) {
45 return true;
46 }
47 }
48 return false;
49}
50
52 PointD ct;
53 ct.x = obj->center[0];
54 ct.y = obj->center[1];
55 ct.z = obj->center[2];
56 return IsPtInRoi(roi, ct);
57}
58
60 const ObjectConstPtr obj) {
61 Eigen::Vector3d bbox_center = obj->center;
62 PointD ct;
63 ct.x = bbox_center[0];
64 ct.y = bbox_center[1];
65 ct.z = bbox_center[2];
66 Eigen::Vector3d bbox_dir = obj->direction.cast<double>();
67 bbox_dir(2) = 0.0;
68 if (bbox_dir.norm() < std::numeric_limits<float>::epsilon()) {
69 return IsPtInRoi(roi, ct);
70 }
71 bbox_dir.normalize();
72 Eigen::Vector3d bbox_ortho_dir =
73 Eigen::Vector3d(-bbox_dir(1), bbox_dir(0), 0.0f);
74 double bbox_length = obj->size[0];
75 double bbox_width = obj->size[1];
76 Eigen::Vector3d bbox_corners[4];
77 bbox_corners[0] = bbox_center + bbox_dir * bbox_length / 2 +
78 bbox_ortho_dir * bbox_width / 2;
79 bbox_corners[1] = bbox_center - bbox_dir * bbox_length / 2 +
80 bbox_ortho_dir * bbox_width / 2;
81 bbox_corners[2] = bbox_center + bbox_dir * bbox_length / 2 -
82 bbox_ortho_dir * bbox_width / 2;
83 bbox_corners[3] = bbox_center - bbox_dir * bbox_length / 2 -
84 bbox_ortho_dir * bbox_width / 2;
85 for (int i = 0; i < 4; ++i) {
86 PointD corner;
87 corner.x = bbox_corners[i][0];
88 corner.y = bbox_corners[i][1];
89 corner.z = bbox_corners[i][2];
90 if (IsPtInRoi(roi, corner)) {
91 return true;
92 }
93 }
94 return false;
95}
96
98 const std::vector<ObjectPtr>& objects,
99 std::vector<ObjectPtr>* valid_objects) {
100 if (roi == nullptr ||
101 (roi->road_polygons.empty() && roi->junction_polygons.empty())) {
102 valid_objects->assign(objects.begin(), objects.end());
103 return true;
104 }
105
106 valid_objects->clear();
107 valid_objects->reserve(objects.size());
108 for (std::size_t i = 0; i < objects.size(); i++) {
109 if (IsObjectInRoi(roi, objects[i])) {
110 valid_objects->push_back(objects[i]);
111 }
112 }
113
114 return valid_objects->size() > 0;
115}
116
117} // namespace algorithm
118} // namespace perception
119} // namespace apollo
std::shared_ptr< apollo::perception::base::Object > ObjectPtr
Definition roi_filter.cc:34
std::shared_ptr< const apollo::perception::base::Object > ObjectConstPtr
Definition roi_filter.cc:33
bool IsObjectInRoi(const HdmapStructConstPtr roi, const ObjectConstPtr obj)
Definition roi_filter.cc:51
bool IsPtInRoi(const HdmapStructConstPtr roi, const PointD pt)
Definition roi_filter.cc:37
std::shared_ptr< const apollo::perception::base::HdmapStruct > HdmapStructConstPtr
Definition roi_filter.cc:31
bool ObjectInRoiCheck(const HdmapStructConstPtr roi, const std::vector< ObjectPtr > &objects, std::vector< ObjectPtr > *valid_objects)
Definition roi_filter.cc:97
bool IsPointXYInPolygon2DXY(const PointT &point, const base::PointCloud< PointT > &polygon)
Definition common.h:35
bool IsObjectBboxInRoi(const HdmapStructConstPtr roi, const ObjectConstPtr obj)
Definition roi_filter.cc:59
class register implement
Definition arena_queue.h:37