more tweaks to catmull-rom and histogram matching after the feedback by DrSlony

This commit is contained in:
Alberto Griggio
2018-08-11 23:40:21 +02:00
parent 2bb27661a2
commit 0d7d1cfc8c
2 changed files with 24 additions and 19 deletions

View File

@@ -289,7 +289,8 @@ inline double catmull_rom_tj(double ti,
double xi, double yi, double xi, double yi,
double xj, double yj) double xj, double yj)
{ {
return sqrt(sqrt(pow2(xj-xi) + pow2(yj-yi))) + ti; static constexpr double alpha = 0.25;
return pow(sqrt(pow2(xj-xi) + pow2(yj-yi)), alpha) + ti;
} }
@@ -303,7 +304,7 @@ inline void catmull_rom_spline(int n_points,
{ {
res_x.reserve(n_points); res_x.reserve(n_points);
res_y.reserve(n_points); res_y.reserve(n_points);
double t0 = 0; double t0 = 0;
double t1 = catmull_rom_tj(t0, p0_x, p0_y, p1_x, p1_y); double t1 = catmull_rom_tj(t0, p0_x, p0_y, p1_x, p1_y);
double t2 = catmull_rom_tj(t1, p1_x, p1_y, p2_x, p2_y); double t2 = catmull_rom_tj(t1, p1_x, p1_y, p2_x, p2_y);
@@ -359,15 +360,13 @@ void catmull_rom_chain(int n_points, int n_cp, double *x, double *y,
std::vector<double> &res_x, std::vector<double> &res_y) std::vector<double> &res_x, std::vector<double> &res_y)
{ {
static const double epsilon = 1e-5; static const double epsilon = 1e-5;
// double xr = x[1] - x[0]; double xr = x[1] - x[0];
// double yr = y[1] - y[0]; double yr = y[1] - y[0];
double xr = x[n_cp-1] - x[0]; double x_first = x[0] - xr * 0.01;
double yr = y[n_cp-1] - y[0];
double x_first = x[0] - xr * 0.1;
double y_first = xr > epsilon ? (yr / xr) * (x_first - x[0]) + y[0] : y[0]; double y_first = xr > epsilon ? (yr / xr) * (x_first - x[0]) + y[0] : y[0];
// xr = x[n_cp-1] - x[n_cp-2]; xr = x[n_cp-1] - x[n_cp-2];
// yr = y[n_cp-1] - x[n_cp-2]; yr = y[n_cp-1] - x[n_cp-2];
double x_last = x[n_cp-1] + xr * 0.1; double x_last = x[n_cp-1] + xr * 0.01;
double y_last = xr > epsilon ? (yr / xr) * (x_last - x[0]) + y[0] : y[0]; double y_last = xr > epsilon ? (yr / xr) * (x_last - x[0]) + y[0] : y[0];
int segments = n_cp - 1; int segments = n_cp - 1;

View File

@@ -221,20 +221,26 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
curve = { DCT_Linear }; // not enough points, fall back to linear curve = { DCT_Linear }; // not enough points, fall back to linear
} else { } else {
CubicSplineCurve c(curve); CubicSplineCurve c(curve);
curve.pop_back(); double mid = coord(idx);
curve.pop_back(); double x = 0.0;
double gap = coord(step); constexpr double shgap = 0.075;
while (1 - curve[curve.size()-2] > gap) { curve = { DCT_Spline };
double x = curve[curve.size()-2] + gap; while (mid - x > shgap / 2) {
if (1 - x <= gap / 3) {
break;
}
curve.push_back(x); curve.push_back(x);
curve.push_back(c.getVal(x)); curve.push_back(c.getVal(x));
x += shgap;
}
curve.push_back(mid);
curve.push_back(c.getVal(mid));
constexpr double hlgap = 0.2;
x = mid + hlgap;
while (1 - x > hlgap / 2) {
curve.push_back(x);
curve.push_back(c.getVal(x));
x += hlgap;
} }
curve.push_back(1.0); curve.push_back(1.0);
curve.push_back(1.0); curve.push_back(1.0);
curve.insert(curve.begin(), DCT_Spline);
} }
} }