Skip to content

Commit 3b2e262

Browse files
committed
Keyframe: New implementation calculating values ondemand
- GetValue() calculates the value at the given position now ondemand, without caching values as previously. First, it uses binary search to find the segment (start and end point) containing the given position. Constant and linear interpolation are straightforward, bezier curves are calculating by binary search between the end points until a point on the curve is found with a X coordinate close enough to the given position. That points Y coordinate is returned. - IsIncreasing(), GetRepeatFraction(), GetDelta() use GetValue() instead of accessing the (removed) Values vector. - Removed now unused private functions, and the unused public Process(). First test results show good performance improvements for the "rendering case" (setting up the keyframe points at once, then getting all values) and drastic performance improvements for the "preview case" (changing keyframe points, mixed with getting values).
1 parent bd82403 commit 3b2e262

File tree

2 files changed

+105
-412
lines changed

2 files changed

+105
-412
lines changed

include/KeyFrame.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,7 @@ namespace openshot {
6363
*/
6464
class Keyframe {
6565
private:
66-
bool needs_update;
67-
double FactorialLookup[4];
6866
std::vector<Point> Points; ///< Vector of all Points
69-
std::vector<Coordinate> Values; ///< Vector of all Values (i.e. the processed coordinates from the curve)
70-
71-
// Process an individual segment
72-
void ProcessSegment(int Segment, Point p1, Point p2);
73-
74-
// create lookup table for fast factorial calculation
75-
void CreateFactorialTable();
76-
77-
// Get a factorial for a coordinate
78-
double Factorial(int64_t n);
79-
80-
// Calculate the factorial function for Bernstein basis
81-
double Ni(int64_t n, int64_t i);
82-
83-
// Calculate Bernstein Basis
84-
double Bernstein(int64_t n, int64_t i, double t);
8567

8668
public:
8769

@@ -155,14 +137,6 @@ namespace openshot {
155137
void SetJson(std::string value); ///< Load JSON string into this object
156138
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
157139

158-
/**
159-
* @brief Calculate all of the values for this keyframe.
160-
*
161-
* This clears any existing data in the "values" vector. This method is automatically called
162-
* by AddPoint(), so you don't typically need to call this method.
163-
*/
164-
void Process();
165-
166140
/// Remove a point by matching a coordinate
167141
void RemovePoint(Point p);
168142

0 commit comments

Comments
 (0)