Trajectory.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4
5#include "Track.h"
6
7namespace armarx::trajectory
8{
9
10 /**
11 * @brief This class is used to update entities based on trajectory
12 * defined by keyframes.
13 *
14 * A Trajectory is a collection of tracks, where each track represents a
15 * timeline of a single value. A track is composed of keyframes, where
16 * each keyframe represents a value at a specific time on the timeline.
17 *
18 * @see Track
19 */
21 {
22 public:
23 /// Constructor.
24 Trajectory();
25
26
27 /// Clear the trajectory of all tracks.
28 void clear();
29
30
31 /**
32 * @brief Add track with the given ID (and no update function).
33 * If there is already a track with the given ID, it is overwritten.
34 */
35 VariantTrack& addTrack(const TrackID& id);
36
37 /**
38 * @brief Add track with the given ID and update function.
39 * If there is already a track with the given ID, it is overwritten.
40 */
41 VariantTrack& addTrack(const TrackID& id, const VariantTrack::UpdateFunc& updateFunc);
42
43
44 /// Add a keyframe to the specified track.
45 /// @throw `error::NoTrackWithID` if there is not track with the given ID
46 void addKeyframe(const TrackID& id, const VariantKeyframe& keyframe);
47
48 /// Add a keyframe to the specified track.
49 /// @throw `error::NoTrackWithID` if there is not track with the given ID
50 void addKeyframe(const TrackID& id, float time, const VariantValue& value);
51
52
53 /**
54 * @brief Update all tracks for the given time.
55 * @param ignoreEmptyTracks If true, empty tracks are ignored.
56 * @throws `error::EmptyTrack` If `ignoreEmptyTracks` is false and a track is empty.
57 */
58 void update(float time, bool ignoreEmptyTracks = false);
59
60
61 /// Get the track with the given ID.
62 /// @throw `error::NoTrackWithID` if there is not track with the given ID
64
65 /// Get the track with the given ID.
66 /// @throw `error::NoTrackWithID` if there is not track with the given ID
67 const VariantTrack& operator[](const TrackID& id) const;
68
69 friend std::ostream& operator<<(std::ostream& os, const Trajectory& trajectory);
70
71
72 private:
73 /// The tracks.
74 std::map<TrackID, VariantTrack> tracks;
75 };
76
77 std::ostream& operator<<(std::ostream& os, const Trajectory& trajectory);
78
79 // UPDATE FUNCTION HELPERS
80
81 /// Get an update function for value assignments.
82 template <typename ValueT>
84 updateValue(ValueT& v)
85 {
86 return [&v](VariantValue value) { v = std::get<ValueT>(value); };
87 }
88
89 /// Wrap the function in a Track::UpdateFunc.
90 VariantTrack::UpdateFunc toUpdateFunc(std::function<void(float)> func);
91 /// Wrap the function in a Track::UpdateFunc.
92 VariantTrack::UpdateFunc toUpdateFunc(std::function<void(const Eigen::MatrixXf&)> func);
93 /// Wrap the function in a Track::UpdateFunc.
94 VariantTrack::UpdateFunc toUpdateFunc(std::function<void(const Eigen::Quaternionf&)> func);
95
96} // namespace armarx::trajectory
std::function< void(VariantValue)> UpdateFunc
Definition Track.h:37
This class is used to update entities based on trajectory defined by keyframes.
Definition Trajectory.h:21
void update(float time, bool ignoreEmptyTracks=false)
Update all tracks for the given time.
VariantTrack & operator[](const TrackID &id)
Get the track with the given ID.
VariantTrack & addTrack(const TrackID &id)
Add track with the given ID (and no update function).
void addKeyframe(const TrackID &id, const VariantKeyframe &keyframe)
Add a keyframe to the specified track.
friend std::ostream & operator<<(std::ostream &os, const Trajectory &trajectory)
void clear()
Clear the trajectory of all tracks.
Quaternion< float, 0 > Quaternionf
VariantTrack::UpdateFunc toUpdateFunc(std::function< void(float)> func)
Wrap the function in a Track::UpdateFunc.
std::variant< float, Eigen::MatrixXf, Eigen::Quaternionf > VariantValue
Variant for trajectory values.
std::ostream & operator<<(std::ostream &os, const Track< ValueT > &track)
Definition Track.h:278
VariantTrack::UpdateFunc updateValue(ValueT &v)
Get an update function for value assignments.
Definition Trajectory.h:84
Keyframe< VariantValue > VariantKeyframe
A keyframe with of type TValue.
Definition Track.h:25
Track< VariantValue > VariantTrack
A track with value type TValue.
Definition Track.h:129
std::string TrackID
ID of tracks.