curves: restored the old DCT_Spline implementation (cubic splines), and added new DCT_CatumullRom curve type

This commit is contained in:
Alberto Griggio
2018-12-06 14:11:49 +01:00
parent 1bf837d5b1
commit fd48b34cd5
10 changed files with 138 additions and 80 deletions

View File

@@ -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;
}
@@ -459,7 +460,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 +485,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();