diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-12-02 10:51:39 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-12-02 10:51:39 +0000 |
| commit | b95f5438b75deffac0e8780857733257e21b1f68 (patch) | |
| tree | b261d5af0bdcf1c0c0a051ddf017e5d3dccbd677 /src | |
| parent | Merge branch 'master' into powerpencilII (diff) | |
| download | inkscape-b95f5438b75deffac0e8780857733257e21b1f68.tar.gz inkscape-b95f5438b75deffac0e8780857733257e21b1f68.zip | |
Remobing bspline interpolator
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-interpolate_points.cpp | 3 | ||||
| -rw-r--r-- | src/live_effects/lpe-powerstroke-interpolators.h | 78 | ||||
| -rw-r--r-- | src/live_effects/lpe-powerstroke.cpp | 9 | ||||
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 1 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.cpp | 1 |
5 files changed, 9 insertions, 83 deletions
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<unsigned> 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<unsigned> 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 0c1b60754..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 <math.h> + #include "live_effects/spiro.h" @@ -29,8 +29,7 @@ enum InterpolatorType { INTERP_CUBICBEZIER_JOHAN, INTERP_SPIRO, INTERP_CUBICBEZIER_SMOOTH, - INTERP_CENTRIPETAL_CATMULLROM, - INTERP_BSPLINE + INTERP_CENTRIPETAL_CATMULLROM }; class Interpolator { @@ -66,77 +65,6 @@ private: Linear& operator=(const Linear&); }; -class BSpline : public Interpolator { -public: - BSpline() {}; - virtual ~BSpline() {}; - - virtual Path interpolateToPath(std::vector<Point> const &points) const { - Path path; - path.start( points.at(0) ); - - Geom::Point point_a = points.at(0); - Geom::Point point_b = points.at(1); - Geom::Point point_c = points.at(2); - Geom::Point point_d = points.at(2); - if (points.size() > 3) { - point_d = points.at(3); - } - Geom::Point handle_1 = point_a; - Geom::Point handle_2 = point_b; - Geom::Point node_1 = point_a; - Geom::Point node_2 = point_b; //if the line is straight with next - Geom::Line line_ab(point_a, point_b); - Geom::Line line_bc(point_b, point_c); - Geom::Line line_cd(point_c, point_d); - Geom::Point handle_next(line_bc.pointAt(0.33334)); //if the line is straight with next - Geom::Point center_ab = line_ab.pointAt(0.5); - Geom::Point center_bc = line_bc.pointAt(0.5); - Geom::Point center_cd = line_cd.pointAt(0.5); - Geom::Line cross_line_hlp(line_ab.pointAt(0.66667), center_cd); - Geom::Point cross_center_hlp = cross_line_hlp.pointAt(0.5); - double angle_ab = line_ab.angle(); - double angle_bc = line_bc.angle(); - double angle_cd = line_cd.angle(); - double cross_angle_hlp = cross_line_hlp.angle(); - Geom::Line perpend_ab(center_ab, center_ab + Geom::Point::polar(angle_ab + Geom::rad_from_deg(90),1)); - Geom::Line perpend_bc(center_bc, center_bc + Geom::Point::polar(angle_bc + Geom::rad_from_deg(90),1)); - Geom::Line cross_1 (cross_center_hlp, cross_center_hlp + Geom::Point::polar(cross_angle_hlp + Geom::rad_from_deg(90),1)); - std::vector<CurveIntersection> cross_hlp = perpend_ab.intersect(perpend_bc); - if(cross_hlp.size() > 0) { - cross_line_hlp.setPoints(cross_hlp[0], line_ab.pointAt(0.66667)); - cross_angle_hlp = cross_line_hlp.angle(); - Geom::Line cross_2(line_ab.pointAt(0.66667), line_ab.pointAt(0.66667) + Geom::Point::polar(cross_angle_hlp + Geom::rad_from_deg(90),1)); - std::vector<CurveIntersection> cross = cross_1.intersect(cross_2); - if(cross.size() > 0) { - Geom::Line handle_line(cross[0],point_b); - handle_2 = handle_line.pointAt(2.0); - Geom::Line rootline(points.at(0),handle_2); - handle_1 = rootline.pointAt(0.5); - node_2 = rootline.pointAt(1.5); - handle_next = cross[0]; - } - } - path.appendNew<CubicBezier>(handle_1, handle_2, points.at(1)); - for (unsigned int i = 2 ; i < points.size(); ++i) { - Geom::Line rootline(node_2, handle_next); - handle_2 = rootline.pointAt(2.0); - node_2 = rootline.pointAt(3.0); - path.appendNew<CubicBezier>(handle_next, handle_2, points.at(i)); - Geom::Line handleline(handle_2, points.at(i)); - handle_next = handleline.pointAt(2.0); - } - Geom::Point last = points.at(points.size()-1); - Geom::LineSegment last_segment(handle_next,last); - path.appendNew<CubicBezier>(last_segment.initialPoint(), 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: @@ -374,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 47543107b..f4e4a06ca 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -123,8 +123,7 @@ static const Util::EnumData<unsigned> 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<unsigned> InterpolatorTypeConverter(InterpolatorTypeData, sizeof(InterpolatorTypeData)/sizeof(*InterpolatorTypeData)); @@ -165,8 +164,8 @@ static const Util::EnumDataConverter<unsigned> 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), + interpolate_original(_("Interpolate original"), _("Interpolate original path"), "interpolate_original", &wr, this, false), 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), scale_width(_("Width scale:"), _("Width scale all points"), "scale_width", &wr, this, 1.0), @@ -706,7 +705,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) Geom::Path fixed_path; Geom::Path fixed_mirrorpath; Geom::Path strokepath; - if (interpolate_original) { + if (interpolate_original && 2==1) { std::vector<Geom::Point> ts_normal; std::vector<Geom::Point> ts_mirror; @@ -782,7 +781,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) y = portion(y, rtsmin.at(0), rtsmax.at(0)); } - if (!interpolate_original) { + if (!interpolate_original || 2>1) { LineJoinType jointype = static_cast<LineJoinType>(linejoin_type.get_value()); Piecewise<D2<SBasis> > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); Piecewise<D2<SBasis> > mirrorpath = reverse( compose(pwd2_in,x) - y*compose(n,x)); diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index 15027b6f3..89d9074ba 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -258,6 +258,7 @@ static void spdc_apply_powerstroke_shape(std::vector<Geom::Point> points, Freeha Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); lpe->getRepr()->setAttribute("sort_points", "true"); lpe->getRepr()->setAttribute("interpolator_type", "CentripetalCatmullRom"); + lpe->getRepr()->setAttribute("interpolate_original", "true"); lpe->getRepr()->setAttribute("interpolator_beta", "0.2"); lpe->getRepr()->setAttribute("miter_limit", "100"); lpe->getRepr()->setAttribute("linejoin_type", "miter"); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 1e1650d44..108a89af8 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -684,6 +684,7 @@ PencilTool::_powerStrokePreview(Geom::Path const path, std::vector<Geom::Point> Effect* lpe = lpeitem->getCurrentLPE(); lpe->getRepr()->setAttribute("sort_points", "true"); lpe->getRepr()->setAttribute("interpolator_type", "CentripetalCatmullRom"); + lpe->getRepr()->setAttribute("interpolate_original", "true"); lpe->getRepr()->setAttribute("interpolator_beta", "0.2"); lpe->getRepr()->setAttribute("miter_limit", "100"); lpe->getRepr()->setAttribute("linejoin_type", "miter"); |
