Trajectory.cpp
Go to the documentation of this file.
1#include "Trajectory.h"
2
3
4using namespace armarx::trajectory;
5
9
10void
12{
13 tracks.clear();
14}
15
18{
19 return tracks.emplace(id, VariantTrack{id}).first->second;
20}
21
24{
25 return tracks.emplace(id, VariantTrack{id, updateFunc}).first->second;
26}
27
28void
30{
31 (*this)[id].addKeyframe(keyframe);
32}
33
34void
35Trajectory::addKeyframe(const TrackID& id, float time, const VariantValue& value)
36{
37 addKeyframe(id, VariantKeyframe{time, value});
38}
39
40void
41Trajectory::update(float time, bool ignoreEmptyTracks)
42{
43 for (auto& it : tracks)
44 {
45 it.second.update(time, ignoreEmptyTracks);
46 }
47}
48
51{
52 try
53 {
54 return tracks.at(id);
55 }
56 catch (const std::out_of_range&)
57 {
58 throw error::NoTrackWithID(id);
59 }
60}
61
62const VariantTrack&
64{
65 try
66 {
67 return tracks.at(id);
68 }
69 catch (const std::out_of_range&)
70 {
71 throw error::NoTrackWithID(id);
72 }
73}
74
75std::ostream&
77{
78 os << "Trajectory with " << trajectory.tracks.size() << " tracks: ";
79 for (const auto& [name, track] : trajectory.tracks)
80 {
81 os << "\n - " << track;
82 }
83 return os;
84}
85
86namespace armarx
87{
88
89 auto
90 trajectory::toUpdateFunc(std::function<void(float)> func) -> VariantTrack::UpdateFunc
91 {
92 return [func](VariantValue value) { func(std::get<float>(value)); };
93 }
94
95 auto
96 trajectory::toUpdateFunc(std::function<void(const Eigen::MatrixXf&)> func)
98 {
99 return [func](VariantValue value) { func(std::get<Eigen::MatrixXf>(value)); };
100 }
101
102 auto
103 trajectory::toUpdateFunc(std::function<void(const Eigen::Quaternionf&)> func)
105 {
106 return [func](VariantValue value) { func(std::get<Eigen::Quaternionf>(value)); };
107 }
108
109} // namespace armarx
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.
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
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.
This file offers overloads of toIce() and fromIce() functions for STL container types.