gramods
Loading...
Searching...
No Matches
TrackerBase.hh
1
2#ifndef GRAMODS_TRACK_TRACKERBASE
3#define GRAMODS_TRACK_TRACKERBASE
4
5#include <gmTrack/config.hh>
6
7#include <gmCore/io_float.hh>
8#include <gmCore/Object.hh>
9#include <gmCore/Pose.hh>
10
11#include <chrono>
12#include <optional>
13
14BEGIN_NAMESPACE_GMTRACK;
15
30template<class TYPE> class TrackerBase : public gmCore::Object {
31
32public:
33
34 typedef std::chrono::steady_clock clock;
35
40 struct Sample {
41 clock::time_point time; //< Collect time
42 TYPE value; //< Sample value
43 };
44
48 typedef std::unordered_map<std::string, Sample> State;
49
55 virtual std::optional<State> get() = 0;
56
64 std::string getDefaultKey() override;
65
74 static void merge(std::optional<State> &A, std::optional<State> B) {
75 if (!B) return;
76 if (!A) {
77 A = B;
78 } else {
79 A->merge(B.value());
80 }
81 }
82};
83
84typedef TrackerBase<gmCore::Pose> PoseTracker;
85typedef TrackerBase<bool> BinaryTracker;
86typedef TrackerBase<float> FloatTracker;
87typedef TrackerBase<gmCore::float2> Float2Tracker;
88
89template<> std::string PoseTracker::getDefaultKey();
90template<> std::string BinaryTracker::getDefaultKey();
91template<> std::string FloatTracker::getDefaultKey();
92template<> std::string Float2Tracker::getDefaultKey();
93
94#ifdef gramods_ENABLE_nlohmann_json
95void to_json(nlohmann::json &j, const PoseTracker::Sample &o);
96void from_json(const nlohmann::json &j, PoseTracker::Sample &o);
97
98void to_json(nlohmann::json &j, const BinaryTracker::Sample &o);
99void from_json(const nlohmann::json &j, BinaryTracker::Sample &o);
100
101void to_json(nlohmann::json &j, const FloatTracker::Sample &o);
102void from_json(const nlohmann::json &j, FloatTracker::Sample &o);
103
104void to_json(nlohmann::json &j, const Float2Tracker::Sample &o);
105void from_json(const nlohmann::json &j, Float2Tracker::Sample &o);
106#endif
107
108END_NAMESPACE_GMTRACK;
109
110#endif
Base type for objects in the Gramods package for standardized handling of construction,...
Definition Object.hh:42
The base of trackers of pose, float, float2 or bool data.
Definition TrackerBase.hh:30
std::string getDefaultKey() override
Returns the default key, in Configuration, for the Object, i.e.
static void merge(std::optional< State > &A, std::optional< State > B)
Merges the two specified states.
Definition TrackerBase.hh:74
std::unordered_map< std::string, Sample > State
Definition TrackerBase.hh:48
virtual std::optional< State > get()=0
Reads state data.
Type of a single sample, consisting of the collect time and the value.
Definition TrackerBase.hh:40