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

Method getIntegrateFromTo

Engine/Curve.cpp:1036–1147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1034} // getDerivativeAt
1035
1036double
1037Curve::getIntegrateFromTo(double t1,
1038 double t2) const
1039{
1040 QMutexLocker l(&_imp->_lock);
1041 bool opposite = false;
1042
1043 // the following assumes that t2 > t1. If it's not the case, swap them and return the opposite.
1044 if (t1 > t2) {
1045 opposite = true;
1046 std::swap(t1, t2);
1047 }
1048
1049 if ( _imp->keyFrames.empty() ) {
1050 throw std::runtime_error("Curve has no control points!");
1051 }
1052 assert(_imp->type == CurvePrivate::eCurveTypeDouble); // only real-valued curves can be derived
1053
1054 // even when there is only one keyframe, there may be tangents!
1055 //if (_imp->keyFrames.size() == 1) {
1056 // //if there's only 1 keyframe, don't bother interpolating
1057 // return (*_imp->keyFrames.begin()).getValue();
1058 //}
1059 double tcur, tnext;
1060 double vcurDerivRight, vnextDerivLeft, vcur, vnext;
1061 KeyframeTypeEnum interp, interpNext;
1062 KeyFrame k(t1, 0.);
1063 // find the first keyframe with time strictly greater than t1
1064 KeyFrameSet::const_iterator itup;
1065 itup = _imp->keyFrames.upper_bound(k);
1066 interParams(_imp->keyFrames,
1067 _imp->isPeriodic,
1068 _imp->xMin,
1069 _imp->xMax,
1070 &t1,
1071 itup,
1072 &tcur,
1073 &vcur,
1074 &vcurDerivRight,
1075 &interp,
1076 &tnext,
1077 &vnext,
1078 &vnextDerivLeft,
1079 &interpNext);
1080
1081 double sum = 0.;
1082
1083 // while there are still keyframes after the current time, add to the total sum and advance
1084 while (itup != _imp->keyFrames.end() && itup->getTime() < t2) {
1085 // add integral from t1 to itup->getTime() to sum
1086 if ( mustClamp() ) {
1087 Curve::YRange minmax = getCurveYRange();
1088 sum += Interpolation::integrate_clamp(tcur, vcur,
1089 vcurDerivRight,
1090 vnextDerivLeft,
1091 tnext, vnext,
1092 t1, itup->getTime(),
1093 minmax.min, minmax.max,

Callers 2

TESTFunction · 0.80

Calls 5

interParamsFunction · 0.85
emptyMethod · 0.80
getTimeMethod · 0.80
swapFunction · 0.70
endMethod · 0.45

Tested by 1

TESTFunction · 0.64