Skip to content

Commit

Permalink
splines updated
Browse files Browse the repository at this point in the history
  • Loading branch information
gaganjyot committed Jul 17, 2016
1 parent e009840 commit fda9dbc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lcUILua/actions/splineoperations.lua
Expand Up @@ -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
Expand Down Expand Up @@ -91,4 +91,4 @@ function SplineOperations:close()
event.delete('point', self)
end
end
end
end
55 changes: 36 additions & 19 deletions lckernel/cad/geometry/geospline.cpp
Expand Up @@ -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
Expand All @@ -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<knotcount; ++i) {
_splineCurve.SetKnot(i, knots[i]);
}
Expand All @@ -151,7 +151,7 @@ void Spline::populateCurve() {
// NON UNIFORM NURBS.

else if(knotPoints().size() > 0) {
_splineCurve.Create(3, false, _degree+1, _controlPoints.size());
_splineCurve.Create(3, false, _degree+1, cpcount);

// auto i = 0;
// for(const auto & cp: _controlPoints) {
Expand All @@ -177,26 +177,43 @@ void Spline::populateCurve() {
}

std::vector<std::vector<lc::geo::Coordinate>> Spline::getBeziers() const {
std::vector<std::vector<lc::geo::Coordinate>> ret;
std::vector<std::vector<lc::geo::Coordinate>> 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<geo::Coordinate> 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<geo::Coordinate> 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<geo::Coordinate> bez;
for (int j=0; j<bc.CVCount(); j++) {
ON_3dPoint onp;
bc.GetCV(j, onp);
bez.push_back(geo::Coordinate(onp.x, onp.y, onp.z));
}
bezlist.push_back(bez);
}
return ret;

return bezlist;
}
19 changes: 15 additions & 4 deletions lcviewernoqt/drawitems/lcvspline.cpp
Expand Up @@ -36,16 +36,27 @@ void LCVSpline::draw(LcPainter &painter, const LcDrawOptions &options, const lc:
std::vector<std::vector<lc::geo::Coordinate>>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();
}
Expand Down

0 comments on commit fda9dbc

Please sign in to comment.