summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-simplify.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-03-18 18:17:44 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-03-18 18:17:44 +0000
commit71508f76c3ddc33c41664599f9c10bf84d994d62 (patch)
tree68f69fd8c5b36c4f5a288bb8b2521405724cf9ce /src/live_effects/lpe-simplify.cpp
parentupdate to trunk (diff)
parentLatvian translation update (diff)
downloadinkscape-71508f76c3ddc33c41664599f9c10bf84d994d62.tar.gz
inkscape-71508f76c3ddc33c41664599f9c10bf84d994d62.zip
update to trunk
(bzr r13879.1.11)
Diffstat (limited to 'src/live_effects/lpe-simplify.cpp')
-rw-r--r--src/live_effects/lpe-simplify.cpp139
1 files changed, 83 insertions, 56 deletions
diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp
index 2b2efb1a9..1fe18dd5e 100644
--- a/src/live_effects/lpe-simplify.cpp
+++ b/src/live_effects/lpe-simplify.cpp
@@ -20,6 +20,7 @@
#include <2geom/generic-rect.h>
#include <2geom/interval.h>
#include "ui/icon-names.h"
+#include "util/units.h"
namespace Inkscape {
namespace LivePathEffect {
@@ -28,32 +29,37 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject)
: Effect(lpeobject),
steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1),
threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003),
- helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 2.),
- nodes(_("Helper nodes"), _("Show helper nodes"), "nodes", &wr, this, false,
- "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")),
- handles(_("Helper handles"), _("Show helper handles"), "handles", &wr, this, false,
- "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")),
+ smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to preform a smooth"), "smooth_angles", &wr, this, 20.),
+ helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5),
simplifyindividualpaths(_("Paths separately"), _("Simplifying paths (separately)"), "simplifyindividualpaths", &wr, this, false,
"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")),
simplifyJustCoalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplifyJustCoalesce", &wr, this, false,
"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off"))
{
- registerParameter(dynamic_cast<Parameter *>(&steps));
- registerParameter(dynamic_cast<Parameter *>(&threshold));
- registerParameter(dynamic_cast<Parameter *>(&helper_size));
- registerParameter(dynamic_cast<Parameter *>(&nodes));
- registerParameter(dynamic_cast<Parameter *>(&handles));
- registerParameter(dynamic_cast<Parameter *>(&simplifyindividualpaths));
- registerParameter(dynamic_cast<Parameter *>(&simplifyJustCoalesce));
+ registerParameter(&steps);
+ registerParameter(&threshold);
+ registerParameter(&smooth_angles);
+ registerParameter(&helper_size);
+ registerParameter(&simplifyindividualpaths);
+ registerParameter(&simplifyJustCoalesce);
+
threshold.param_set_range(0.0001, Geom::infinity());
threshold.param_set_increments(0.0001, 0.0001);
threshold.param_set_digits(6);
+
steps.param_set_range(0, 100);
steps.param_set_increments(1, 1);
steps.param_set_digits(0);
- helper_size.param_set_range(0.1, 100);
- helper_size.param_set_increments(1, 1);
- helper_size.param_set_digits(1);
+
+ smooth_angles.param_set_range(0.0, 365.0);
+ smooth_angles.param_set_increments(10, 10);
+ smooth_angles.param_set_digits(2);
+
+ helper_size.param_set_range(0.0, 999.0);
+ helper_size.param_set_increments(5, 5);
+ helper_size.param_set_digits(2);
+
+ radiusHelperNodes = 6.0;
}
LPESimplify::~LPESimplify() {}
@@ -66,9 +72,9 @@ LPESimplify::doBeforeEffect (SPLPEItem const* lpeitem)
}
bbox = SP_ITEM(lpeitem)->visualBounds();
SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem);
+ radiusHelperNodes = helper_size;
item->apply_to_clippath(item);
item->apply_to_mask(item);
-
}
Gtk::Widget *
@@ -81,7 +87,6 @@ LPESimplify::newWidget()
vbox->set_spacing(2);
std::vector<Parameter *>::iterator it = param_vector.begin();
Gtk::HBox * buttons = Gtk::manage(new Gtk::HBox(true,0));
- Gtk::HBox * buttonsTwo = Gtk::manage(new Gtk::HBox(true,0));
while (it != param_vector.end()) {
if ((*it)->widget_is_visible) {
Parameter * param = *it;
@@ -91,19 +96,6 @@ LPESimplify::newWidget()
{
Glib::ustring * tip = param->param_getTooltip();
if (widg) {
- buttonsTwo->pack_start(*widg, true, true, 2);
- if (tip) {
- widg->set_tooltip_text(*tip);
- } else {
- widg->set_tooltip_text("");
- widg->set_has_tooltip(false);
- }
- }
- } else if (param->param_key == "nodes" ||
- param->param_key == "handles")
- {
- Glib::ustring * tip = param->param_getTooltip();
- if (widg) {
buttons->pack_start(*widg, true, true, 2);
if (tip) {
widg->set_tooltip_text(*tip);
@@ -112,7 +104,7 @@ LPESimplify::newWidget()
widg->set_has_tooltip(false);
}
}
- }else{
+ } else{
Glib::ustring * tip = param->param_getTooltip();
if (widg) {
Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widg);
@@ -133,7 +125,6 @@ LPESimplify::newWidget()
++it;
}
vbox->pack_start(*buttons,true, true, 2);
- vbox->pack_start(*buttonsTwo,true, true, 2);
return dynamic_cast<Gtk::Widget *>(vbox);
}
@@ -154,9 +145,9 @@ LPESimplify::doEffect(SPCurve *curve) {
pathliv->Simplify(threshold * size);
}
}
- Geom::PathVector outres = Geom::parse_svg_path(pathliv->svg_dump_path());
- generateHelperPath(outres);
- curve->set_pathvector(outres);
+ Geom::PathVector result = Geom::parse_svg_path(pathliv->svg_dump_path());
+ generateHelperPathAndSmooth(result);
+ curve->set_pathvector(result);
SPDesktop* desktop = SP_ACTIVE_DESKTOP;
if(desktop && INK_IS_NODE_TOOL(desktop->event_context)){
Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context);
@@ -165,16 +156,12 @@ LPESimplify::doEffect(SPCurve *curve) {
}
void
-LPESimplify::generateHelperPath(Geom::PathVector result)
+LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result)
{
- if(!handles && !nodes){
- return;
- }
-
if(steps < 1){
return;
}
-
+ Geom::PathVector tmpPath;
Geom::CubicBezier const *cubic = NULL;
for (Geom::PathVector::iterator path_it = result.begin(); path_it != result.end(); ++path_it) {
//Si está vacío...
@@ -183,11 +170,9 @@ LPESimplify::generateHelperPath(Geom::PathVector result)
}
//Itreadores
Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve
- Geom::Path::const_iterator curve_it2 =
- ++(path_it->begin()); // outgoing curve
- Geom::Path::const_iterator curve_endit =
- path_it->end_default(); // this determines when the loop has to stop
-
+ Geom::Path::const_iterator curve_it2 = ++(path_it->begin());// outgoing curve
+ Geom::Path::const_iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop
+ SPCurve *nCurve = new SPCurve();
if (path_it->closed()) {
// if the path is closed, maybe we have to stop a bit earlier because the
// closing line segment has zerolength.
@@ -202,13 +187,50 @@ LPESimplify::generateHelperPath(Geom::PathVector result)
curve_endit = path_it->end_open();
}
}
- if(nodes){
+ if(helper_size > 0){
drawNode(curve_it1->initialPoint());
}
+ nCurve->moveto(curve_it1->initialPoint());
+ Geom::Point start = Geom::Point(0,0);
while (curve_it1 != curve_endit) {
cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1);
+ Geom::Point pointAt1 = curve_it1->initialPoint();
+ Geom::Point pointAt2 = curve_it1->finalPoint();
+ Geom::Point pointAt3 = curve_it1->finalPoint();
+ Geom::Point pointAt4 = curve_it1->finalPoint();
+ if (cubic) {
+ pointAt1 = (*cubic)[1];
+ pointAt2 = (*cubic)[2];
+ }
+ if(start == Geom::Point(0,0)){
+ start = pointAt1;
+ }
+
+ if(path_it->closed() && curve_it2 == curve_endit){
+ pointAt4 = start;
+ }
+ if(curve_it2 != curve_endit){
+ cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it2);
+ if (cubic) {
+ pointAt4 = (*cubic)[1];
+ }
+ }
+ Geom::Ray ray1(pointAt2, pointAt3);
+ Geom::Ray ray2(pointAt3, pointAt4);
+ double angle1 = Geom::rad_to_deg(ray1.angle());
+ double angle2 = Geom::rad_to_deg(ray2.angle());
+ if((smooth_angles >= angle2 - angle1) && !are_near(pointAt4,pointAt3) && !are_near(pointAt2,pointAt3)){
+ double dist = Geom::distance(pointAt2,pointAt3);
+ Geom::Angle angleFixed = ray2.angle();
+ angleFixed -= Geom::Angle::from_degrees(180.0);
+ pointAt2 = Geom::Point::polar(angleFixed,dist) + pointAt3;
+ }
+ nCurve->curveto(pointAt1, pointAt2, curve_it1->finalPoint());
+ cubic = dynamic_cast<Geom::CubicBezier const *>(nCurve->last_segment());
if (cubic) {
- if(handles) {
+ pointAt1 = (*cubic)[1];
+ pointAt2 = (*cubic)[2];
+ if(helper_size > 0) {
if(!are_near((*cubic)[0],(*cubic)[1])){
drawHandle((*cubic)[1]);
drawHandleLine((*cubic)[0],(*cubic)[1]);
@@ -219,21 +241,26 @@ LPESimplify::generateHelperPath(Geom::PathVector result)
}
}
}
- if(nodes) {
+ if(helper_size > 0) {
drawNode(curve_it1->finalPoint());
}
++curve_it1;
- if(curve_it2 != curve_endit){
- ++curve_it2;
- }
+ ++curve_it2;
+ }
+ if (path_it->closed()) {
+ nCurve->closepath_current();
}
+ tmpPath.push_back(nCurve->get_pathvector()[0]);
+ nCurve->reset();
+ delete nCurve;
}
+ result = tmpPath;
}
void
LPESimplify::drawNode(Geom::Point p)
{
- double r = helper_size/0.67;
+ double r = radiusHelperNodes;
char const * svgd;
svgd = "M 0.55,0.5 A 0.05,0.05 0 0 1 0.5,0.55 0.05,0.05 0 0 1 0.45,0.5 0.05,0.05 0 0 1 0.5,0.45 0.05,0.05 0 0 1 0.55,0.5 Z M 0,0 1,0 1,1 0,1 Z";
Geom::PathVector pathv = sp_svg_read_pathv(svgd);
@@ -246,7 +273,7 @@ LPESimplify::drawNode(Geom::Point p)
void
LPESimplify::drawHandle(Geom::Point p)
{
- double r = helper_size/0.67;
+ double r = radiusHelperNodes;
char const * svgd;
svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z";
Geom::PathVector pathv = sp_svg_read_pathv(svgd);
@@ -261,8 +288,8 @@ LPESimplify::drawHandleLine(Geom::Point p,Geom::Point p2)
{
Geom::Path path;
path.start( p );
- double diameter = helper_size/0.67;
- if(helper_size > 0.0 && Geom::distance(p,p2) > (diameter * 0.35)){
+ double diameter = radiusHelperNodes;
+ if(helper_size > 0 && Geom::distance(p,p2) > (diameter * 0.35)){
Geom::Ray ray2(p, p2);
p2 = p2 - Geom::Point::polar(ray2.angle(),(diameter * 0.35));
}