From 2930567e3fed1875a3c1d903634b865b135ea6ef Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 29 Nov 2017 15:26:56 +0100 Subject: Add base interpolator parameter --- src/live_effects/lpe-powerstroke.cpp | 209 +++++++++++++++++++++++++++++------ src/live_effects/lpe-powerstroke.h | 3 +- 2 files changed, 175 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 51c8451a5..96f487211 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -164,6 +164,7 @@ static const Util::EnumDataConverter LineJoinTypeConverter(LineJoinTyp LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) : Effect(lpeobject), offset_points(_("Offset points"), _("Offset points"), "offset_points", &wr, this), + interpolate_original(_("Interpolate original"), _("Interpolate original path"), "interpolate_original", &wr, this, false), sort_points(_("Sort points"), _("Sort offset points according to their time value along the curve"), "sort_points", &wr, this, true), interpolator_type(_("Interpolator type:"), _("Determines which kind of interpolator will be used to interpolate between stroke width along the path"), "interpolator_type", InterpolatorTypeConverter, &wr, this, Geom::Interpolate::INTERP_CUBICBEZIER), interpolator_beta(_("Smoothness:"), _("Sets the smoothness for the CubicBezierJohan interpolator; 0 = linear interpolation, 1 = smooth"), "interpolator_beta", &wr, this, 0.2), @@ -182,6 +183,7 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) : registerParameter(&offset_points); registerParameter(&sort_points); + registerParameter(&interpolate_original); registerParameter(&interpolator_type); registerParameter(&interpolator_beta); registerParameter(&start_linecap_type); @@ -192,6 +194,7 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) : scale_width.param_set_range(0.0, Geom::infinity()); scale_width.param_set_increments(0.1, 0.1); scale_width.param_set_digits(4); + interpolate_original_prev = !interpolate_original; } LPEPowerStroke::~LPEPowerStroke() @@ -566,6 +569,42 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) return path_out; } Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); + // create stroke path where points (x,y) := (t, offset) + + if (interpolate_original) { + Geom::PathVector path_out; + for(Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()) + continue; + + if (path_it->closed()) { + g_warning("Interpolate points LPE currently ignores whether path is closed or not."); + } + std::vector pts; + pts.push_back(path_it->initialPoint()); + + for (Geom::Path::const_iterator it = path_it->begin(), e = path_it->end_default(); it != e; ++it) { + pts.push_back((*it).finalPoint()); + } + //We use this fixed interpolator to simplfy the UI and for better results + Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM); + Geom::Path path = interpolator->interpolateToPath(pts); + + path_out.push_back(path); + } + pathv = path_out; + } + Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast(interpolator_type.get_value())); + if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast(interpolator)) { + johan->setBeta(interpolator_beta); + } + if (Geom::Interpolate::CubicBezierSmooth *smooth = dynamic_cast(interpolator)) { + smooth->setBeta(interpolator_beta); + } + if (interpolate_original_prev != interpolate_original) { + adjustForNewPath(pathv); + interpolate_original_prev = interpolate_original; + } Geom::Piecewise > pwd2_in = pathv[0].toPwSb(); Piecewise > der = derivative(pwd2_in); Piecewise > n = unitVector(der,0.0001); @@ -609,18 +648,116 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) // instead of the heavily compressed coordinate system of (segment_no offset, Y) in which the knots are stored double pwd2_in_arclength = length(pwd2_in); double xcoord_scaling = pwd2_in_arclength / ts.back()[Geom::X]; - for (std::size_t i = 0, e = ts.size(); i < e; ++i) { - ts[i][Geom::X] *= xcoord_scaling; + if (interpolate_original) { + size_t i = 0; + std::vector ts_aprox; + size_t steps = 0; + double distance = 0; + Geom::PathVector splits; + Geom::Coord start = 0; + for(std::vector::iterator point = ts.begin(); point != ts.end();) { + point++; + Geom::Coord end = (*point)[Geom::X]; + if (Geom::are_near(start, end,0.0001)) { + continue; + } + splits.push_back(path_in[0].portion(start, end)); + start = end; + if (end == pathv[0].size()) { + break; + } + } + size_t counter = 0; + for(Geom::PathVector::const_iterator path_it = splits.begin(); path_it != splits.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + Geom::Piecewise > path_pwd = (*path_it).toPwSb(); + size_t size = (*path_it).size(); + double path_it_arclength = length(path_pwd); + Geom::Point start = ts[counter]; + counter++; + Geom::Point end = ts[counter]; + if (Geom::are_near(start[Geom::Y],end[Geom::Y],0.0001)) { + continue; + } + double gap = (start[Geom::Y] - end[Geom::Y])/size; + double width = 0; + width = start[Geom::Y]; + for (size_t j = 1; j < size; j++){ + Geom::Path current_curve = (*path_it).portion(j-1, j); + double path_it_arclength_sub = length(current_curve.toPwSb()); + double factor = path_it_arclength_sub * size/path_it_arclength; + width -= gap * factor; + ts.push_back(Geom::Point(std::floor(ts[counter-1][Geom::X]) + j, width)); + } + } + sort(ts.begin(), ts.end(), compare_offsets); } // create stroke path where points (x,y) := (t, offset) - Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast(interpolator_type.get_value())); - if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast(interpolator)) { - johan->setBeta(interpolator_beta); - } - if (Geom::Interpolate::CubicBezierSmooth *smooth = dynamic_cast(interpolator)) { - smooth->setBeta(interpolator_beta); + + Geom::Path fixed_path; + Geom::Path fixed_mirrorpath; + Geom::Path strokepath; + if (interpolate_original) { + std::vector ts_normal; + std::vector ts_mirror; + + bool previous_isnode = false; + size_t counter = 0; + for(auto point:ts) { + Geom::Point normal_pos = pwd2_in.valueAt(point[Geom::X]) + (point[Geom::Y] * scale_width) * n.valueAt(point[Geom::X]); + Geom::Point mirror_pos = pwd2_in.valueAt(point[Geom::X]) + (point[Geom::Y] * -1 * scale_width) * n.valueAt(point[Geom::X]); + Geom::Point normal = Geom::Point(normal_pos[Geom::X] * xcoord_scaling, normal_pos[Geom::Y]); + Geom::Point mirror = Geom::Point(mirror_pos [Geom::X] * xcoord_scaling, mirror_pos [Geom::Y]); + //a bit smoothig tweak + if (counter > 2) { + Geom::Point granparent_normal = ts_normal[counter-2]; + Geom::Point parent_normal = ts_normal[counter-1]; + Geom::Point granparent_mirror = ts_mirror [counter-2]; + Geom::Point parent_mirror = ts_mirror [counter-1]; + bool isnode = ts[counter][Geom::X] == std::floor(ts[counter ][Geom::X]); + bool previous_isnode = ts[counter-1][Geom::X] == std::floor(ts[counter-1][Geom::X]); + bool ccw_toggle_normal = cross(parent_normal - granparent_normal, normal - granparent_normal) < 0; + bool ccw_toggle_mirror = cross(parent_mirror - granparent_mirror , mirror - granparent_mirror ) < 0; + Geom::Ray ray_normal_a(parent_normal, granparent_normal); + Geom::Ray ray_normal_b(parent_normal , normal); + Geom::Ray ray_mirror_a (parent_mirror, granparent_mirror); + Geom::Ray ray_mirror_b (parent_mirror , mirror); + double angle_normal = angle_between(ray_normal_a, ray_normal_b, ccw_toggle_normal); + double angle_mirror = angle_between(ray_mirror_a , ray_mirror_b , ccw_toggle_mirror); + if (point[Geom::X] > 2 && + previous_isnode && + !isnode && + !ccw_toggle_normal && + angle_normal < Geom::rad_from_deg(90)) + { + ts_normal.pop_back(); + } + if (point[Geom::X] > 2 && + previous_isnode && + !isnode && + ccw_toggle_mirror && + angle_mirror < Geom::rad_from_deg(90)) + { + ts_mirror.pop_back(); + } + } + ts_normal.push_back(normal); + ts_mirror.push_back(mirror); + counter++; + } + fixed_path = interpolator->interpolateToPath(ts_normal); + fixed_path *= Scale(1/xcoord_scaling, 1); + fixed_mirrorpath = interpolator->interpolateToPath(ts_mirror); + fixed_mirrorpath *= Scale(1/xcoord_scaling, 1); + fixed_mirrorpath = fixed_mirrorpath.reversed(); + } else { + for (std::size_t i = 0, e = ts.size(); i < e; ++i) { + ts[i][Geom::X] *= xcoord_scaling; + } + strokepath = interpolator->interpolateToPath(ts); } - Geom::Path strokepath = interpolator->interpolateToPath(ts); delete interpolator; // apply the inverse knot-xcoord scaling that was applied before the interpolation @@ -638,13 +775,13 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) y = portion(y, rtsmin.at(0), rtsmax.at(0)); } - LineJoinType jointype = static_cast(linejoin_type.get_value()); - - Piecewise > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); - Piecewise > mirrorpath = reverse( compose(pwd2_in,x) - y*compose(n,x)); - - Geom::Path fixed_path = path_from_piecewise_fix_cusps( pwd2_out, y, jointype, miter_limit, LPE_CONVERSION_TOLERANCE); - Geom::Path fixed_mirrorpath = path_from_piecewise_fix_cusps( mirrorpath, reverse(y), jointype, miter_limit, LPE_CONVERSION_TOLERANCE); + if (!interpolate_original) { + LineJoinType jointype = static_cast(linejoin_type.get_value()); + Piecewise > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); + Piecewise > mirrorpath = reverse( compose(pwd2_in,x) - y*compose(n,x)); + fixed_path = path_from_piecewise_fix_cusps( pwd2_out, y, jointype, miter_limit, LPE_CONVERSION_TOLERANCE); + fixed_mirrorpath = path_from_piecewise_fix_cusps( mirrorpath, reverse(y), jointype, miter_limit, LPE_CONVERSION_TOLERANCE); + } if (pathv[0].closed()) { fixed_path.close(true); path_out.push_back(fixed_path); @@ -659,31 +796,31 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) case LINECAP_PEAK: { Geom::Point end_deriv = -unitTangentAt( reverse(pwd2_in.segs.back()), 0.); - double radius = 0.5 * distance(pwd2_out.lastValue(), mirrorpath.firstValue()); - Geom::Point midpoint = 0.5*(pwd2_out.lastValue() + mirrorpath.firstValue()) + radius*end_deriv; + double radius = 0.5 * distance(fixed_path.finalPoint(), fixed_mirrorpath.initialPoint()); + Geom::Point midpoint = 0.5*(fixed_path.finalPoint() + fixed_mirrorpath.initialPoint()) + radius*end_deriv; fixed_path.appendNew(midpoint); - fixed_path.appendNew(mirrorpath.firstValue()); + fixed_path.appendNew(fixed_mirrorpath.initialPoint()); break; } case LINECAP_SQUARE: { Geom::Point end_deriv = -unitTangentAt( reverse(pwd2_in.segs.back()), 0.); - double radius = 0.5 * distance(pwd2_out.lastValue(), mirrorpath.firstValue()); - fixed_path.appendNew( pwd2_out.lastValue() + radius*end_deriv ); - fixed_path.appendNew( mirrorpath.firstValue() + radius*end_deriv ); - fixed_path.appendNew( mirrorpath.firstValue() ); + double radius = 0.5 * distance(fixed_path.finalPoint(), fixed_mirrorpath.initialPoint()); + fixed_path.appendNew( fixed_path.finalPoint() + radius*end_deriv ); + fixed_path.appendNew( fixed_mirrorpath.initialPoint() + radius*end_deriv ); + fixed_path.appendNew( fixed_mirrorpath.initialPoint() ); break; } case LINECAP_BUTT: { - fixed_path.appendNew( mirrorpath.firstValue() ); + fixed_path.appendNew( fixed_mirrorpath.initialPoint() ); break; } case LINECAP_ROUND: default: { - double radius1 = 0.5 * distance(pwd2_out.lastValue(), mirrorpath.firstValue()); - fixed_path.appendNew( radius1, radius1, M_PI/2., false, y.lastValue() < 0, mirrorpath.firstValue() ); + double radius1 = 0.5 * distance(fixed_path.finalPoint(), fixed_mirrorpath.initialPoint()); + fixed_path.appendNew( radius1, radius1, M_PI/2., false, y.lastValue() < 0, fixed_mirrorpath.initialPoint() ); break; } } @@ -696,31 +833,31 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) case LINECAP_PEAK: { Geom::Point start_deriv = unitTangentAt( pwd2_in.segs.front(), 0.); - double radius = 0.5 * distance(pwd2_out.firstValue(), mirrorpath.lastValue()); - Geom::Point midpoint = 0.5*(mirrorpath.lastValue() + pwd2_out.firstValue()) - radius*start_deriv; + double radius = 0.5 * distance(fixed_path.initialPoint(), fixed_mirrorpath.finalPoint()); + Geom::Point midpoint = 0.5*(fixed_mirrorpath.finalPoint() + fixed_path.initialPoint()) - radius*start_deriv; fixed_path.appendNew( midpoint ); - fixed_path.appendNew( pwd2_out.firstValue() ); + fixed_path.appendNew( fixed_path.initialPoint() ); break; } case LINECAP_SQUARE: { Geom::Point start_deriv = unitTangentAt( pwd2_in.segs.front(), 0.); - double radius = 0.5 * distance(pwd2_out.firstValue(), mirrorpath.lastValue()); - fixed_path.appendNew( mirrorpath.lastValue() - radius*start_deriv ); - fixed_path.appendNew( pwd2_out.firstValue() - radius*start_deriv ); - fixed_path.appendNew( pwd2_out.firstValue() ); + double radius = 0.5 * distance(fixed_path.initialPoint(), fixed_mirrorpath.finalPoint()); + fixed_path.appendNew( fixed_mirrorpath.finalPoint() - radius*start_deriv ); + fixed_path.appendNew( fixed_path.initialPoint() - radius*start_deriv ); + fixed_path.appendNew( fixed_path.initialPoint() ); break; } case LINECAP_BUTT: { - fixed_path.appendNew( pwd2_out.firstValue() ); + fixed_path.appendNew( fixed_path.initialPoint() ); break; } case LINECAP_ROUND: default: { - double radius2 = 0.5 * distance(pwd2_out.firstValue(), mirrorpath.lastValue()); - fixed_path.appendNew( radius2, radius2, M_PI/2., false, y.firstValue() < 0, pwd2_out.firstValue() ); + double radius2 = 0.5 * distance(fixed_path.initialPoint(), fixed_mirrorpath.finalPoint()); + fixed_path.appendNew( radius2, radius2, M_PI/2., false, y.firstValue() < 0, fixed_path.initialPoint() ); break; } } diff --git a/src/live_effects/lpe-powerstroke.h b/src/live_effects/lpe-powerstroke.h index 4a0eda75a..53aab1b05 100644 --- a/src/live_effects/lpe-powerstroke.h +++ b/src/live_effects/lpe-powerstroke.h @@ -38,6 +38,7 @@ public: private: BoolParam sort_points; + BoolParam interpolate_original; EnumParam interpolator_type; ScalarParam interpolator_beta; ScalarParam scale_width; @@ -45,7 +46,7 @@ private: EnumParam linejoin_type; ScalarParam miter_limit; EnumParam end_linecap_type; - + bool interpolate_original_prev; LPEPowerStroke(const LPEPowerStroke&); LPEPowerStroke& operator=(const LPEPowerStroke&); }; -- cgit v1.2.3 From cd56d55f26a8c9029de91924d0ab827ad877713d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 29 Nov 2017 15:34:49 +0100 Subject: Add BSPLine interpolator --- src/live_effects/lpe-interpolate_points.cpp | 3 +- src/live_effects/lpe-powerstroke-interpolators.h | 37 +++++++++++++++++++++++- src/live_effects/lpe-powerstroke.cpp | 3 +- 3 files changed, 40 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index 7d4c88dc1..c745921c2 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -25,7 +25,8 @@ static const Util::EnumData InterpolatorTypeData[] = { {Geom::Interpolate::INTERP_CUBICBEZIER , N_("CubicBezierFit"), "CubicBezierFit"}, {Geom::Interpolate::INTERP_CUBICBEZIER_JOHAN , N_("CubicBezierJohan"), "CubicBezierJohan"}, {Geom::Interpolate::INTERP_SPIRO , N_("SpiroInterpolator"), "SpiroInterpolator"}, - {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"} + {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"}, + {Geom::Interpolate::INTERP_BSPLINE , N_("BSpline"), "BSpline"} }; static const Util::EnumDataConverter InterpolatorTypeConverter(InterpolatorTypeData, sizeof(InterpolatorTypeData)/sizeof(*InterpolatorTypeData)); diff --git a/src/live_effects/lpe-powerstroke-interpolators.h b/src/live_effects/lpe-powerstroke-interpolators.h index e3ab37e27..651eba057 100644 --- a/src/live_effects/lpe-powerstroke-interpolators.h +++ b/src/live_effects/lpe-powerstroke-interpolators.h @@ -15,7 +15,7 @@ #include <2geom/path.h> #include <2geom/bezier-utils.h> #include <2geom/sbasis-to-bezier.h> - +#include #include "live_effects/spiro.h" @@ -27,6 +27,7 @@ enum InterpolatorType { INTERP_LINEAR, INTERP_CUBICBEZIER, INTERP_CUBICBEZIER_JOHAN, + INTERP_BSPLINE, INTERP_SPIRO, INTERP_CUBICBEZIER_SMOOTH, INTERP_CENTRIPETAL_CATMULLROM @@ -65,6 +66,38 @@ private: Linear& operator=(const Linear&); }; +class BSpline : public Interpolator { +public: + BSpline() {}; + virtual ~BSpline() {}; + + virtual Path interpolateToPath(std::vector const &points) const { + Path path; + path.start( points.at(0) ); + for (unsigned int i = 1 ; i < points.size(); ++i) { + Geom::Point pointA = points.at(i-1); + Geom::Point pointB = points.at(i); + Geom::Ray ray(pointA, pointB); + double angle = ray.angle(); + if (angle == 0) { + continue; + } + std::cout << angle << "angle" << std::endl; + double k1 = (Geom::distance(pointA, pointB)*std::sin(angle))/2.0; + std::cout << k1 << "k1" << std::endl; + std::cout << std::sin(angle) << "std::sin(angle)" << std::endl; + Geom::Point handle_1 = Geom::Point::polar(angle, k1) + pointA; + Geom::Point handle_2 = Geom::Point::polar(angle, k1 * 2) + pointA; + path.appendNew(handle_1, handle_2, pointB); + } + return path; + }; + +private: + BSpline(const BSpline&); + BSpline& operator=(const BSpline&); +}; + // this class is terrible class CubicBezierFit : public Interpolator { public: @@ -302,6 +335,8 @@ Interpolator::create(InterpolatorType type) { return new Geom::Interpolate::CubicBezierSmooth(); case INTERP_CENTRIPETAL_CATMULLROM: return new Geom::Interpolate::CentripetalCatmullRomInterpolator(); + case INTERP_BSPLINE: + return new Geom::Interpolate::BSpline(); default: return new Geom::Interpolate::Linear(); } diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 96f487211..b2b55a08c 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -123,7 +123,8 @@ static const Util::EnumData InterpolatorTypeData[] = { {Geom::Interpolate::INTERP_CUBICBEZIER , N_("CubicBezierFit"), "CubicBezierFit"}, {Geom::Interpolate::INTERP_CUBICBEZIER_JOHAN , N_("CubicBezierJohan"), "CubicBezierJohan"}, {Geom::Interpolate::INTERP_SPIRO , N_("SpiroInterpolator"), "SpiroInterpolator"}, - {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"} + {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"}, + {Geom::Interpolate::INTERP_BSPLINE , N_("BSpline"), "BSpline"} }; static const Util::EnumDataConverter InterpolatorTypeConverter(InterpolatorTypeData, sizeof(InterpolatorTypeData)/sizeof(*InterpolatorTypeData)); -- cgit v1.2.3 From 9599c53b48cbd737cf4c95120f0eb654dfce7b74 Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Wed, 29 Nov 2017 22:40:27 +0100 Subject: Working with BSPline interpolator --- src/live_effects/lpe-powerstroke-interpolators.h | 26 ++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-powerstroke-interpolators.h b/src/live_effects/lpe-powerstroke-interpolators.h index 651eba057..baa341fcb 100644 --- a/src/live_effects/lpe-powerstroke-interpolators.h +++ b/src/live_effects/lpe-powerstroke-interpolators.h @@ -74,21 +74,17 @@ public: virtual Path interpolateToPath(std::vector const &points) const { Path path; path.start( points.at(0) ); - for (unsigned int i = 1 ; i < points.size(); ++i) { - Geom::Point pointA = points.at(i-1); - Geom::Point pointB = points.at(i); - Geom::Ray ray(pointA, pointB); - double angle = ray.angle(); - if (angle == 0) { - continue; - } - std::cout << angle << "angle" << std::endl; - double k1 = (Geom::distance(pointA, pointB)*std::sin(angle))/2.0; - std::cout << k1 << "k1" << std::endl; - std::cout << std::sin(angle) << "std::sin(angle)" << std::endl; - Geom::Point handle_1 = Geom::Point::polar(angle, k1) + pointA; - Geom::Point handle_2 = Geom::Point::polar(angle, k1 * 2) + pointA; - path.appendNew(handle_1, handle_2, pointB); + Geom::Point handle_prev = points.at(0); + for (unsigned int i = 1 ; i < points.size() - 2; ++i) { + Geom::Line line_a(points.at(i), points.at(i+1)); + Geom::Line line_b(points.at(i+1), points.at(i+2)); + Geom::Point handle_next_tmp = line_a.pointAt(line_a.nearestTime(points.at(i-1))); + Geom::Point handle_next = line_b.pointAt(line_b.nearestTime(handle_next_tmp)); + Geom::Line line_handles(handle_next, points.at(i-1)); + double angle = line_handles.angle(); + Geom::Point handle_2 = Geom::Point::polar(angle, Geom::distance(handle_next,points.at(i))) + handle_next; + path.appendNew(handle_prev, handle_2, points.at(i)); + handle_prev = handle_next; } return path; }; -- cgit v1.2.3 From 524ed2d90dbea0b3be40c0786b4200bf3f6a146c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Thu, 30 Nov 2017 02:26:02 +0100 Subject: Working bspline, to fine tune --- src/live_effects/lpe-powerstroke-interpolators.h | 41 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-powerstroke-interpolators.h b/src/live_effects/lpe-powerstroke-interpolators.h index baa341fcb..21d25a797 100644 --- a/src/live_effects/lpe-powerstroke-interpolators.h +++ b/src/live_effects/lpe-powerstroke-interpolators.h @@ -74,18 +74,41 @@ public: virtual Path interpolateToPath(std::vector const &points) const { Path path; path.start( points.at(0) ); + Geom::Point handle_1(0,0); Geom::Point handle_prev = points.at(0); - for (unsigned int i = 1 ; i < points.size() - 2; ++i) { - Geom::Line line_a(points.at(i), points.at(i+1)); - Geom::Line line_b(points.at(i+1), points.at(i+2)); - Geom::Point handle_next_tmp = line_a.pointAt(line_a.nearestTime(points.at(i-1))); - Geom::Point handle_next = line_b.pointAt(line_b.nearestTime(handle_next_tmp)); - Geom::Line line_handles(handle_next, points.at(i-1)); - double angle = line_handles.angle(); - Geom::Point handle_2 = Geom::Point::polar(angle, Geom::distance(handle_next,points.at(i))) + handle_next; + for (unsigned int i = 1 ; i < points.size() - 1; ++i) { + Geom::Line line_a(points.at(i - 1), points.at(i)); + double angle_a = line_a.angle(); + Geom::Line line_b(points.at(i),points.at(i + 1)); + double angle_b = line_b.angle(); + Geom::Line line_handles(line_a.pointAt(0.66667),line_b.pointAt(0.33334)); + line_handles *= Geom::Translate(points.at(i) - line_handles.pointAt(0.5)); + Geom::Line line_perp_a(line_a.pointAt(0.5), Geom::Point::polar(angle_a + Geom::rad_from_deg(90),1) +line_a.pointAt(0.5)); + Geom::Line line_perp_b(line_b.pointAt(0.5), Geom::Point::polar(angle_b + Geom::rad_from_deg(90),1) +line_b.pointAt(0.5)); + std::vector result = line_perp_a.intersect(line_perp_b); + Geom::Point handle_2(0,0); + if(result.size() > 0) { + Geom::Line line_to_handle_a(result[0],line_a.pointAt(0.66667)); + Geom::Line line_to_handle_b(result[0],line_b.pointAt(0.33334)); + std::vector handle_a_res = line_to_handle_a.intersect(line_handles); + std::vector handle_b_res = line_to_handle_b.intersect(line_handles); + if(handle_a_res.size() > 0) { + handle_2 = handle_a_res[0]; + } + if(handle_a_res.size() > 0) { + handle_1 = handle_b_res[0]; + } + } + if (i == 1) { + Geom::Line start_segment(handle_prev,handle_2); + handle_prev = start_segment.pointAt(0.5); + } path.appendNew(handle_prev, handle_2, points.at(i)); - handle_prev = handle_next; + handle_prev = handle_1; } + Geom::Point last = points.at(points.size()-1); + Geom::Line last_segment(last,handle_1); + path.appendNew(handle_1, last_segment.pointAt(0.5), last); return path; }; -- cgit v1.2.3 From 67f654a049a12eb86b0e2f137212a50407b8e82e Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Fri, 1 Dec 2017 20:21:25 +0100 Subject: Add show handles --- src/live_effects/lpe-show_handles.cpp | 23 +++++++++++++++++++++-- src/live_effects/lpe-show_handles.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 7c298d0e7..2da570537 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -12,6 +12,7 @@ #include <2geom/svg-path-parser.h> #include "helper/geom.h" #include "desktop-style.h" +#include "display/curve.h" #include "style.h" #include "svg/svg.h" @@ -27,12 +28,14 @@ LPEShowHandles::LPEShowHandles(LivePathEffectObject *lpeobject) handles(_("Show handles"), _("Show handles"), "handles", &wr, this, true), original_path(_("Show path"), _("Show path"), "original_path", &wr, this, true), show_center_node(_("Show center of node"), _("Show center of node"), "show_center_node", &wr, this, false), + original_d(_("Show original"), _("Show original"), "original_d", &wr, this, false), scale_nodes_and_handles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scale_nodes_and_handles", &wr, this, 10) { registerParameter(&nodes); registerParameter(&handles); registerParameter(&original_path); registerParameter(&show_center_node); + registerParameter(&original_d); registerParameter(&scale_nodes_and_handles); scale_nodes_and_handles.param_set_range(0, 500.); scale_nodes_and_handles.param_set_increments(1, 1); @@ -80,7 +83,7 @@ void LPEShowHandles::doBeforeEffect (SPLPEItem const* lpeitem) Geom::PathVector LPEShowHandles::doEffect_path (Geom::PathVector const & path_in) { Geom::PathVector path_out; - Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); + Geom::PathVector original_pathv = pathv_to_linear_and_cubic_beziers(path_in); if(original_path) { for (unsigned int i=0; i < path_in.size(); i++) { path_out.push_back(path_in[i]); @@ -89,10 +92,26 @@ Geom::PathVector LPEShowHandles::doEffect_path (Geom::PathVector const & path_in if(!outline_path.empty()) { outline_path.clear(); } - generateHelperPath(original_pathv); + if (original_d) { + SPCurve * shape_curve = sp_shape->getCurveBeforeLPE(); + if (shape_curve) { + Geom::PathVector original_curve = shape_curve->get_pathvector(); + if(original_path) { + for (unsigned int i=0; i < original_curve.size(); i++) { + path_out.push_back(original_curve[i]); + } + } + original_pathv.insert(original_pathv.end(), original_curve.begin(), original_curve.end()); + } + generateHelperPath(original_pathv); + shape_curve->unref(); + } else { + generateHelperPath(original_pathv); + } for (unsigned int i=0; i < outline_path.size(); i++) { path_out.push_back(outline_path[i]); } + return path_out; } diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index c46abd2c2..583be9e61 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -43,6 +43,7 @@ private: BoolParam nodes; BoolParam handles; BoolParam original_path; + BoolParam original_d; BoolParam show_center_node; ScalarParam scale_nodes_and_handles; double stroke_width; -- cgit v1.2.3 From cbdd1dfb6d9e228c82905cc5032eef81164887d6 Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Fri, 1 Dec 2017 20:54:29 +0100 Subject: Remobe BSPline interpolator, a non success code and remove showhandles code --- src/live_effects/lpe-interpolate_points.cpp | 3 +- src/live_effects/lpe-powerstroke-interpolators.h | 56 +----------------------- src/live_effects/lpe-powerstroke.cpp | 3 +- src/live_effects/lpe-show_handles.cpp | 23 +--------- src/live_effects/lpe-show_handles.h | 1 - 5 files changed, 5 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index c745921c2..7d4c88dc1 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -25,8 +25,7 @@ static const Util::EnumData InterpolatorTypeData[] = { {Geom::Interpolate::INTERP_CUBICBEZIER , N_("CubicBezierFit"), "CubicBezierFit"}, {Geom::Interpolate::INTERP_CUBICBEZIER_JOHAN , N_("CubicBezierJohan"), "CubicBezierJohan"}, {Geom::Interpolate::INTERP_SPIRO , N_("SpiroInterpolator"), "SpiroInterpolator"}, - {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"}, - {Geom::Interpolate::INTERP_BSPLINE , N_("BSpline"), "BSpline"} + {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"} }; static const Util::EnumDataConverter InterpolatorTypeConverter(InterpolatorTypeData, sizeof(InterpolatorTypeData)/sizeof(*InterpolatorTypeData)); diff --git a/src/live_effects/lpe-powerstroke-interpolators.h b/src/live_effects/lpe-powerstroke-interpolators.h index 21d25a797..e3ab37e27 100644 --- a/src/live_effects/lpe-powerstroke-interpolators.h +++ b/src/live_effects/lpe-powerstroke-interpolators.h @@ -15,7 +15,7 @@ #include <2geom/path.h> #include <2geom/bezier-utils.h> #include <2geom/sbasis-to-bezier.h> -#include + #include "live_effects/spiro.h" @@ -27,7 +27,6 @@ enum InterpolatorType { INTERP_LINEAR, INTERP_CUBICBEZIER, INTERP_CUBICBEZIER_JOHAN, - INTERP_BSPLINE, INTERP_SPIRO, INTERP_CUBICBEZIER_SMOOTH, INTERP_CENTRIPETAL_CATMULLROM @@ -66,57 +65,6 @@ private: Linear& operator=(const Linear&); }; -class BSpline : public Interpolator { -public: - BSpline() {}; - virtual ~BSpline() {}; - - virtual Path interpolateToPath(std::vector const &points) const { - Path path; - path.start( points.at(0) ); - Geom::Point handle_1(0,0); - Geom::Point handle_prev = points.at(0); - for (unsigned int i = 1 ; i < points.size() - 1; ++i) { - Geom::Line line_a(points.at(i - 1), points.at(i)); - double angle_a = line_a.angle(); - Geom::Line line_b(points.at(i),points.at(i + 1)); - double angle_b = line_b.angle(); - Geom::Line line_handles(line_a.pointAt(0.66667),line_b.pointAt(0.33334)); - line_handles *= Geom::Translate(points.at(i) - line_handles.pointAt(0.5)); - Geom::Line line_perp_a(line_a.pointAt(0.5), Geom::Point::polar(angle_a + Geom::rad_from_deg(90),1) +line_a.pointAt(0.5)); - Geom::Line line_perp_b(line_b.pointAt(0.5), Geom::Point::polar(angle_b + Geom::rad_from_deg(90),1) +line_b.pointAt(0.5)); - std::vector result = line_perp_a.intersect(line_perp_b); - Geom::Point handle_2(0,0); - if(result.size() > 0) { - Geom::Line line_to_handle_a(result[0],line_a.pointAt(0.66667)); - Geom::Line line_to_handle_b(result[0],line_b.pointAt(0.33334)); - std::vector handle_a_res = line_to_handle_a.intersect(line_handles); - std::vector handle_b_res = line_to_handle_b.intersect(line_handles); - if(handle_a_res.size() > 0) { - handle_2 = handle_a_res[0]; - } - if(handle_a_res.size() > 0) { - handle_1 = handle_b_res[0]; - } - } - if (i == 1) { - Geom::Line start_segment(handle_prev,handle_2); - handle_prev = start_segment.pointAt(0.5); - } - path.appendNew(handle_prev, handle_2, points.at(i)); - handle_prev = handle_1; - } - Geom::Point last = points.at(points.size()-1); - Geom::Line last_segment(last,handle_1); - path.appendNew(handle_1, last_segment.pointAt(0.5), last); - return path; - }; - -private: - BSpline(const BSpline&); - BSpline& operator=(const BSpline&); -}; - // this class is terrible class CubicBezierFit : public Interpolator { public: @@ -354,8 +302,6 @@ Interpolator::create(InterpolatorType type) { return new Geom::Interpolate::CubicBezierSmooth(); case INTERP_CENTRIPETAL_CATMULLROM: return new Geom::Interpolate::CentripetalCatmullRomInterpolator(); - case INTERP_BSPLINE: - return new Geom::Interpolate::BSpline(); default: return new Geom::Interpolate::Linear(); } diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index b2b55a08c..96f487211 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -123,8 +123,7 @@ static const Util::EnumData InterpolatorTypeData[] = { {Geom::Interpolate::INTERP_CUBICBEZIER , N_("CubicBezierFit"), "CubicBezierFit"}, {Geom::Interpolate::INTERP_CUBICBEZIER_JOHAN , N_("CubicBezierJohan"), "CubicBezierJohan"}, {Geom::Interpolate::INTERP_SPIRO , N_("SpiroInterpolator"), "SpiroInterpolator"}, - {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"}, - {Geom::Interpolate::INTERP_BSPLINE , N_("BSpline"), "BSpline"} + {Geom::Interpolate::INTERP_CENTRIPETAL_CATMULLROM, N_("Centripetal Catmull-Rom"), "CentripetalCatmullRom"} }; static const Util::EnumDataConverter InterpolatorTypeConverter(InterpolatorTypeData, sizeof(InterpolatorTypeData)/sizeof(*InterpolatorTypeData)); diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 2da570537..7c298d0e7 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -12,7 +12,6 @@ #include <2geom/svg-path-parser.h> #include "helper/geom.h" #include "desktop-style.h" -#include "display/curve.h" #include "style.h" #include "svg/svg.h" @@ -28,14 +27,12 @@ LPEShowHandles::LPEShowHandles(LivePathEffectObject *lpeobject) handles(_("Show handles"), _("Show handles"), "handles", &wr, this, true), original_path(_("Show path"), _("Show path"), "original_path", &wr, this, true), show_center_node(_("Show center of node"), _("Show center of node"), "show_center_node", &wr, this, false), - original_d(_("Show original"), _("Show original"), "original_d", &wr, this, false), scale_nodes_and_handles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scale_nodes_and_handles", &wr, this, 10) { registerParameter(&nodes); registerParameter(&handles); registerParameter(&original_path); registerParameter(&show_center_node); - registerParameter(&original_d); registerParameter(&scale_nodes_and_handles); scale_nodes_and_handles.param_set_range(0, 500.); scale_nodes_and_handles.param_set_increments(1, 1); @@ -83,7 +80,7 @@ void LPEShowHandles::doBeforeEffect (SPLPEItem const* lpeitem) Geom::PathVector LPEShowHandles::doEffect_path (Geom::PathVector const & path_in) { Geom::PathVector path_out; - Geom::PathVector original_pathv = pathv_to_linear_and_cubic_beziers(path_in); + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); if(original_path) { for (unsigned int i=0; i < path_in.size(); i++) { path_out.push_back(path_in[i]); @@ -92,26 +89,10 @@ Geom::PathVector LPEShowHandles::doEffect_path (Geom::PathVector const & path_in if(!outline_path.empty()) { outline_path.clear(); } - if (original_d) { - SPCurve * shape_curve = sp_shape->getCurveBeforeLPE(); - if (shape_curve) { - Geom::PathVector original_curve = shape_curve->get_pathvector(); - if(original_path) { - for (unsigned int i=0; i < original_curve.size(); i++) { - path_out.push_back(original_curve[i]); - } - } - original_pathv.insert(original_pathv.end(), original_curve.begin(), original_curve.end()); - } - generateHelperPath(original_pathv); - shape_curve->unref(); - } else { - generateHelperPath(original_pathv); - } + generateHelperPath(original_pathv); for (unsigned int i=0; i < outline_path.size(); i++) { path_out.push_back(outline_path[i]); } - return path_out; } diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index 583be9e61..c46abd2c2 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -43,7 +43,6 @@ private: BoolParam nodes; BoolParam handles; BoolParam original_path; - BoolParam original_d; BoolParam show_center_node; ScalarParam scale_nodes_and_handles; double stroke_width; -- cgit v1.2.3