28#ifndef EASY3D_RENDERER_KEYFRAME_INTERPOLATOR_H
29#define EASY3D_RENDERER_KEYFRAME_INTERPOLATOR_H
31#include <easy3d/core/types.h>
32#include "easy3d/util/signal.h"
33#include <easy3d/util/timer.h>
34#include <easy3d/renderer/frame.h>
45 class TrianglesDrawable;
146 const std::vector<float>& times,
147 const std::vector<float>& dwells);
445 std::vector<float> length_fraction()
const;
450 static float segment_fraction(
float w,
bool stop_start,
bool stop_end);
474 const vec4& color =
vec4(0.15f, 0.45f, 1.0f, 1.0f));
499 const vec4& color =
vec4(0.2f, 0.7f, 0.3f, 1.0f))
const;
571 Keyframe(
const Frame& fr,
float t);
572 const vec3& position()
const {
return p_; }
573 const quat& orientation()
const {
return q_; }
574 float time()
const {
return time_; }
575 void set_time(
float t) { time_ = t; }
576 void set_position(
const vec3& p) { p_ = p; }
577 void set_orientation(
const quat& q) { q_ = q; }
585 float dwell_time()
const {
return dwell_time_; }
591 void set_dwell_time(
float seconds) { dwell_time_ = seconds; }
592 void flip_if_needed(
const quat& prev);
597 float dwell_time_ = 0.0f;
605 void append_camera_glyphs(
float camera_width,
float fov,
float aspect,
606 std::vector<vec3>& points, std::vector<unsigned int>& indices)
const;
613 std::vector<Keyframe> keyframes_;
614 std::vector<Frame> interpolated_path_;
619 Method interpolation_method_;
620 float interpolation_speed_;
621 bool interpolation_started_;
622 bool manual_playback_ =
false;
623 bool timer_mode_used_ =
false;
624 int last_stopped_index_;
625 float playback_elapsed_ = 0.0f;
629 bool path_is_periodic_ =
false;
A perspective or orthographic camera.
Definition camera.h:142
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition frame.h:79
A keyframe interpolator for animation generation.
Definition keyframe_interpolator.h:94
float interpolation_speed() const
Returns the current interpolation speed.
Definition keyframe_interpolator.h:309
const quat & keyframe_orientation(std::size_t index) const
Returns the orientation of the index-th keyframe.
Definition keyframe_interpolator.cpp:285
void delete_last_keyframe()
Removes the lastly added keyframe from the path.
Definition keyframe_interpolator.cpp:195
void set_path_periodic(bool periodic)
Sets whether the path is interpolated as a closed periodic loop.
Definition keyframe_interpolator.cpp:338
static std::size_t camera_glyph_triangles()
The number of triangles one camera glyph occupies in update_cameras_drawable().
Definition keyframe_interpolator.cpp:463
Method
Definition keyframe_interpolator.h:292
@ INTERPOLATION
Interpolate between keyframes.
Definition keyframe_interpolator.h:294
@ FITTING
Fit a curve to the keyframes.
Definition keyframe_interpolator.h:293
float duration() const
Returns the duration of the KeyframeInterpolator path, expressed in seconds.
Definition keyframe_interpolator.cpp:290
Signal interpolation_stopped
Emitted when the interpolation is stopped.
Definition keyframe_interpolator.h:633
std::size_t number_of_keyframes() const
Returns the number of keyframes used by the interpolation.
Definition keyframe_interpolator.h:213
bool advance_interpolation()
Advance manual playback by one interpolation sample.
Definition keyframe_interpolator.cpp:399
float playback_elapsed() const
Returns the playback position in seconds, along the path's timeline (travel plus dwell).
Definition keyframe_interpolator.cpp:309
void set_keyframe_orientation(std::size_t index, const quat &q)
Sets the orientation of the index-th keyframe.
Definition keyframe_interpolator.cpp:240
const std::vector< Frame > & interpolate()
Computes and returns all the interpolated frames.
Definition keyframe_interpolator.cpp:676
bool replace_keyframes(const std::vector< Frame > &frames, const std::vector< float > ×, const std::vector< float > &dwells)
Atomically replaces the path with frames, times and optional dwells.
Definition keyframe_interpolator.cpp:204
void set_keyframe_time(std::size_t index, float t)
Sets the time corresponding to the index-th keyframe.
Definition keyframe_interpolator.cpp:226
virtual ~KeyframeInterpolator()
Definition keyframe_interpolator.cpp:152
void set_interpolation_method(Method m)
Sets the interpolation_method().
Definition keyframe_interpolator.cpp:316
int interpolation_period() const
Returns the current interpolation period, expressed in milliseconds.
Definition keyframe_interpolator.h:319
void start_interpolation()
Starts the interpolation process.
Definition keyframe_interpolator.cpp:347
void set_keyframe_position(std::size_t index, const vec3 &pos)
Sets the position of the index-th keyframe.
Definition keyframe_interpolator.cpp:233
void set_frame(Frame *const frame)
Sets the frame() associated with the KeyframeInterpolator.
Definition keyframe_interpolator.h:202
bool load_keyframes(std::istream &input)
Reads the camera path's keyframes from a stream.
Definition keyframe_interpolator.cpp:544
void set_interpolation_speed(float speed)
Sets the interpolation_speed().
Definition keyframe_interpolator.cpp:322
int frame_rate() const
Returns the desired frame rate. Default value is 30.
Definition keyframe_interpolator.h:326
Frame keyframe(std::size_t index) const
Returns the Frame associated with the keyframe at index.
Definition keyframe_interpolator.cpp:269
void start_manual_interpolation()
Start interpolation without creating a timer or worker thread.
Definition keyframe_interpolator.cpp:388
float total_duration() const
Returns the duration of the path, in seconds.
Definition keyframe_interpolator.cpp:924
const vec3 & keyframe_position(std::size_t index) const
Returns the position of the index-th keyframe.
Definition keyframe_interpolator.cpp:280
void seek_to_keyframe(std::size_t index)
Stops playback and positions the frame and playhead at the given keyframe.
Definition keyframe_interpolator.cpp:421
bool save_keyframes(std::ostream &output) const
Writes the camera path's keyframes to a stream.
Definition keyframe_interpolator.cpp:520
float last_time() const
Returns the time corresponding to the last keyframe, expressed in seconds.
Definition keyframe_interpolator.cpp:302
void toggle_interpolation()
Calls start_interpolation() or stop_interpolation(), depending on is_interpolation_started().
Definition keyframe_interpolator.h:414
bool is_path_periodic() const
Definition keyframe_interpolator.h:358
void set_frame_rate(int fps)
Sets the desired frame rate.
Definition keyframe_interpolator.cpp:330
void stop_interpolation()
Stops an interpolation started with start_interpolation().
Definition keyframe_interpolator.cpp:440
Signal frame_interpolated
Emitted when a frame is interpolated.
Definition keyframe_interpolator.h:632
bool update_cameras_drawable(TrianglesDrawable &drawable, const Camera *camera, float camera_width, const vec4 &color=vec4(0.2f, 0.7f, 0.3f, 1.0f)) const
Fills drawable with the keyframe cameras as solid glyphs, for drawing them as scene geometry.
Definition keyframe_interpolator.cpp:447
bool is_interpolation_started() const
Returns whether the interpolation is being performed.
Definition keyframe_interpolator.h:369
float keyframe_dwell(std::size_t index) const
Returns the dwell time of the index-th keyframe, in seconds.
Definition keyframe_interpolator.cpp:254
Frame * frame() const
Returns the associated Frame, which is interpolated by the KeyframeInterpolator.
Definition keyframe_interpolator.h:195
void delete_path()
Removes all keyframes from the path.
Definition keyframe_interpolator.cpp:259
void set_keyframe_dwell(std::size_t index, float seconds)
Sets the dwell time of the index-th keyframe.
Definition keyframe_interpolator.cpp:247
float first_time() const
Returns the time corresponding to the first keyframe, expressed in seconds.
Definition keyframe_interpolator.cpp:295
Method interpolation_method() const
Returns the interpolation method.
Definition keyframe_interpolator.h:301
bool update_path_drawable(LinesDrawable &drawable, float thickness=2.0f, const vec4 &color=vec4(0.15f, 0.45f, 1.0f, 1.0f))
Fills drawable with the interpolated camera path, for drawing it as scene geometry.
Definition keyframe_interpolator.cpp:509
float keyframe_time(std::size_t index) const
Returns the time corresponding to the index-th keyframe.
Definition keyframe_interpolator.cpp:275
bool add_keyframe(const Frame &frame)
Appends a new keyframe to the path.
Definition keyframe_interpolator.cpp:157
The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields.
Definition drawable_lines.h:40
A light-weight implementation of the simple signal-slot mechanism.
Definition signal.h:56
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition drawable_triangles.h:46
std::string time(double time, int num_digits)
Format a duration in milliseconds using a readable unit.
Definition string.cpp:227
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
Quat< float > quat
A quaternion of float type.
Definition types.h:85
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46