[Sketcher] [planegcs] Evaluate lower degree B-spline factors

This commit is contained in:
Ajinkya Dahale
2022-09-21 20:23:30 +05:30
committed by Chris Hennes
parent fa6dc8d0e1
commit 57fa3e44f4
2 changed files with 14 additions and 11 deletions

View File

@@ -712,7 +712,7 @@ BSpline* BSpline::Copy()
return crv;
}
double BSpline::getLinCombFactor(double x, size_t k, size_t i)
double BSpline::getLinCombFactor(double x, size_t k, size_t i, size_t p)
{
// Adapted to C++ from the python implementation in the Wikipedia page for de Boor algorithm
// https://en.wikipedia.org/wiki/De_Boor%27s_algorithm.
@@ -727,23 +727,23 @@ double BSpline::getLinCombFactor(double x, size_t k, size_t i)
if (flattenedknots.empty())
setupFlattenedKnots();
std::vector d(degree + 1, 0.0);
std::vector d(p + 1, 0.0);
// Ensure this is within range
int idxOfPole = static_cast<int>(i) + degree - static_cast<int>(k);
if (idxOfPole < 0 || idxOfPole > degree)
int idxOfPole = static_cast<int>(i) + p - static_cast<int>(k);
if (idxOfPole < 0 || idxOfPole > static_cast<int>(p))
return 0.0;
d[idxOfPole] = 1.0;
for (size_t r = 1; static_cast<int>(r) < degree + 1; ++r) {
for (size_t j = degree; j > r - 1; --j) {
for (size_t r = 1; static_cast<int>(r) < p + 1; ++r) {
for (size_t j = p; j > r - 1; --j) {
double alpha =
(x - flattenedknots[j + k - degree]) /
(flattenedknots[j + 1 + k - r] - flattenedknots[j + k - degree]);
(x - flattenedknots[j + k - p]) /
(flattenedknots[j + 1 + k - r] - flattenedknots[j + k - p]);
d[j] = (1.0 - alpha) * d[j-1] + alpha * d[j];
}
}
return d[degree];
return d[p];
}
void BSpline::setupFlattenedKnots()

View File

@@ -300,10 +300,13 @@ namespace GCS
void ReconstructOnNewPvec (VEC_pD &pvec, int &cnt) override;
BSpline* Copy() override;
/// finds the value B_i(x) such that spline(x) = sum(poles[i] * B_i(x))
/// i is index of control point
/// x is the point at which combination is needed
/// k is the range in `flattenedknots` that contains x
double getLinCombFactor(double x, size_t k, size_t i);
/// i is index of control point
/// p is the degree
double getLinCombFactor(double x, size_t k, size_t i, size_t p);
inline double getLinCombFactor(double x, size_t k, size_t i)
{ return getLinCombFactor(x, k, i, degree); }
void setupFlattenedKnots();
};