void BSpline::regularizeKnotVectors(std::vector<double> &lb, std::vector<double> &ub) { // Add and remove controlpoints and knots to make the b-spline p-regular with support [lb, ub] if (!(lb.size() == numVariables && ub.size() == numVariables)) throw Exception("BSpline::regularizeKnotVectors: Inconsistent vector sizes."); for (unsigned int dim = 0; dim < numVariables; dim++) { unsigned int multiplicityTarget = basis.getBasisDegree(dim) + 1; // Inserting many knots at the time (to save number of B-spline coefficient calculations) // NOTE: This method generates knot insertion matrices with more nonzero elements than // the method that inserts one knot at the time. This causes the preallocation of // kronecker product matrices to become too small and the speed deteriorates drastically // in higher dimensions because reallocation is necessary. This can be prevented by // precomputing the number of nonzeros when preallocating memory (see myKroneckerProduct). int numKnotsLB = multiplicityTarget - basis.getKnotMultiplicity(dim, lb.at(dim)); if (numKnotsLB > 0) { insertKnots(lb.at(dim), dim, numKnotsLB); } int numKnotsUB = multiplicityTarget - basis.getKnotMultiplicity(dim, ub.at(dim)); if (numKnotsUB > 0) { insertKnots(ub.at(dim), dim, numKnotsUB); } } }
//=========================================================================== shared_ptr<SplineSurface> SplineUtils::refineToBezier(const SplineSurface& spline_sf) //=========================================================================== { shared_ptr<SplineSurface> bez_sf; const BsplineBasis& bas_u = spline_sf.basis_u(); const BsplineBasis& bas_v = spline_sf.basis_v(); const int order_u = bas_u.order(); const int order_v = bas_v.order(); // We extract the unique knots. vector<double> new_knots_u, new_knots_v; // vector<double> ref_knots_u, ref_knots_v; vector<double>::const_iterator iter = bas_u.begin(); while (iter != bas_u.end() - order_u) { if (iter[0] != iter[1]) { int knot_mult = bas_u.knotMultiplicity(iter[0]); int num_insert = order_u - knot_mult; if (num_insert > 0) { new_knots_u.insert(new_knots_u.end(), num_insert, iter[0]); } } ++iter; } iter = bas_v.begin(); while (iter != bas_v.end() - order_v) { if (iter[0] != iter[1]) { int knot_mult = bas_v.knotMultiplicity(iter[0]); int num_insert = order_v - knot_mult; if (num_insert > 0) { new_knots_v.insert(new_knots_v.end(), num_insert, iter[0]); } } ++iter; } bez_sf = insertKnots(spline_sf, new_knots_u, new_knots_v); return bez_sf; }