17 #ifndef CARTOGRAPHER_SENSOR_MAP_BY_TIME_H_ 18 #define CARTOGRAPHER_SENSOR_MAP_BY_TIME_H_ 29 #include "glog/logging.h" 35 template <
typename DataType>
39 void Append(
const int trajectory_id,
const DataType& data) {
40 CHECK_GE(trajectory_id, 0);
43 CHECK_GT(data.time, std::prev(
trajectory.end())->first);
50 template <
typename NodeType>
54 CHECK_GE(trajectory_id, 0);
55 if (
data_.count(trajectory_id) == 0) {
62 const auto node_it = nodes.
find(node_id);
63 CHECK(node_it != nodes.
end());
66 ? std::prev(node_it)->data.time
67 : common::Time::min();
68 const auto next_it = std::next(node_it);
71 : common::Time::max();
72 CHECK_LT(gap_start, gap_end);
75 auto data_it =
trajectory.lower_bound(gap_start);
76 auto data_end =
trajectory.upper_bound(gap_end);
77 if (data_it == data_end) {
80 if (gap_end != common::Time::max()) {
82 data_end = std::prev(data_end);
83 if (data_it == data_end) {
87 if (gap_start != common::Time::min()) {
89 data_it = std::next(data_it);
91 while (data_it != data_end) {
95 data_.erase(trajectory_id);
100 return data_.count(trajectory_id) != 0;
112 typename std::map<common::Time, DataType>::const_iterator iterator)
136 typename std::map<common::Time, DataType>::const_iterator
iterator_;
148 typename std::map<
int, std::map<common::Time, DataType>>::const_iterator
150 : current_trajectory_(current_trajectory) {}
152 int operator*()
const {
return current_trajectory_->first; }
155 ++current_trajectory_;
160 --current_trajectory_;
173 typename std::map<int, std::map<common::Time, DataType>>::const_iterator
188 ConstTrajectoryIterator(
data_.begin()),
189 ConstTrajectoryIterator(
data_.end()));
207 std::map<int, std::map<common::Time, DataType>>
data_;
213 #endif // CARTOGRAPHER_SENSOR_MAP_BY_TIME_H_ ConstIterator & operator++()
void Append(const int trajectory_id, const DataType &data)
std::map< int, std::map< common::Time, DataType > >::const_iterator current_trajectory_
const DataType & operator*() const
void Trim(const mapping::MapById< mapping::NodeId, NodeType > &nodes, const mapping::NodeId &node_id)
ConstIterator lower_bound(const int trajectory_id, const common::Time time) const
bool HasTrajectory(const int trajectory_id) const
ConstIterator end() const
std::bidirectional_iterator_tag iterator_category
std::bidirectional_iterator_tag iterator_category
const DataType & reference
ConstIterator BeginOfTrajectory(const int trajectory_id) const
const DataType * operator->() const
UniversalTimeScaleClock::time_point Time
bool operator==(const ConstIterator &it) const
ConstIterator EndOfTrajectory(const int trajectory_id) const
ConstTrajectoryIterator & operator++()
std::map< common::Time, DataType >::const_iterator iterator_
ConstIterator EndOfTrajectory(const int trajectory_id) const
mapping::Range< ConstIterator > trajectory(const int trajectory_id) const
std::map< int, std::map< common::Time, DataType > > data_
ConstIterator(typename std::map< common::Time, DataType >::const_iterator iterator)
ConstTrajectoryIterator(typename std::map< int, std::map< common::Time, DataType >>::const_iterator current_trajectory)
bool operator!=(const ConstTrajectoryIterator &it) const
ConstIterator find(const IdType &id) const
bool operator!=(const ConstIterator &it) const
ConstIterator & operator--()
ConstIterator BeginOfTrajectory(const int trajectory_id) const
mapping::Range< ConstTrajectoryIterator > trajectory_ids() const
bool operator==(const ConstTrajectoryIterator &it) const
ConstTrajectoryIterator & operator--()