Skip to content

Commit

Permalink
Removed unused class KeyframeBase
Browse files Browse the repository at this point in the history
Moved the functions IsPointBeforeX(), InterpolateLinearCurve() , InterpolateBezierCurve() and InterpolateBetween() from KeyFrameBase files to KeyFrame files
  • Loading branch information
BrennoCaldato committed Feb 1, 2021
1 parent c0c2a82 commit 9df3b51
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 210 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -86,7 +86,6 @@ set(OPENSHOT_SOURCES
FrameMapper.cpp
Json.cpp
KeyFrame.cpp
KeyFrameBase.cpp
TrackedObjectBase.cpp
TrackedObjectBBox.cpp
OpenShotVersion.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/Clip.cpp
Expand Up @@ -1210,7 +1210,7 @@ void Clip::AddEffect(EffectBase* effect)
// Sort effects
sort_effects();

// Add Tracker to Timeline
// Add Tracked Object to Timeline
if (effect->info.has_tracked_object){

Timeline* parentTimeline = (Timeline *) ParentTimeline();
Expand Down
94 changes: 77 additions & 17 deletions src/KeyFrame.cpp
Expand Up @@ -31,35 +31,95 @@
#include "KeyFrame.h"
#include "Exceptions.h"

#include <cassert> // For assert()
#include <iostream> // For std::cout
#include <iomanip> // For std::setprecision
#include <algorithm>
#include <functional>
#include <utility>
#include <cassert> // For assert()
#include <iostream> // For std::cout
#include <iomanip> // For std::setprecision

using namespace std;
using namespace openshot;

namespace{
template<typename Check>
int64_t SearchBetweenPoints(Point const & left, Point const & right, int64_t const current, Check check) {
int64_t start = left.co.X;
int64_t stop = right.co.X;
while (start < stop) {
int64_t const mid = (start + stop + 1) / 2;
double const value = InterpolateBetween(left, right, mid, 0.01);
if (check(round(value), current)) {
start = mid;
} else {
stop = mid - 1;
namespace openshot{

// Check if the X coordinate of a given Point is lower than a given value
bool IsPointBeforeX(Point const & p, double const x) {
return p.co.X < x;
}

// Linear interpolation between two points
double InterpolateLinearCurve(Point const & left, Point const & right, double const target) {
double const diff_Y = right.co.Y - left.co.Y;
double const diff_X = right.co.X - left.co.X;
double const slope = diff_Y / diff_X;
return left.co.Y + slope * (target - left.co.X);
}

// Bezier interpolation between two points
double InterpolateBezierCurve(Point const & left, Point const & right, double const target, double const allowed_error) {
double const X_diff = right.co.X - left.co.X;
double const Y_diff = right.co.Y - left.co.Y;
Coordinate const p0 = left.co;
Coordinate const p1 = Coordinate(p0.X + left.handle_right.X * X_diff, p0.Y + left.handle_right.Y * Y_diff);
Coordinate const p2 = Coordinate(p0.X + right.handle_left.X * X_diff, p0.Y + right.handle_left.Y * Y_diff);
Coordinate const p3 = right.co;

double t = 0.5;
double t_step = 0.25;
do {
// Bernstein polynoms
double B[4] = {1, 3, 3, 1};
double oneMinTExp = 1;
double tExp = 1;
for (int i = 0; i < 4; ++i, tExp *= t) {
B[i] *= tExp;
}
for (int i = 0; i < 4; ++i, oneMinTExp *= 1 - t) {
B[4 - i - 1] *= oneMinTExp;
}
double const x = p0.X * B[0] + p1.X * B[1] + p2.X * B[2] + p3.X * B[3];
double const y = p0.Y * B[0] + p1.Y * B[1] + p2.Y * B[2] + p3.Y * B[3];
if (fabs(target - x) < allowed_error) {
return y;
}
if (x > target) {
t -= t_step;
}
else {
t += t_step;
}
t_step /= 2;
} while (true);
}

// Interpolate two points using the right Point's interpolation method
double InterpolateBetween(Point const & left, Point const & right, double target, double allowed_error) {
assert(left.co.X < target);
assert(target <= right.co.X);
switch (right.interpolation) {
case CONSTANT: return left.co.Y;
case LINEAR: return InterpolateLinearCurve(left, right, target);
case BEZIER: return InterpolateBezierCurve(left, right, target, allowed_error);
}
return start;
}
}


template<typename Check>
int64_t SearchBetweenPoints(Point const & left, Point const & right, int64_t const current, Check check) {
int64_t start = left.co.X;
int64_t stop = right.co.X;
while (start < stop) {
int64_t const mid = (start + stop + 1) / 2;
double const value = InterpolateBetween(left, right, mid, 0.01);
if (check(round(value), current)) {
start = mid;
} else {
stop = mid - 1;
}
}
return start;
}

// Constructor which sets the default point & coordinate at X=1
Keyframe::Keyframe(double value) {
Expand Down
17 changes: 14 additions & 3 deletions src/KeyFrame.h
Expand Up @@ -37,10 +37,21 @@
#include "Fraction.h"
#include "Point.h"
#include "Json.h"
#include "KeyFrameBase.h"

namespace openshot {

/// Check if the X coordinate of a given Point is lower than a given value
bool IsPointBeforeX(Point const & p, double const x);

/// Linear interpolation between two points
double InterpolateLinearCurve(Point const & left, Point const & right, double const target);

/// Bezier interpolation between two points
double InterpolateBezierCurve(Point const & left, Point const & right, double const target, double const allowed_error);

/// Interpolate two points using the right Point's interpolation method
double InterpolateBetween(Point const & left, Point const & right, double target, double allowed_error);

/**
* @brief A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
*
Expand All @@ -58,7 +69,7 @@ namespace openshot {
* kf.PrintValues();
* \endcode
*/
class Keyframe : public KeyframeBase {
class Keyframe {


private:
Expand Down Expand Up @@ -143,7 +154,7 @@ namespace openshot {

/// Scale all points by a percentage (good for evenly lengthening or shortening an openshot::Keyframe)
/// 1.0 = same size, 1.05 = 5% increase, etc...
void ScalePoints(double scale) override;
void ScalePoints(double scale);

/// Replace an existing point with a new point
void UpdatePoint(int64_t index, Point p);
Expand Down
103 changes: 0 additions & 103 deletions src/KeyFrameBase.cpp

This file was deleted.

85 changes: 0 additions & 85 deletions src/KeyFrameBase.h

This file was deleted.

0 comments on commit 9df3b51

Please sign in to comment.