inline double smoothXY10B(double iter,long i,const double* datas){ const double s=(iter+5-(long)(iter+5)); return smoothMap(datas[i ])*BSpline(2-s) +smoothMap(datas[i-1])*BSpline(1-s) +smoothMap(datas[i-2])*BSpline(s) +smoothMap(datas[i-3])*BSpline(1+s); }
double BSpline(int t, int k, double z, int *knots, int n) { if (k == 1) { if ((z >= knots[t] && z < knots[t + 1]) || (fabs(z - knots[t + 1]) < 1e-10 && t + 1 == n)) return 1; else return 0; } double d1, d2; double value; d1 = knots[t + k -1] - knots[t]; d2 = knots[t + k] - knots[t + 1]; if (d1 == 0 && d2 == 0) return 0; if (d1 == 0) value = ((knots[t + k] - z) / d2) * BSpline(t+1, k-1, z, knots, n); else if (d2 == 0) value = ((z - knots[t]) / d1) * BSpline(t, k-1, z, knots, n); else value = ((z - knots[t]) / d1) * BSpline(t, k-1, z, knots, n) + ((knots[t + k] - z) / d2) * BSpline(t+1, k-1, z, knots, n); if (value < 0) return 0; return value; }
matrix *calcWeights(matrix *m, int n, int k, int *knots) { //double w[m->rows][m->cols][n]; matrix *w; matrix *z; w = new_matrix(m->rows, n * m->cols); z =convData(m, n, k); int i, j, t; for (i = 0; i < m->rows; ++i) { for (t = 0; t < n; ++t) { for (j = 0; j < m->cols; ++j) { w->m[i][t * m->cols + j] = BSpline(t, k, z->m[i][j], knots, n); //if (w->m[i][t*n + j] > 1) //printf("bad weight %lf\n", w->m[i][t*n +j]); } } } /*matrix *p; p = new_matrix(m->rows, n); //printf("p: %d, %d\n", p->rows, p->cols); double sum; for (i = 0; i < m->rows; ++i) { for (t = 0; t < n; ++t) { sum = 0; for (j = 0; j < m->cols; ++j) { sum += w[i][j][t]; } sum /= n; p->m[i][t] = sum; } } */ //printf("p2: %d, %d\n", p->rows, p->cols); free_matrix(z); return w; }
void Interpolator_CurveInterpolate_NonNormalized( int interpolationType, const Vector &vPre, const Vector &vStart, const Vector &vEnd, const Vector &vNext, float f, Vector &vOut ) { vOut.Init(); switch ( interpolationType ) { default: Warning( "Unknown interpolation type %d\n", (int)interpolationType ); // break; // Fall through and use catmull_rom as default case INTERPOLATE_CATMULL_ROM_NORMALIZEX: case INTERPOLATE_DEFAULT: case INTERPOLATE_CATMULL_ROM: case INTERPOLATE_CATMULL_ROM_NORMALIZE: case INTERPOLATE_CATMULL_ROM_TANGENT: Catmull_Rom_Spline( vPre, vStart, vEnd, vNext, f, vOut ); break; case INTERPOLATE_EASE_IN: { f = sin( M_PI * f * 0.5f ); // Fixme, since this ignores vPre and vNext we could omit computing them aove VectorLerp( vStart, vEnd, f, vOut ); } break; case INTERPOLATE_EASE_OUT: { f = 1.0f - sin( M_PI * f * 0.5f + 0.5f * M_PI ); // Fixme, since this ignores vPre and vNext we could omit computing them aove VectorLerp( vStart, vEnd, f, vOut ); } break; case INTERPOLATE_EASE_INOUT: { f = SimpleSpline( f ); // Fixme, since this ignores vPre and vNext we could omit computing them aove VectorLerp( vStart, vEnd, f, vOut ); } break; case INTERPOLATE_LINEAR_INTERP: // Fixme, since this ignores vPre and vNext we could omit computing them aove VectorLerp( vStart, vEnd, f, vOut ); break; case INTERPOLATE_KOCHANEK_BARTELS: case INTERPOLATE_KOCHANEK_BARTELS_EARLY: case INTERPOLATE_KOCHANEK_BARTELS_LATE: { float t, b, c; Interpolator_GetKochanekBartelsParams( interpolationType, t, b, c ); Kochanek_Bartels_Spline ( t, b, c, vPre, vStart, vEnd, vNext, f, vOut ); } break; case INTERPOLATE_SIMPLE_CUBIC: Cubic_Spline( vPre, vStart, vEnd, vNext, f, vOut ); break; case INTERPOLATE_BSPLINE: BSpline( vPre, vStart, vEnd, vNext, f, vOut ); break; case INTERPOLATE_EXPONENTIAL_DECAY: { float dt = vEnd.x - vStart.x; if ( dt > 0.0f ) { float val = 1.0f - ExponentialDecay( 0.001, dt, f * dt ); vOut.y = vStart.y + val * ( vEnd.y - vStart.y ); } else { vOut.y = vStart.y; } } break; case INTERPOLATE_HOLD: { vOut.y = vStart.y; } break; } }