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 Apache License, Version 2.0
7// (the "License"); you may not use this file except in compliance with the
8// License. You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15// License for the specific language governing permissions and limitations
16// under the License.
17//
18// You can contact the authors at <alessandro.fornasier@ieee.org>
19
20#ifndef TRACK_HPP
21#define TRACK_HPP
22
23#include <opencv2/opencv.hpp>
24
25#include "types/fptypes.hpp"
26#include "vision/features.hpp"
27
28namespace msceqf
29{
37struct Track
38{
39 using Times = std::vector<fp>;
40
46 inline bool empty() const noexcept { return uvs_.empty(); }
47
53 inline size_t size() const noexcept
54 {
55 assert(uvs_.size() == normalized_uvs_.size());
56 assert(uvs_.size() == timestamps_.size());
57 return uvs_.size();
58 }
59
66 void removeInvalid(std::vector<bool>& invalid)
67 {
68 assert(invalid.size() == uvs_.size());
69 assert(uvs_.size() == normalized_uvs_.size());
70 assert(uvs_.size() == timestamps_.size());
71
72 size_t i = 0;
73 size_t j = 0;
74
75 while (i < uvs_.size())
76 {
77 if (!invalid[i])
78 {
79 uvs_[j] = uvs_[i];
82 ++j;
83 }
84 ++i;
85 }
86
87 uvs_.resize(j);
88 normalized_uvs_.resize(j);
89 timestamps_.resize(j);
90 }
91
100 void removeTail(const fp& timestamp, const bool& remove_equal = true)
101 {
102 assert(uvs_.size() == normalized_uvs_.size());
103 assert(uvs_.size() == timestamps_.size());
104
105 size_t j = 0;
106 size_t i = 0;
107
108 while (i < uvs_.size())
109 {
110 if (remove_equal && timestamps_[i] > timestamp)
111 {
112 uvs_[j] = uvs_[i];
114 timestamps_[j] = timestamps_[i];
115 ++j;
116 }
117 if (!remove_equal && timestamps_[i] >= timestamp)
118 {
119 uvs_[j] = uvs_[i];
121 timestamps_[j] = timestamps_[i];
122 ++j;
123 }
124 ++i;
125 }
126
127 uvs_.resize(j);
128 normalized_uvs_.resize(j);
129 timestamps_.resize(j);
130 }
131
136 friend bool operator<(const Track& lhs, const Track& rhs) { return lhs.size() < rhs.size(); }
137
138 FeaturesCoordinates uvs_;
139 FeaturesCoordinates normalized_uvs_;
141};
142
143using Tracks = std::unordered_map<uint, Track>;
144
145} // namespace msceqf
146
147#endif // TRACK_HPP
(Cache friendly) Track struct. Define a feature (labeled via a feature id) detected/tracked at differ...
Definition track.hpp:38
void removeInvalid(std::vector< bool > &invalid)
Remove invalid features coordinates, normalized feature coordinates and ids given a vector of boolean...
Definition track.hpp:66
bool empty() const noexcept
Check if there valid coordinates in uvs_.
Definition track.hpp:46
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:100
FeaturesCoordinates uvs_
(u, v) coordinates of the same feature at different time steps
Definition track.hpp:138
size_t size() const noexcept
Return the amount of features (size of uvs_).
Definition track.hpp:53
friend bool operator<(const Track &lhs, const Track &rhs)
Comparison operator with other tracks for sorting based on track length.
Definition track.hpp:136
FeaturesCoordinates normalized_uvs_
Normalized (u, v) coordinates of the same feature at different time steps.
Definition track.hpp:139
Times timestamps_
Timestamps of the camera measurement containing the feature.
Definition track.hpp:140
std::vector< fp > Times
vector of timestamps
Definition track.hpp:39