MSCEqF 1.0
Multi State Constraint Equivariant Filter for visual inertial navigation
Loading...
Searching...
No Matches
track.hpp
1// Copyright (C) 2023 Alessandro Fornasier.
2// Control of Networked Systems, University of Klagenfurt, Austria.
3//
4// All rights reserved.
5//
6// This software is licensed under the terms of the BSD-2-Clause-License with
7// no commercial use allowed, the full terms of which are made available
8// in the LICENSE file. No license in patents is granted.
9//
10// You can contact the authors at <alessandro.fornasier@ieee.org>
11
12#ifndef TRACK_HPP
13#define TRACK_HPP
14
15#include <opencv2/opencv.hpp>
16
17#include "types/fptypes.hpp"
18#include "vision/features.hpp"
19
20namespace msceqf
21{
29struct Track
30{
31 using Times = std::vector<fp>;
32
38 inline bool empty() const noexcept { return uvs_.empty(); }
39
45 inline size_t size() const noexcept
46 {
47 assert(uvs_.size() == normalized_uvs_.size());
48 assert(uvs_.size() == timestamps_.size());
49 return uvs_.size();
50 }
51
58 void removeInvalid(std::vector<bool>& invalid)
59 {
60 assert(invalid.size() == uvs_.size());
61 assert(uvs_.size() == normalized_uvs_.size());
62 assert(uvs_.size() == timestamps_.size());
63
64 size_t i = 0;
65 size_t j = 0;
66
67 while (i < uvs_.size())
68 {
69 if (!invalid[i])
70 {
71 uvs_[j] = uvs_[i];
74 ++j;
75 }
76 ++i;
77 }
78
79 uvs_.resize(j);
80 normalized_uvs_.resize(j);
81 timestamps_.resize(j);
82 }
83
92 void removeTail(const fp& timestamp, const bool& remove_equal = true)
93 {
94 assert(uvs_.size() == normalized_uvs_.size());
95 assert(uvs_.size() == timestamps_.size());
96
97 size_t j = 0;
98 size_t i = 0;
99
100 while (i < uvs_.size())
101 {
102 if (remove_equal && timestamps_[i] > timestamp)
103 {
104 uvs_[j] = uvs_[i];
106 timestamps_[j] = timestamps_[i];
107 ++j;
108 }
109 if (!remove_equal && timestamps_[i] >= timestamp)
110 {
111 uvs_[j] = uvs_[i];
113 timestamps_[j] = timestamps_[i];
114 ++j;
115 }
116 ++i;
117 }
118
119 uvs_.resize(j);
120 normalized_uvs_.resize(j);
121 timestamps_.resize(j);
122 }
123
128 friend bool operator<(const Track& lhs, const Track& rhs) { return lhs.size() < rhs.size(); }
129
130 FeaturesCoordinates uvs_;
131 FeaturesCoordinates normalized_uvs_;
133};
134
135using Tracks = std::unordered_map<uint, Track>;
136
137} // namespace msceqf
138
139#endif // TRACK_HPP
(Cache friendly) Track struct. Define a feature (labeled via a feature id) detected/tracked at differ...
Definition track.hpp:30
void removeInvalid(std::vector< bool > &invalid)
Remove invalid features coordinates, normalized feature coordinates and ids given a vector of boolean...
Definition track.hpp:58
bool empty() const noexcept
Check if there valid coordinates in uvs_.
Definition track.hpp:38
void removeTail(const fp &timestamp, const bool &remove_equal=true)
Remove the tail of the track. this method removes coordinates and timestamps that are older or equal ...
Definition track.hpp:92
FeaturesCoordinates uvs_
(u, v) coordinates of the same feature at different time steps
Definition track.hpp:130
size_t size() const noexcept
Return the amount of features (size of uvs_)
Definition track.hpp:45
friend bool operator<(const Track &lhs, const Track &rhs)
Comparison operator with other tracks for sorting based on track length.
Definition track.hpp:128
FeaturesCoordinates normalized_uvs_
Normalized (u, v) coordinates of the same feature at different time steps.
Definition track.hpp:131
Times timestamps_
Timestamps of the camera measurement containing the feature.
Definition track.hpp:132
std::vector< fp > Times
vector of timestamps
Definition track.hpp:31