Go to the documentation of this file.
13 template <
typename ValueT>
33 template <
typename ValueT>
51 id(id), updateFunc(updateFunc)
73 ValueT
at(
float time)
const;
81 void update(
float time,
bool ignoreIfEmpty =
false);
96 void checkValueType(
const ValueT&
value);
104 std::vector<Keyframe<ValueT>> keyframes;
114 operator ValueT()
const;
121 ValueT
value()
const;
137 template <
typename V>
140 return keyframes.empty();
149 template <
typename V>
152 checkValueType(keyframe.
value);
153 keyframes.push_back(keyframe);
157 template <
typename V>
160 addKeyframe(Keyframe<V>(time,
value));
169 template <
typename V>
172 std::sort(keyframes.begin(), keyframes.end(),
175 return lhs.time < rhs.time;
180 template <
typename V>
181 void Track<V>::checkValueType(
const V&)
194 template <
typename V>
202 if (keyframes.size() == 1)
204 return keyframes.front().value;
207 if (time <= keyframes.front().time)
209 return keyframes.front().value;
211 if (time >= keyframes.back().time)
213 return keyframes.back().value;
218 while (i + 1 <= keyframes.size() && keyframes[i + 1].time < time)
230 return interpolate::linear<V>(t, kf1.
value, kf2.
value);
234 template <
typename V>
237 if (updateFunc && !(ignoreIfEmpty &&
empty()))
239 updateFunc(at(time));
246 track(track), time(time)
249 template <
typename V>
250 Track<V>::KeyframeProxy::operator V()
const
252 return track.
at(time);
255 template <
typename V>
261 template <
typename V>
264 track.addKeyframe(time, other.
value());
267 template <
typename V>
270 return track.at(time);
273 template <
typename ValueT>
276 os <<
"Track '" << track.id <<
"' with " << track.keyframes.size() <<
" keyframes: [";
279 os << kf.
time <<
", ";
std::variant< float, Eigen::MatrixXf, Eigen::Quaternionf > VariantValue
Variant for trajectory values.
A keyframe, representing a value at a given time.
A track represents the timeline of a single value, identified by a track ID.
std::string TrackID
ID of tracks.
void clear()
Clear the track of all keyframes.
void operator=(const ValueT &value)
Add a keyframe on assignment.
ValueT value() const
Get the value at time.
void update(float time, bool ignoreIfEmpty=false)
Call the update function with the interpolated value at the given time.
std::function< void(ValueT)> UpdateFunc
The update function type.
bool empty(const std::string &s)
std::shared_ptr< Value > value()
Keyframe(float time, const ValueT &value)
Constructor.
friend std::ostream & operator<<(std::ostream &os, const Track< V > &track)
KeyframeProxy operator[](float time)
Add a keyframe by assignment: track[time] = value;
A proxy allowing for adding keyframes by: track[time] = value;
ValueT at(float time) const
Get the interpolated value at the given time.
float time
The time on the timeline.
Track(const TrackID &id, UpdateFunc updateFunc)
Construct a track with given ID and update function.
bool empty() const
Indicate whether this track does not contain any keyframes.
Track(const TrackID &id)
Construct a track with given ID (and no update function).
void addKeyframe(const Keyframe< ValueT > &keyframe)
Add a keyframe to this track.