MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / derive

Method derive

Engine/Interpolation.cpp:464–510  ·  view source on GitHub ↗

derive at currentTime. The derivative is with respect to currentTime

Source from the content-addressed store, hash-verified

462
463/// derive at currentTime. The derivative is with respect to currentTime
464double
465Interpolation::derive(double tcur,
466 const double vcur, //start control point
467 const double vcurDerivRight, //being the derivative dv/dt at tcur
468 const double vnextDerivLeft, //being the derivative dv/dt at tnext
469 double tnext,
470 const double vnext, //end control point
471 double currentTime,
472 KeyframeTypeEnum interp,
473 KeyframeTypeEnum interpNext)
474{
475 double P0 = vcur;
476 double P3 = vnext;
477 // Hermite coefficients P0' and P3' are the derivatives with respect to x \in [0,1]
478 double P0pr = vcurDerivRight * (tnext - tcur); // normalize for x \in [0,1]
479 double P3pl = vnextDerivLeft * (tnext - tcur); // normalize for x \in [0,1]
480
481 // if the following is true, this makes the special case for eKeyframeTypeConstant at tnext useless, and we can always use a cubic - the strict "currentTime < tnext" is the key
482 assert( ( (interp == eKeyframeTypeNone) || (tcur <= currentTime) ) && ( (currentTime < tnext) || (interpNext == eKeyframeTypeNone) ) );
483 // after the last / before the first keyframe, derivatives are wrt currentTime (i.e. non-normalized)
484 if (interp == eKeyframeTypeNone) {
485 // virtual previous frame at t-1
486 P0 = P3 - P3pl;
487 P0pr = P3pl;
488 tcur = tnext - 1.;
489 } else if (interp == eKeyframeTypeConstant) {
490 P0pr = 0.;
491 P3pl = 0.;
492 P3 = P0;
493 }
494 if (interpNext == eKeyframeTypeNone) {
495 // virtual next frame at t+1
496 P3pl = P0pr;
497 P3 = P0 + P0pr;
498 tnext = tcur + 1;
499 }
500 double c0, c1, c2, c3;
501 hermiteToCubicCoeffs(P0, P0pr, P3pl, P3, &c0, &c1, &c2, &c3);
502
503 const double t = (currentTime - tcur) / (tnext - tcur);
504 double ret = cubicDerive(c0, c1, c2, c3, t);
505
506 // cubicDerive: divide the result by (tnext-tcur)
507
508 // cubicIntegrate: multiply the result by (tnext-tcur)
509 return ret / (tnext - tcur);
510}
511
512/// interpolate and derive at currentTime. The derivative is with respect to currentTime
513double

Callers

nothing calls this directly

Calls 2

hermiteToCubicCoeffsFunction · 0.85
cubicDeriveFunction · 0.85

Tested by

no test coverage detected