Apollo 11.0
自动驾驶开放平台
track_data.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 "cyber/common/log.h"
19
20namespace apollo {
21namespace perception {
22namespace radar4d {
23const int TrackData::kMaxHistorySize = 40;
25
27
29
30std::pair<double, TrackedObjectPtr> TrackData::GetHistoryObject(int idx) {
31 if (history_objects_.empty()) {
32 AWARN << "no object in track";
33 return std::pair<double, TrackedObjectPtr>(0.0, TrackedObjectPtr(nullptr));
34 }
35 int max_idx = std::abs(idx) >= static_cast<int>(history_objects_.size())
36 ? static_cast<int>(history_objects_.size()) - 1
37 : abs(idx);
38 // from oldest
39 if (idx > 0) {
40 std::map<double, TrackedObjectPtr>::iterator cur_obj =
41 history_objects_.begin();
42 for (int i = 0; i < max_idx; ++i) {
43 ++cur_obj;
44 }
45 return *cur_obj;
46 } else {
47 std::map<double, TrackedObjectPtr>::reverse_iterator cur_obj =
48 history_objects_.rbegin();
49 for (int i = 0; i < max_idx; ++i) {
50 ++cur_obj;
51 }
52 return *cur_obj;
53 }
54}
55
56std::pair<double, TrackedObjectConstPtr> TrackData::GetHistoryObject(
57 int idx) const {
58 if (history_objects_.empty()) {
59 AINFO << "no object in track";
60 return std::pair<double, TrackedObjectPtr>(0.0, TrackedObjectPtr(nullptr));
61 }
62 int max_idx = static_cast<size_t>(abs(idx)) >= history_objects_.size()
63 ? static_cast<int>(history_objects_.size()) - 1
64 : abs(idx);
65 // from oldest
66 if (idx > 0) {
67 std::map<double, TrackedObjectPtr>::const_iterator cur_obj =
68 history_objects_.cbegin();
69 for (int i = 0; i < max_idx; ++i) {
70 ++cur_obj;
71 }
72 return *cur_obj;
73 } else {
74 std::map<double, TrackedObjectPtr>::const_reverse_iterator cur_obj =
75 history_objects_.crbegin();
76 for (int i = 0; i < max_idx; ++i) {
77 ++cur_obj;
78 }
79 return *cur_obj;
80 }
81}
82
98
99void TrackData::Reset(TrackedObjectPtr obj, double time, int track_id) {
100 Reset();
101 track_id_ = track_id;
102 PushTrackedObjectToTrack(obj, time);
103}
104
106 if (history_objects_.find(time) == history_objects_.end()) {
107 history_objects_.insert(std::make_pair(time, obj));
108 age_++;
109 obj->track_id = track_id_;
110 obj->tracking_time = time - history_objects_.begin()->first;
111 if (obj->is_fake) {
113 } else {
116 }
117 if (history_objects_.size() > kMaxHistorySize) {
118 history_objects_.erase(history_objects_.begin());
119 }
120 } else {
121 AWARN << "push object time " << time
122 << " already exist in track, ignore insert.";
123 }
124}
125
126} // namespace radar4d
127} // namespace perception
128} // namespace apollo
virtual void PushTrackedObjectToTrack(TrackedObjectPtr obj, double time)
Push tracked object to track
std::deque< double > history_norm_variance_
Definition track_data.h:146
std::map< double, TrackedObjectPtr > history_objects_
Definition track_data.h:130
std::deque< double > history_theta_variance_
Definition track_data.h:147
std::pair< double, TrackedObjectPtr > GetHistoryObject(int idx)
Get histroy object
Definition track_data.cc:30
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
std::shared_ptr< TrackedObject > TrackedObjectPtr
class register implement
Definition arena_queue.h:37