Merge branch 'dev' into blur-flat-regions
This commit is contained in:
@@ -48,7 +48,7 @@ DiagonalCurve::DiagonalCurve (const std::vector<double>& p, int poly_pn)
|
||||
bool identity = true;
|
||||
kind = (DiagonalCurveType)p[0];
|
||||
|
||||
if (kind == DCT_Linear || kind == DCT_Spline || kind == DCT_NURBS) {
|
||||
if (kind == DCT_Linear || kind == DCT_Spline || kind == DCT_NURBS || kind == DCT_CatumullRom) {
|
||||
N = (p.size() - 1) / 2;
|
||||
x = new double[N];
|
||||
y = new double[N];
|
||||
@@ -86,11 +86,12 @@ DiagonalCurve::DiagonalCurve (const std::vector<double>& p, int poly_pn)
|
||||
|
||||
if (!identity) {
|
||||
if (kind == DCT_Spline && N > 2) {
|
||||
//spline_cubic_set ();
|
||||
catmull_rom_set();
|
||||
spline_cubic_set ();
|
||||
} else if (kind == DCT_NURBS && N > 2) {
|
||||
NURBS_set ();
|
||||
fillHash();
|
||||
} else if (kind == DCT_CatumullRom && N > 2) {
|
||||
catmull_rom_set();
|
||||
} else {
|
||||
kind = DCT_Linear;
|
||||
}
|
||||
@@ -325,6 +326,9 @@ inline void catmull_rom_spline(int n_points,
|
||||
if (p1_y == p2_y && (p1_y == 0 || p1_y == 1)) {
|
||||
for (i = 1; i < n_points-1; ++i) {
|
||||
t = p1_x + space * i;
|
||||
if (t >= p2_x) {
|
||||
break;
|
||||
}
|
||||
res_x.push_back(t);
|
||||
res_y.push_back(p1_y);
|
||||
}
|
||||
@@ -459,7 +463,7 @@ double DiagonalCurve::getVal (double t) const
|
||||
}
|
||||
|
||||
case DCT_Linear :
|
||||
// case DCT_Spline :
|
||||
case DCT_Spline :
|
||||
{
|
||||
// values under and over the first and last point
|
||||
if (t > x[N - 1]) {
|
||||
@@ -484,21 +488,21 @@ double DiagonalCurve::getVal (double t) const
|
||||
double h = x[k_hi] - x[k_lo];
|
||||
|
||||
// linear
|
||||
// if (kind == DCT_Linear) {
|
||||
if (kind == DCT_Linear) {
|
||||
return y[k_lo] + (t - x[k_lo]) * ( y[k_hi] - y[k_lo] ) / h;
|
||||
// }
|
||||
// // spline curve
|
||||
// else { // if (kind==Spline) {
|
||||
// double a = (x[k_hi] - t) / h;
|
||||
// double b = (t - x[k_lo]) / h;
|
||||
// double r = a * y[k_lo] + b * y[k_hi] + ((a * a * a - a) * ypp[k_lo] + (b * b * b - b) * ypp[k_hi]) * (h * h) * 0.1666666666666666666666666666666;
|
||||
// return CLIPD(r);
|
||||
// }
|
||||
}
|
||||
// spline curve
|
||||
else { // if (kind==Spline) {
|
||||
double a = (x[k_hi] - t) / h;
|
||||
double b = (t - x[k_lo]) / h;
|
||||
double r = a * y[k_lo] + b * y[k_hi] + ((a * a * a - a) * ypp[k_lo] + (b * b * b - b) * ypp[k_hi]) * (h * h) * 0.1666666666666666666666666666666;
|
||||
return CLIPD(r);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case DCT_Spline: {
|
||||
case DCT_CatumullRom: {
|
||||
auto it = std::lower_bound(poly_x.begin(), poly_x.end(), t);
|
||||
if (it == poly_x.end()) {
|
||||
return poly_y.back();
|
||||
|
||||
@@ -97,55 +97,6 @@ int findMatch(int val, const std::vector<int> &cdf, int j)
|
||||
}
|
||||
|
||||
|
||||
class CubicSplineCurve: public DiagonalCurve {
|
||||
public:
|
||||
CubicSplineCurve(const std::vector<double> &points):
|
||||
DiagonalCurve({DCT_Linear})
|
||||
{
|
||||
N = points.size() / 2;
|
||||
x = new double[N];
|
||||
y = new double[N];
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
x[i] = points[2*i];
|
||||
y[i] = points[2*i+1];
|
||||
}
|
||||
kind = DCT_Spline;
|
||||
spline_cubic_set();
|
||||
}
|
||||
|
||||
double getVal(double t) const override
|
||||
{
|
||||
// values under and over the first and last point
|
||||
if (t > x[N - 1]) {
|
||||
return y[N - 1];
|
||||
} else if (t < x[0]) {
|
||||
return y[0];
|
||||
}
|
||||
|
||||
// do a binary search for the right interval:
|
||||
unsigned int k_lo = 0, k_hi = N - 1;
|
||||
|
||||
while (k_hi > 1 + k_lo) {
|
||||
unsigned int k = (k_hi + k_lo) / 2;
|
||||
|
||||
if (x[k] > t) {
|
||||
k_hi = k;
|
||||
} else {
|
||||
k_lo = k;
|
||||
}
|
||||
}
|
||||
|
||||
double h = x[k_hi] - x[k_lo];
|
||||
|
||||
double a = (x[k_hi] - t) / h;
|
||||
double b = (t - x[k_lo]) / h;
|
||||
double r = a * y[k_lo] + b * y[k_hi] + ((a * a * a - a) * ypp[k_lo] + (b * b * b - b) * ypp[k_hi]) * (h * h) * 0.1666666666666666666666666666666;
|
||||
return LIM01(r);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
||||
{
|
||||
curve.clear();
|
||||
@@ -259,10 +210,11 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
||||
if (curve.size() < 4) {
|
||||
curve = { DCT_Linear }; // not enough points, fall back to linear
|
||||
} else {
|
||||
CubicSplineCurve c(curve);
|
||||
curve.insert(curve.begin(), DCT_Spline);
|
||||
DiagonalCurve c(curve);
|
||||
double gap = 0.05;
|
||||
double x = 0.0;
|
||||
curve = { DCT_Spline };
|
||||
curve = { DCT_CatumullRom };
|
||||
while (x < 1.0) {
|
||||
curve.push_back(x);
|
||||
curve.push_back(c.getVal(x));
|
||||
|
||||
Reference in New Issue
Block a user