19 #ifndef VISION_COMMON_FEATURE_TRACKER_H_
20 #define VISION_COMMON_FEATURE_TRACKER_H_
31 template <
typename FeatureTrackType = FeatureTrack>
68 void AddOrUpdateTrack(
const FeaturePoint& feature_point);
74 void RemoveEmptyFeatureTracks();
77 friend class boost::serialization::access;
78 template <
class ARCHIVE>
79 void serialize(ARCHIVE& ar,
const unsigned int ) {
80 ar& BOOST_SERIALIZATION_NVP(id_feature_track_map_);
81 ar& BOOST_SERIALIZATION_NVP(params_);
89 template <
typename FeatureTrackType>
92 template <
typename FeatureTrackType>
94 if (feature_points.empty() && params_.remove_undetected_feature_tracks) {
96 LogDebug(
"UpdateFeatureTracks: Removed all feature tracks.");
100 const int starting_num_feature_tracks = size();
101 LogDebug(
"UpdateFeatureTracks: Starting num feature tracks: " << starting_num_feature_tracks);
102 for (
const auto& feature_point : feature_points) {
103 AddOrUpdateTrack(feature_point);
105 const int post_add_num_feature_tracks = size();
106 LogDebug(
"UpdateFeatureTracks: Added feature tracks: " << post_add_num_feature_tracks - starting_num_feature_tracks);
108 if (params_.remove_undetected_feature_tracks) {
109 const auto feature_points_timestamp = feature_points.front().timestamp;
110 RemoveUndetectedFeatureTracks(feature_points_timestamp);
112 const int removed_num_feature_tracks = post_add_num_feature_tracks - size();
113 LogDebug(
"UpdateFeatureTracks: Removed feature tracks: " << removed_num_feature_tracks);
114 LogDebug(
"UpdateFeatureTracks: Final total num feature tracks: " << size());
117 template <
typename FeatureTrackType>
119 for (
auto& feature_track : id_feature_track_map_) {
120 feature_track.second.RemoveOldValues(oldest_allowed_time);
122 RemoveEmptyFeatureTracks();
125 template <
typename FeatureTrackType>
128 return id_feature_track_map_;
131 template <
typename FeatureTrackType>
132 std::vector<std::reference_wrapper<const FeatureTrackType>>
134 std::map<int, int> length_id_map;
135 for (
const auto& feature_track : feature_tracks()) {
136 length_id_map.insert({feature_track.second.size(), feature_track.first});
138 std::vector<std::reference_wrapper<const FeatureTrackType>> feature_tracks_length_ordered;
140 for (
auto it = length_id_map.crbegin(); it != length_id_map.crend(); ++it) {
141 feature_tracks_length_ordered.emplace_back((this->feature_tracks().at(it->second)));
144 return feature_tracks_length_ordered;
147 template <
typename FeatureTrackType>
149 return id_feature_track_map_.
size();
152 template <
typename FeatureTrackType>
154 return id_feature_track_map_.
empty();
157 template <
typename FeatureTrackType>
159 id_feature_track_map_.clear();
162 template <
typename FeatureTrackType>
170 template <
typename FeatureTrackType>
171 void FeatureTracker<FeatureTrackType>::RemoveUndetectedFeatureTracks(
173 for (
auto feature_it = id_feature_track_map_.cbegin(); feature_it != id_feature_track_map_.cend();) {
174 if (!feature_it->second.Contains(feature_point_timestamp)) {
175 feature_it = id_feature_track_map_.erase(feature_it);
182 template <
typename FeatureTrackType>
183 void FeatureTracker<FeatureTrackType>::RemoveEmptyFeatureTracks() {
184 for (
auto feature_it = id_feature_track_map_.cbegin(); feature_it != id_feature_track_map_.cend();) {
185 if (feature_it->second.empty()) {
186 feature_it = id_feature_track_map_.erase(feature_it);
194 #endif // VISION_COMMON_FEATURE_TRACKER_H_