bool RSpline::isValid() const { if (!dirty) { #ifndef R_NO_OPENNURBS return curve.IsValid(); #endif } if (degree<1 || degree>3) { return false; } if (hasFitPoints()) { if (fitPoints.count() < 3) { return false; } return true; } else { if (controlPoints.count() < degree+1) { return false; } return true; } /* bool ret = curve.ctrlPnts().size() > degree && curve.ctrlPnts().size() + degree + 1 == curve.knot().size(); if (!ret) { qWarning() << "RSpine::isValid: false"; } return ret; */ //return true; }
bool RSpline::isValid() const { if (!dirty) { #ifndef R_NO_OPENNURBS // enable for opennurbs debugging: // ON_wString s; // ON_TextLog log(s); // if (!curve.IsValid(&log)) { // qDebug() << "RSpline::isValid: spline curve is not valid:"; // QString qs; // for (int i=0; i<s.Length(); i++) { // qs.append(QChar(s.GetAt(i))); // } // qDebug() << qs; // } return curve.IsValid(); #endif } if (degree<1) { qDebug() << "RSpline::isValid: spline not valid: degree: " << degree; return false; } if (hasFitPoints()) { if (fitPoints.count() < 3) { //qDebug() << "RSpline::isValid: spline not valid: less than 3 fit points"; return false; } return true; } else { if (controlPoints.count() < degree+1) { //qDebug() << "RSpline::isValid: spline not valid: less than " << degree+1 << " control points"; return false; } return true; } /* bool ret = curve.ctrlPnts().size() > degree && curve.ctrlPnts().size() + degree + 1 == curve.knot().size(); if (!ret) { qWarning() << "RSpine::isValid: false"; } return ret; */ //return true; }
void RSpline::updateFromControlPoints() const { #ifndef R_NO_OPENNURBS if (controlPoints.size()<degree+1) { invalidate(); qWarning() << "RSpline::updateFromControlPoints: not enough control points: " << controlPoints.size(); return; } // periodic: if (periodic && !hasFitPoints()) { ON_3dPoint* points = new ON_3dPoint[controlPoints.size()]; for (int i=0; i<controlPoints.size(); ++i) { RVector cp = controlPoints.at(i); points[i] = ON_3dPoint(cp.x, cp.y, cp.z); } curve.CreatePeriodicUniformNurbs(3, getOrder(), controlPoints.size(), points); delete[] points; } // open or from fit points: else { curve.Create(3, false, getOrder(), controlPoints.size()); // setting control points: for (int i=0; i<controlPoints.size(); ++i) { RVector cp = controlPoints.at(i); ON_3dPoint onp(cp.x, cp.y, cp.z); curve.SetCV(i, onp); //qDebug() << "RSpline: controlPoints[" << i << "]: " << cp; } bool knotCondition = (knotVector.size() == getOrder() + controlPoints.size() - 2); //knotCondition = true; // genetate knot vector automatically: if (knotVector.isEmpty() || !knotCondition) { // if (!knotVector.isEmpty()) { // qDebug() << "RSpline: knotVector ignored"; // qDebug() << "RSpline: knots: " << knotVector.size(); // qDebug() << "RSpline: order: " << getOrder(); // qDebug() << "RSpline: controlPoints: " << controlPoints.size(); // } int si = ON_KnotCount(getOrder(), controlPoints.size()); double* knot = new double[si]; //ON_MakePeriodicUniformKnotVector(getOrder(), controlPoints.size(), knot); ON_MakeClampedUniformKnotVector(getOrder(), controlPoints.size(), knot); for (int i=0; i<si; ++i) { // qDebug() << "RSpline: knot[" << i << "]: " << knot[i]; curve.SetKnot(i, knot[i]); } delete[] knot; } else { int k=0; for (int i=0; i<knotVector.count(); ++i) { //qDebug() << "RSpline: knot[" << i << "]: " << knotVector.at(i); bool ok = curve.SetKnot(k++, knotVector.at(i)); if (!ok) { //qDebug() << "RSpline: knot[" << i << "]: NOT set"; } } } } //##getExploded(); #endif }