Go to the documentation of this file.
12 template <
typename ValueT>
32 template <
typename ValueT>
70 ValueT
at(
float time)
const;
78 void update(
float time,
bool ignoreIfEmpty =
false);
92 void checkValueType(
const ValueT&
value);
100 std::vector<Keyframe<ValueT>> keyframes;
109 operator ValueT()
const;
116 ValueT
value()
const;
131 template <
typename V>
135 return keyframes.empty();
138 template <
typename V>
145 template <
typename V>
149 checkValueType(keyframe.
value);
150 keyframes.push_back(keyframe);
154 template <
typename V>
158 addKeyframe(Keyframe<V>(time,
value));
161 template <
typename V>
168 template <
typename V>
172 std::sort(keyframes.begin(),
175 { return lhs.time < rhs.time; });
179 template <
typename V>
181 Track<V>::checkValueType(
const V&)
194 template <
typename V>
203 if (keyframes.size() == 1)
205 return keyframes.front().value;
208 if (time <= keyframes.front().time)
210 return keyframes.front().value;
212 if (time >= keyframes.back().time)
214 return keyframes.back().value;
219 while (i + 1 <= keyframes.size() && keyframes[i + 1].time < time)
231 return interpolate::linear<V>(t, kf1.
value, kf2.
value);
234 template <
typename V>
238 if (updateFunc && !(ignoreIfEmpty &&
empty()))
240 updateFunc(at(time));
244 template <
typename V>
249 template <
typename V>
250 Track<V>::KeyframeProxy::operator V()
const
252 return track.
at(time);
255 template <
typename V>
262 template <
typename V>
266 track.addKeyframe(time, other.
value());
269 template <
typename V>
273 return track.at(time);
276 template <
typename ValueT>
280 os <<
"Track '" << track.id <<
"' with " << track.keyframes.size() <<
" keyframes: [";
283 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.