From fda9dbcaea4732dc36e2ac82416712305a185578 Mon Sep 17 00:00:00 2001 From: gaganjyot Date: Mon, 18 Jul 2016 02:29:19 +0530 Subject: [PATCH] splines updated --- lcUILua/actions/splineoperations.lua | 4 +- lckernel/cad/geometry/geospline.cpp | 55 ++++++++++++++++++---------- lcviewernoqt/drawitems/lcvspline.cpp | 19 ++++++++-- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/lcUILua/actions/splineoperations.lua b/lcUILua/actions/splineoperations.lua index 1825b5579..36c630700 100644 --- a/lcUILua/actions/splineoperations.lua +++ b/lcUILua/actions/splineoperations.lua @@ -44,7 +44,7 @@ end function SplineOperations:getSpline(points) local d = active_widget():document() local layer = d:layerByName("0") - local s = Spline(points, {}, {}, 1, false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, layer, MetaInfo()) + local s = Spline(points, {}, {}, 3, false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, layer, MetaInfo()) s:setId(self.spline_id) return s @@ -91,4 +91,4 @@ function SplineOperations:close() event.delete('point', self) end end -end \ No newline at end of file +end diff --git a/lckernel/cad/geometry/geospline.cpp b/lckernel/cad/geometry/geospline.cpp index dbf276d1e..18f7365b3 100644 --- a/lckernel/cad/geometry/geospline.cpp +++ b/lckernel/cad/geometry/geospline.cpp @@ -119,7 +119,7 @@ void Spline::populateCurve() { // UNIFORM OPEN CURVE if(_flags == splineflag::PERIODIC) { - _splineCurve.CreatePeriodicUniformNurbs(3, _degree, cpcount, points); + _splineCurve.CreatePeriodicUniformNurbs(3, _degree+1, cpcount, points); } // UNIFORM BUT CLOSED ONE @@ -138,10 +138,10 @@ void Spline::populateCurve() { _splineCurve.SetCV(i, points[i]); } - int knotcount = _degree+_controlPoints.size()-1; + int knotcount = _degree+cpcount-1; double* knots = new double[knotcount]; - ON_MakeClampedUniformKnotVector(_degree+1, _controlPoints.size(), knots); + ON_MakeClampedUniformKnotVector(_degree+1, cpcount, knots); for (int i=0; i 0) { - _splineCurve.Create(3, false, _degree+1, _controlPoints.size()); + _splineCurve.Create(3, false, _degree+1, cpcount); // auto i = 0; // for(const auto & cp: _controlPoints) { @@ -177,26 +177,43 @@ void Spline::populateCurve() { } std::vector> Spline::getBeziers() const { - std::vector> ret; + std::vector> bezlist; auto curve = _splineCurve.Duplicate(); // std::cout << _splineCurve.CVSize(); curve->MakePiecewiseBezier(); int span_count = curve->SpanCount(); - int order = curve->m_order; - for(int spani = 0; spani < span_count; spani++) { - std::vector coords; - ON_3dPoint *ctrl_points = new ON_3dPoint[order]; - //Load bezier control points - for(int i = 0; i < order; i++ ){ - curve->GetCV(spani*(order-1) + i,ctrl_points[i]); - coords.push_back(geo::Coordinate(ctrl_points[i].x, ctrl_points[i].y, ctrl_points[i].z)); - } +// for(int spani = 0; spani < span_count; spani++) { +// std::vector coords; +// ON_3dPoint *ctrl_points = new ON_3dPoint[order]; +// //Load bezier control points +// for(int i = 0; i < order; i++ ){ +//// curve->GetCV(spani*(order-1) + i,ctrl_points[i]); + + +// coords.push_back(geo::Coordinate(ctrl_points[i].x, ctrl_points[i].y, ctrl_points[i].z)); +// } + +// std::cout << "DEBUG: Degree : "<< order - 1 << "\n"; - std::cout << "DEBUG: Degree : "<< order - 1 << "\n"; +// //Use control points to create bezier with our representation, +// // if the order is 3 elevate degree to make cubic bezier +// ret.push_back(coords); +// } - //Use control points to create bezier with our representation, - // if the order is 3 elevate degree to make cubic bezier - ret.push_back(coords); + for (int i=0; i<=span_count; ++i) { + ON_BezierCurve bc; + if (!curve->ConvertSpanToBezier(i, bc)) { + continue; + } + + std::vector bez; + for (int j=0; j>bezlist = getBeziers(); std::cout <<"Bezies called"; - //painter.move_to(bezlist[0][0].x(), bezlist[0][0].y()); +// painter.move_to(bezlist[0][0].x(), bezlist[0][0].y()); + +// lc::geo::Coordinate l = bezlist.at(0).at(0); + +// std::cout << bezlist.size() << bezlist.at(0).size(); + + if(bezlist.size()>0) { + auto bez = bezlist.at(0); + if(bez.size()>0) { + painter.move_to(bez.at(0).x(), bez.at(0).y()); + } + } for(const auto &bez: bezlist) { if(bez.size()==4) { painter.curve_to(bez[1].x(), bez[1].y(), bez[2].x(), bez[2].y(), bez[3].x(), bez[3].y()); - } else { //(bez.size()==3) { + } else if (bez.size()==3) { painter.quadratic_curve_to(bez[1].x(), bez[1].y(), bez[2].x(), bez[2].y()); - } /*else if(bez.size()==2) { + } else if(bez.size()==2) { painter.line_to(bez[1].x(), bez[1].y()); - }*/ + } } painter.stroke(); }