summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-curvestitch.cpp
diff options
context:
space:
mode:
authorPeter Moulder <peter.moulder@monash.edu>2007-10-11 14:30:52 +0000
committerpjrm <pjrm@users.sourceforge.net>2007-10-11 14:30:52 +0000
commitb7403d737c0549e540393bfe92160a5fc7b407a1 (patch)
tree784c7cbfd26a14f67679376a700dce1d61262bb1 /src/live_effects/lpe-curvestitch.cpp
parenttrivial: ui/widget/*, ui/dialog/*: svn propset svn:eol-style native *.h *.cpp. (diff)
downloadinkscape-b7403d737c0549e540393bfe92160a5fc7b407a1.tar.gz
inkscape-b7403d737c0549e540393bfe92160a5fc7b407a1.zip
trivial: live_effects/**: svn propset svn:eol-style native *.h *.cpp.
(bzr r3884)
Diffstat (limited to 'src/live_effects/lpe-curvestitch.cpp')
-rw-r--r--src/live_effects/lpe-curvestitch.cpp270
1 files changed, 135 insertions, 135 deletions
diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp
index 7368fd55b..c39277727 100644
--- a/src/live_effects/lpe-curvestitch.cpp
+++ b/src/live_effects/lpe-curvestitch.cpp
@@ -1,135 +1,135 @@
-#define INKSCAPE_LPE_EXPRESSION_CPP
-/** \file
- * SVG <skeleton> implementation, used as an example for a base starting class
- * when implementing new LivePathEffects.
- *
- */
-/*
- * Authors:
- * Johan Engelen
-*
-* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include "live_effects/lpe-curvestitch.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
-
-#include <2geom/path.h>
-#include <2geom/piecewise.h>
-#include <2geom/sbasis.h>
-#include <2geom/sbasis-geometric.h>
-#include <2geom/bezier-to-sbasis.h>
-#include <2geom/sbasis-to-bezier.h>
-#include <2geom/d2.h>
-#include <2geom/matrix.h>
-
-
-#include "ui/widget/scalar.h"
-#include "libnr/nr-values.h"
-
-namespace Inkscape {
-namespace LivePathEffect {
-
-using namespace Geom;
-
-LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) :
- Effect(lpeobject),
- strokepath(_("Stroke path"), _("The path that will be stroked, whatever, think of good text here."), "strokepath", &wr, this, "M0,0 L1,0"),
- nrofpaths(_("Nr of paths"), _("The number of paths that will be generated."), "count", &wr, this, 5),
- startpoint_variation(_("Startpoint variation"), _("..."), "startpoint_variation", &wr, this, 0),
- endpoint_variation(_("Endpoint variation"), _("..."), "endpoint_variation", &wr, this, 0),
- prop_scale(_("Scale width"), _("Scaling of the width of the stroke path"), "prop_scale", &wr, this, 1),
- scale_y_rel(_("Scale width relative"), _("Scale the width of the stroke path relative to its length"), "scale_y_rel", &wr, this, false)
-{
- registerParameter( dynamic_cast<Parameter *>(&nrofpaths) );
- registerParameter( dynamic_cast<Parameter *>(&startpoint_variation) );
- registerParameter( dynamic_cast<Parameter *>(&endpoint_variation) );
- registerParameter( dynamic_cast<Parameter *>(&strokepath) );
- registerParameter( dynamic_cast<Parameter *>(&prop_scale) );
- registerParameter( dynamic_cast<Parameter *>(&scale_y_rel) );
-
- nrofpaths.param_make_integer();
- nrofpaths.param_set_range(2, NR_HUGE);
-
- prop_scale.param_set_digits(3);
- prop_scale.param_set_increments(0.01, 0.10);
-}
-
-LPECurveStitch::~LPECurveStitch()
-{
-
-}
-
-std::vector<Geom::Path>
-LPECurveStitch::doEffect (std::vector<Geom::Path> & path_in)
-{
- if (path_in.size() >= 2) {
- startpoint_variation.resetRandomizer();
- endpoint_variation.resetRandomizer();
-
- D2<Piecewise<SBasis> > stroke = make_cuts_independant(strokepath);
- Interval bndsStroke = bounds_exact(stroke[0]);
- gdouble scaling = bndsStroke.max() - bndsStroke.min();
- Interval bndsStrokeY = bounds_exact(stroke[1]);
- Point stroke_origin(bndsStroke.min(), (bndsStrokeY.max()+bndsStrokeY.min())/2);
-
- std::vector<Geom::Path> path_out (nrofpaths);
-
- // do this for all permutations if there are more than 2 paths? realllly cool!
- Piecewise<D2<SBasis> > A = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[0].toPwSb()),2,.1);
- Piecewise<D2<SBasis> > B = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[1].toPwSb()),2,.1);
- Interval bndsA = A.domain();
- Interval bndsB = B.domain();
- gdouble incrementA = (bndsA.max()-bndsA.min()) / (nrofpaths-1);
- gdouble incrementB = (bndsB.max()-bndsB.min()) / (nrofpaths-1);
- gdouble tA = bndsA.min();
- gdouble tB = bndsB.min();
- for (int i = 0; i < nrofpaths; i++) {
- Point start = A(tA);
- Point end = B(tB);
- if (startpoint_variation.get_value() != 0)
- start = start + startpoint_variation * (end - start);
- if (endpoint_variation.get_value() != 0)
- end = end + endpoint_variation * (end - start);
-
- gdouble scaling_y = 1.0;
- if (scale_y_rel.get_value()) {
- scaling_y = (L2(end-start)/scaling)*prop_scale;
- } else {
- scaling_y = prop_scale;
- }
-
- Matrix transform;
- transform.setXAxis( (end-start) / scaling );
- transform.setYAxis( rot90(unit_vector(end-start)) * scaling_y);
- transform.setTranslation( start );
- Piecewise<D2<SBasis> > pwd2_out = (strokepath-stroke_origin) * transform;
- // add stuff to one big pw<d2<sbasis> > and then outside the loop convert to path?
- std::vector<Path> result = Geom::path_from_piecewise(pwd2_out, LPE_CONVERSION_TOLERANCE);
- path_out[i] = result[0];
- tA += incrementA;
- tB += incrementB;
- }
-
- return path_out;
- } else {
- return path_in;
- }
-}
-
-} //namespace LivePathEffect
-} /* namespace Inkscape */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+#define INKSCAPE_LPE_EXPRESSION_CPP
+/** \file
+ * SVG <skeleton> implementation, used as an example for a base starting class
+ * when implementing new LivePathEffects.
+ *
+ */
+/*
+ * Authors:
+ * Johan Engelen
+*
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/lpe-curvestitch.h"
+#include "display/curve.h"
+#include <libnr/n-art-bpath.h>
+
+#include <2geom/path.h>
+#include <2geom/piecewise.h>
+#include <2geom/sbasis.h>
+#include <2geom/sbasis-geometric.h>
+#include <2geom/bezier-to-sbasis.h>
+#include <2geom/sbasis-to-bezier.h>
+#include <2geom/d2.h>
+#include <2geom/matrix.h>
+
+
+#include "ui/widget/scalar.h"
+#include "libnr/nr-values.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+using namespace Geom;
+
+LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ strokepath(_("Stroke path"), _("The path that will be stroked, whatever, think of good text here."), "strokepath", &wr, this, "M0,0 L1,0"),
+ nrofpaths(_("Nr of paths"), _("The number of paths that will be generated."), "count", &wr, this, 5),
+ startpoint_variation(_("Startpoint variation"), _("..."), "startpoint_variation", &wr, this, 0),
+ endpoint_variation(_("Endpoint variation"), _("..."), "endpoint_variation", &wr, this, 0),
+ prop_scale(_("Scale width"), _("Scaling of the width of the stroke path"), "prop_scale", &wr, this, 1),
+ scale_y_rel(_("Scale width relative"), _("Scale the width of the stroke path relative to its length"), "scale_y_rel", &wr, this, false)
+{
+ registerParameter( dynamic_cast<Parameter *>(&nrofpaths) );
+ registerParameter( dynamic_cast<Parameter *>(&startpoint_variation) );
+ registerParameter( dynamic_cast<Parameter *>(&endpoint_variation) );
+ registerParameter( dynamic_cast<Parameter *>(&strokepath) );
+ registerParameter( dynamic_cast<Parameter *>(&prop_scale) );
+ registerParameter( dynamic_cast<Parameter *>(&scale_y_rel) );
+
+ nrofpaths.param_make_integer();
+ nrofpaths.param_set_range(2, NR_HUGE);
+
+ prop_scale.param_set_digits(3);
+ prop_scale.param_set_increments(0.01, 0.10);
+}
+
+LPECurveStitch::~LPECurveStitch()
+{
+
+}
+
+std::vector<Geom::Path>
+LPECurveStitch::doEffect (std::vector<Geom::Path> & path_in)
+{
+ if (path_in.size() >= 2) {
+ startpoint_variation.resetRandomizer();
+ endpoint_variation.resetRandomizer();
+
+ D2<Piecewise<SBasis> > stroke = make_cuts_independant(strokepath);
+ Interval bndsStroke = bounds_exact(stroke[0]);
+ gdouble scaling = bndsStroke.max() - bndsStroke.min();
+ Interval bndsStrokeY = bounds_exact(stroke[1]);
+ Point stroke_origin(bndsStroke.min(), (bndsStrokeY.max()+bndsStrokeY.min())/2);
+
+ std::vector<Geom::Path> path_out (nrofpaths);
+
+ // do this for all permutations if there are more than 2 paths? realllly cool!
+ Piecewise<D2<SBasis> > A = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[0].toPwSb()),2,.1);
+ Piecewise<D2<SBasis> > B = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[1].toPwSb()),2,.1);
+ Interval bndsA = A.domain();
+ Interval bndsB = B.domain();
+ gdouble incrementA = (bndsA.max()-bndsA.min()) / (nrofpaths-1);
+ gdouble incrementB = (bndsB.max()-bndsB.min()) / (nrofpaths-1);
+ gdouble tA = bndsA.min();
+ gdouble tB = bndsB.min();
+ for (int i = 0; i < nrofpaths; i++) {
+ Point start = A(tA);
+ Point end = B(tB);
+ if (startpoint_variation.get_value() != 0)
+ start = start + startpoint_variation * (end - start);
+ if (endpoint_variation.get_value() != 0)
+ end = end + endpoint_variation * (end - start);
+
+ gdouble scaling_y = 1.0;
+ if (scale_y_rel.get_value()) {
+ scaling_y = (L2(end-start)/scaling)*prop_scale;
+ } else {
+ scaling_y = prop_scale;
+ }
+
+ Matrix transform;
+ transform.setXAxis( (end-start) / scaling );
+ transform.setYAxis( rot90(unit_vector(end-start)) * scaling_y);
+ transform.setTranslation( start );
+ Piecewise<D2<SBasis> > pwd2_out = (strokepath-stroke_origin) * transform;
+ // add stuff to one big pw<d2<sbasis> > and then outside the loop convert to path?
+ std::vector<Path> result = Geom::path_from_piecewise(pwd2_out, LPE_CONVERSION_TOLERANCE);
+ path_out[i] = result[0];
+ tA += incrementA;
+ tB += incrementB;
+ }
+
+ return path_out;
+ } else {
+ return path_in;
+ }
+}
+
+} //namespace LivePathEffect
+} /* namespace Inkscape */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :