metadata_cache.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 // SPDX-FileCopyrightText: Czech Technical University in Prague
3 
10 #pragma once
11 
12 #include <memory>
13 #include <string>
14 
15 #include <compass_msgs/Azimuth.h>
17 #include <geometry_msgs/Transform.h>
18 #include <gps_common/GPSFix.h>
20 #include <sensor_msgs/CameraInfo.h>
21 #include <sensor_msgs/Imu.h>
22 #include <sensor_msgs/MagneticField.h>
23 #include <sensor_msgs/NavSatFix.h>
24 #include <vision_msgs/Detection2DArray.h>
25 
26 namespace movie_publisher
27 {
28 
32 struct LatestMetadataCache final
33 {
36 
37  void clear();
38 
39  cras::optional<cras::optional<std::string>>& getCameraGeneralName();
40  const cras::optional<cras::optional<std::string>>& getCameraGeneralName() const;
41 
42  cras::optional<cras::optional<std::string>>& getCameraUniqueName();
43  const cras::optional<cras::optional<std::string>>& getCameraUniqueName() const;
44 
45  cras::optional<cras::optional<std::string>>& getCameraSerialNumber();
46  const cras::optional<cras::optional<std::string>>& getCameraSerialNumber() const;
47 
48  cras::optional<cras::optional<std::string>>& getCameraMake();
49  const cras::optional<cras::optional<std::string>>& getCameraMake() const;
50 
51  cras::optional<cras::optional<std::string>>& getCameraModel();
52  const cras::optional<cras::optional<std::string>>& getCameraModel() const;
53 
54  cras::optional<cras::optional<std::string>>& getLensMake();
55  const cras::optional<cras::optional<std::string>>& getLensMake() const;
56 
57  cras::optional<cras::optional<std::string>>& getLensModel();
58  const cras::optional<cras::optional<std::string>>& getLensModel() const;
59 
60  cras::optional<cras::optional<int>>& getRotation();
61  const cras::optional<cras::optional<int>>& getRotation() const;
62 
63  cras::optional<cras::optional<ros::Time>>& getCreationTime();
64  const cras::optional<cras::optional<ros::Time>>& getCreationTime() const;
65 
66  cras::optional<cras::optional<double>>& getCropFactor();
67  const cras::optional<cras::optional<double>>& getCropFactor() const;
68 
69  cras::optional<cras::optional<SensorSize>>& getSensorSizeMM();
70  const cras::optional<cras::optional<SensorSize>>& getSensorSizeMM() const;
71 
72  cras::optional<cras::optional<double>>& getFocalLength35MM();
73  const cras::optional<cras::optional<double>>& getFocalLength35MM() const;
74 
75  cras::optional<cras::optional<double>>& getFocalLengthPx();
76  const cras::optional<cras::optional<double>>& getFocalLengthPx() const;
77 
78  cras::optional<cras::optional<double>>& getFocalLengthMM();
79  const cras::optional<cras::optional<double>>& getFocalLengthMM() const;
80 
81  cras::optional<cras::optional<IntrinsicMatrix>>& getIntrinsicMatrix();
82  const cras::optional<cras::optional<IntrinsicMatrix>>& getIntrinsicMatrix() const;
83 
84  cras::optional<cras::optional<DistortionData>>& getDistortion();
85  const cras::optional<cras::optional<DistortionData>>& getDistortion() const;
86 
87  cras::optional<GNSSFixAndDetail>& getGNSSPosition();
88  const cras::optional<GNSSFixAndDetail>& getGNSSPosition() const;
89 
90  cras::optional<cras::optional<compass_msgs::Azimuth>>& getAzimuth();
91  const cras::optional<cras::optional<compass_msgs::Azimuth>>& getAzimuth() const;
92 
93  cras::optional<cras::optional<sensor_msgs::MagneticField>>& getMagneticField();
94  const cras::optional<cras::optional<sensor_msgs::MagneticField>>& getMagneticField() const;
95 
96  cras::optional<cras::optional<RollPitch>>& getRollPitch();
97  const cras::optional<cras::optional<RollPitch>>& getRollPitch() const;
98 
99  cras::optional<cras::optional<geometry_msgs::Vector3>>& getAngularVelocity();
100  const cras::optional<cras::optional<geometry_msgs::Vector3>>& getAngularVelocity() const;
101 
102  cras::optional<cras::optional<geometry_msgs::Vector3>>& getAcceleration();
103  const cras::optional<cras::optional<geometry_msgs::Vector3>>& getAcceleration() const;
104 
105  cras::optional<cras::optional<sensor_msgs::CameraInfo>>& getCameraInfo();
106  const cras::optional<cras::optional<sensor_msgs::CameraInfo>>& getCameraInfo() const;
107 
108  cras::optional<cras::optional<sensor_msgs::Imu>>& getImu();
109  const cras::optional<cras::optional<sensor_msgs::Imu>>& getImu() const;
110 
111  cras::optional<cras::optional<geometry_msgs::Transform>>& getOpticalFrameTF();
112  const cras::optional<cras::optional<geometry_msgs::Transform>>& getOpticalFrameTF() const;
113 
114  cras::optional<cras::optional<geometry_msgs::Transform>>& getZeroRollPitchTF();
115  const cras::optional<cras::optional<geometry_msgs::Transform>>& getZeroRollPitchTF() const;
116 
117  cras::optional<cras::optional<vision_msgs::Detection2DArray>>& getFaces();
118  const cras::optional<cras::optional<vision_msgs::Detection2DArray>>& getFaces() const;
119 
120 private:
121  struct Impl;
122  std::shared_ptr<Impl> data;
123 };
124 
128 struct TimedMetadataCache final
129 {
132 
133  void clear();
134 
135  std::vector<TimedMetadata<int>>& rotation();
136  const std::vector<TimedMetadata<int>>& rotation() const;
137 
138  std::vector<TimedMetadata<double>>& cropFactor();
139  const std::vector<TimedMetadata<double>>& cropFactor() const;
140 
141  std::vector<TimedMetadata<SensorSize>>& sensorSizeMM();
142  const std::vector<TimedMetadata<SensorSize>>& sensorSizeMM() const;
143 
144  std::vector<TimedMetadata<double>>& focalLength35MM();
145  const std::vector<TimedMetadata<double>>& focalLength35MM() const;
146 
147  std::vector<TimedMetadata<double>>& focalLengthMM();
148  const std::vector<TimedMetadata<double>>& focalLengthMM() const;
149 
150  std::vector<TimedMetadata<double>>& focalLengthPx();
151  const std::vector<TimedMetadata<double>>& focalLengthPx() const;
152 
153  std::vector<TimedMetadata<IntrinsicMatrix>>& intrinsicMatrix();
154  const std::vector<TimedMetadata<IntrinsicMatrix>>& intrinsicMatrix() const;
155 
156  std::vector<TimedMetadata<std::pair<DistortionType, Distortion>>>& distortion();
157  const std::vector<TimedMetadata<std::pair<DistortionType, Distortion>>>& distortion() const;
158 
159  std::vector<TimedMetadata<compass_msgs::Azimuth>>& azimuth();
160  const std::vector<TimedMetadata<compass_msgs::Azimuth>>& azimuth() const;
161 
162  std::vector<TimedMetadata<sensor_msgs::MagneticField>>& magneticField();
163  const std::vector<TimedMetadata<sensor_msgs::MagneticField>>& magneticField() const;
164 
165  std::vector<TimedMetadata<RollPitch>>& rollPitch();
166  const std::vector<TimedMetadata<RollPitch>>& rollPitch() const;
167 
168  std::vector<TimedMetadata<geometry_msgs::Vector3>>& acceleration();
169  const std::vector<TimedMetadata<geometry_msgs::Vector3>>& acceleration() const;
170 
171  std::vector<TimedMetadata<geometry_msgs::Vector3>>& angularVelocity();
172  const std::vector<TimedMetadata<geometry_msgs::Vector3>>& angularVelocity() const;
173 
174  std::vector<TimedMetadata<vision_msgs::Detection2DArray>>& faces();
175  const std::vector<TimedMetadata<vision_msgs::Detection2DArray>>& faces() const;
176 
177  std::vector<TimedMetadata<sensor_msgs::CameraInfo>>& cameraInfo();
178  const std::vector<TimedMetadata<sensor_msgs::CameraInfo>>& cameraInfo() const;
179 
180  std::vector<TimedMetadata<sensor_msgs::Imu>>& imu();
181  const std::vector<TimedMetadata<sensor_msgs::Imu>>& imu() const;
182 
183  std::vector<TimedMetadata<geometry_msgs::Transform>>& opticalFrameTF();
184  const std::vector<TimedMetadata<geometry_msgs::Transform>>& opticalFrameTF() const;
185 
186  std::vector<TimedMetadata<geometry_msgs::Transform>>& zeroRollPitchTF();
187  const std::vector<TimedMetadata<geometry_msgs::Transform>>& zeroRollPitchTF() const;
188 
189  std::vector<TimedMetadata<GNSSFixAndDetail>>& gnssPosition();
190  const std::vector<TimedMetadata<GNSSFixAndDetail>>& gnssPosition() const;
191 
192 private:
193  struct Impl;
194  std::unique_ptr<Impl> data;
195 };
196 
200 struct MetadataCache final
201 {
204 };
205 
213 template<typename M>
214 static bool CompareStamp(const TimedMetadata<M>& a, const StreamTime& b)
215 {
216  return a.stamp > b;
217 }
218 
226 template<typename M>
227 auto findLastUpToStamp(const std::vector<TimedMetadata<M>>& data, const StreamTime& stamp)
228 {
229  return std::lower_bound(data.crbegin(), data.crend(), stamp, &CompareStamp<M>);
230 }
231 
240 template<typename M>
241 cras::optional<TimedMetadata<M>> findLastUpToStamp(const std::vector<TimedMetadata<M>>& data, const StreamTime& stamp,
242  const cras::optional<M>& defaultVal)
243 {
244  const auto it = findLastUpToStamp(data, stamp);
245  if (it != data.crend())
246  return *it;
247  if (defaultVal.has_value())
248  return TimedMetadata<M>{StreamTime{}, *defaultVal};
249  return cras::nullopt;
250 }
251 
252 }
optional.hpp
movie_publisher::TimedMetadataCache::opticalFrameTF
std::vector< TimedMetadata< geometry_msgs::Transform > > & opticalFrameTF()
movie_publisher::MetadataCache
Metadata cache.
Definition: metadata_cache.h:200
movie_publisher::TimedMetadataCache::rollPitch
std::vector< TimedMetadata< RollPitch > > & rollPitch()
movie_publisher::TimedMetadataCache::focalLengthMM
std::vector< TimedMetadata< double > > & focalLengthMM()
movie_publisher::LatestMetadataCache::getRollPitch
cras::optional< cras::optional< RollPitch > > & getRollPitch()
movie_publisher::TimedMetadataCache
Metadata cache.
Definition: metadata_cache.h:128
movie_publisher::LatestMetadataCache::getOpticalFrameTF
cras::optional< cras::optional< geometry_msgs::Transform > > & getOpticalFrameTF()
movie_publisher::TimedMetadataCache::gnssPosition
std::vector< TimedMetadata< GNSSFixAndDetail > > & gnssPosition()
movie_publisher::LatestMetadataCache::getCameraUniqueName
cras::optional< cras::optional< std::string > > & getCameraUniqueName()
movie_publisher::TimedMetadataCache::imu
std::vector< TimedMetadata< sensor_msgs::Imu > > & imu()
movie_publisher::TimedMetadataCache::cameraInfo
std::vector< TimedMetadata< sensor_msgs::CameraInfo > > & cameraInfo()
movie_publisher::TimedMetadataCache::focalLengthPx
std::vector< TimedMetadata< double > > & focalLengthPx()
movie_publisher::TimedMetadata
Timestamping wrapper for any kind of metadata.
Definition: metadata_type.h:72
movie_publisher::LatestMetadataCache::clear
void clear()
movie_publisher::TimedMetadataCache::intrinsicMatrix
std::vector< TimedMetadata< IntrinsicMatrix > > & intrinsicMatrix()
movie_publisher::findLastUpToStamp
auto findLastUpToStamp(const std::vector< TimedMetadata< M >> &data, const StreamTime &stamp)
Find index of the latest data from data that have their timestamp less than or equal to stamp.
Definition: metadata_cache.h:227
movie_publisher::LatestMetadataCache::getAngularVelocity
cras::optional< cras::optional< geometry_msgs::Vector3 > > & getAngularVelocity()
data
data
movie_publisher::LatestMetadataCache::getCameraMake
cras::optional< cras::optional< std::string > > & getCameraMake()
movie_publisher::StreamTime
Time type denoting movie stream time.
Definition: types.h:115
movie_publisher::TimedMetadataCache::data
std::unique_ptr< Impl > data
PIMPL.
Definition: metadata_cache.h:193
movie_publisher::LatestMetadataCache::getFocalLengthMM
cras::optional< cras::optional< double > > & getFocalLengthMM()
movie_publisher::LatestMetadataCache::getGNSSPosition
cras::optional< GNSSFixAndDetail > & getGNSSPosition()
movie_publisher::LatestMetadataCache::getCameraModel
cras::optional< cras::optional< std::string > > & getCameraModel()
movie_publisher::TimedMetadataCache::zeroRollPitchTF
std::vector< TimedMetadata< geometry_msgs::Transform > > & zeroRollPitchTF()
movie_publisher::LatestMetadataCache::getZeroRollPitchTF
cras::optional< cras::optional< geometry_msgs::Transform > > & getZeroRollPitchTF()
movie_publisher::MetadataCache::timed
TimedMetadataCache timed
Timed metadata.
Definition: metadata_cache.h:203
movie_publisher::TimedMetadataCache::distortion
std::vector< TimedMetadata< std::pair< DistortionType, Distortion > > > & distortion()
movie_publisher::LatestMetadataCache::~LatestMetadataCache
~LatestMetadataCache()
movie_publisher::LatestMetadataCache::getMagneticField
cras::optional< cras::optional< sensor_msgs::MagneticField > > & getMagneticField()
movie_publisher::TimedMetadataCache::~TimedMetadataCache
~TimedMetadataCache()
movie_publisher::TimedMetadataCache::TimedMetadataCache
TimedMetadataCache()
movie_publisher::LatestMetadataCache::getRotation
cras::optional< cras::optional< int > > & getRotation()
movie_publisher::LatestMetadataCache::getLensMake
cras::optional< cras::optional< std::string > > & getLensMake()
movie_publisher::LatestMetadataCache::getIntrinsicMatrix
cras::optional< cras::optional< IntrinsicMatrix > > & getIntrinsicMatrix()
movie_publisher::LatestMetadataCache
Latest metadata of each type.
Definition: metadata_cache.h:32
movie_publisher::TimedMetadataCache::magneticField
std::vector< TimedMetadata< sensor_msgs::MagneticField > > & magneticField()
movie_publisher::LatestMetadataCache::data
std::shared_ptr< Impl > data
PIMPL.
Definition: metadata_cache.h:121
movie_publisher::TimedMetadataCache::angularVelocity
std::vector< TimedMetadata< geometry_msgs::Vector3 > > & angularVelocity()
movie_publisher::LatestMetadataCache::getSensorSizeMM
cras::optional< cras::optional< SensorSize > > & getSensorSizeMM()
movie_publisher::LatestMetadataCache::getFocalLengthPx
cras::optional< cras::optional< double > > & getFocalLengthPx()
movie_publisher::LatestMetadataCache::getCreationTime
cras::optional< cras::optional< ros::Time > > & getCreationTime()
movie_publisher::TimedMetadata::stamp
StreamTime stamp
Timestamp of the data (in stream time).
Definition: metadata_type.h:75
movie_publisher::TimedMetadataCache::clear
void clear()
movie_publisher::TimedMetadataCache::azimuth
std::vector< TimedMetadata< compass_msgs::Azimuth > > & azimuth()
movie_publisher::CompareStamp
static bool CompareStamp(const TimedMetadata< M > &a, const StreamTime &b)
Compare TimedMetadata according to their stamps (in decreasing order).
Definition: metadata_cache.h:214
movie_publisher::LatestMetadataCache::getCameraGeneralName
cras::optional< cras::optional< std::string > > & getCameraGeneralName()
movie_publisher::TimedMetadataCache::focalLength35MM
std::vector< TimedMetadata< double > > & focalLength35MM()
movie_publisher::LatestMetadataCache::getLensModel
cras::optional< cras::optional< std::string > > & getLensModel()
movie_publisher::TimedMetadataCache::sensorSizeMM
std::vector< TimedMetadata< SensorSize > > & sensorSizeMM()
movie_publisher::TimedMetadataCache::cropFactor
std::vector< TimedMetadata< double > > & cropFactor()
movie_publisher::LatestMetadataCache::getImu
cras::optional< cras::optional< sensor_msgs::Imu > > & getImu()
movie_publisher::LatestMetadataCache::getCameraInfo
cras::optional< cras::optional< sensor_msgs::CameraInfo > > & getCameraInfo()
movie_publisher
Definition: ExifBaseMetadataExtractor.h:27
movie_publisher::LatestMetadataCache::getAcceleration
cras::optional< cras::optional< geometry_msgs::Vector3 > > & getAcceleration()
movie_publisher::LatestMetadataCache::getDistortion
cras::optional< cras::optional< DistortionData > > & getDistortion()
movie_publisher::LatestMetadataCache::getFocalLength35MM
cras::optional< cras::optional< double > > & getFocalLength35MM()
movie_publisher::LatestMetadataCache::getAzimuth
cras::optional< cras::optional< compass_msgs::Azimuth > > & getAzimuth()
movie_publisher::LatestMetadataCache::getCropFactor
cras::optional< cras::optional< double > > & getCropFactor()
movie_publisher::TimedMetadataCache::faces
std::vector< TimedMetadata< vision_msgs::Detection2DArray > > & faces()
movie_publisher::LatestMetadataCache::getFaces
cras::optional< cras::optional< vision_msgs::Detection2DArray > > & getFaces()
movie_publisher::LatestMetadataCache::LatestMetadataCache
LatestMetadataCache()
metadata_type.h
Types of metadata.
movie_publisher::MetadataCache::latest
LatestMetadataCache latest
Latest metadata of each type.
Definition: metadata_cache.h:202
movie_publisher::TimedMetadataCache::acceleration
std::vector< TimedMetadata< geometry_msgs::Vector3 > > & acceleration()
movie_publisher::TimedMetadataCache::rotation
std::vector< TimedMetadata< int > > & rotation()
movie_publisher::LatestMetadataCache::getCameraSerialNumber
cras::optional< cras::optional< std::string > > & getCameraSerialNumber()


movie_publisher
Author(s): Martin Pecka
autogenerated on Wed May 28 2025 02:07:22