void ASplineVec3::appendKey(double time, const vec3& value, bool updateCurve) { mKeys.push_back(Key(time, value)); if (mKeys.size() >= 2) { int totalPoints = mKeys.size(); //If there are more than 1 interpolation point, set up the 2 end points to help determine the curve. //They lie on the tangent of the first and last interpolation points. vec3 tmp = mKeys[0].second - mKeys[1].second; double n = tmp.Length(); mStartPoint = mKeys[0].second + (tmp / n) * n * 0.25; // distance to endpoint is 25% of distance between first 2 points tmp = mKeys[totalPoints - 1].second - mKeys[totalPoints - 2].second; n = tmp.Length(); mEndPoint = mKeys[totalPoints - 1].second + (tmp / n) * n * 0.25; } if (updateCurve) { computeControlPoints(); cacheCurve(); } }
void ASplineVec3::editControlPoint(int ID, const vec3& value) { assert(ID >= 0 && ID < mCtrlPoints.size()+2); if (ID == 0) { mStartPoint = value; computeControlPoints(); } else if (ID == mCtrlPoints.size() + 1) { mEndPoint = value; computeControlPoints(); } else mCtrlPoints[ID-1] = value; cacheCurve(); }
void ASplineVec3::editKey(int keyID, const vec3& value) { assert(keyID >= 0 && keyID < mKeys.size()); mKeys[keyID].second = value; computeControlPoints(); cacheCurve(); }
void ASplineVec3::deleteKey(int keyID) { assert(keyID >= 0 && keyID < mKeys.size()); mKeys.erase(mKeys.begin() + keyID); computeControlPoints(); cacheCurve(); }
PSpline::PSpline(const DataTable &samples, double lambda) : lambda(lambda) { // Check data assert(samples.isGridComplete()); std::vector< std::vector<double> > xdata = samples.getTableX(); numVariables = samples.getNumVariables(); // Assuming a cubic spline std::vector<unsigned int> basisDegrees(samples.getNumVariables(), 3); basis = BSplineBasis(xdata, basisDegrees, KnotVectorType::FREE); computeControlPoints(samples); init(); checkControlPoints(); }
void ASplineVec3::setInterpolationType(ASplineVec3::InterpolationType type) { double fps = getFramerate(); delete mInterpolator; switch (type) { case LINEAR: mInterpolator = new ALinearInterpolatorVec3(); break; case CUBIC_BERNSTEIN: mInterpolator = new ABernsteinInterpolatorVec3(); break; case CUBIC_CASTELJAU: mInterpolator = new ACasteljauInterpolatorVec3(); break; case CUBIC_MATRIX: mInterpolator = new AMatrixInterpolatorVec3(); break; case CUBIC_HERMITE: mInterpolator = new AHermiteInterpolatorVec3(); break; case CUBIC_BSPLINE: mInterpolator = new ABSplineInterpolatorVec3(); break; }; mInterpolator->setFramerate(fps); computeControlPoints(); cacheCurve(); }