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 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;
}
@@ -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)
{
static const double epsilon = 1e-5;
// double xr = x[1] - x[0];
// double yr = y[1] - y[0];
double xr = x[n_cp-1] - x[0];
double yr = y[n_cp-1] - y[0];
double x_first = x[0] - xr * 0.1;
double xr = x[1] - x[0];
double yr = y[1] - y[0];
double x_first = x[0] - xr * 0.01;
double y_first = xr > epsilon ? (yr / xr) * (x_first - x[0]) + y[0] : y[0];
// xr = x[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;
xr = x[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.01;
double y_last = xr > epsilon ? (yr / xr) * (x_last - x[0]) + y[0] : y[0];
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
} else {
CubicSplineCurve c(curve);
curve.pop_back();
curve.pop_back();
double gap = coord(step);
while (1 - curve[curve.size()-2] > gap) {
double x = curve[curve.size()-2] + gap;
if (1 - x <= gap / 3) {
break;
}
double mid = coord(idx);
double x = 0.0;
constexpr double shgap = 0.075;
curve = { DCT_Spline };
while (mid - x > shgap / 2) {
curve.push_back(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.insert(curve.begin(), DCT_Spline);
}
}