summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: db6bf59)
raw | patch | inline | side by side (parent: db6bf59)
author | jfbarraud <jfbarraud@users.sourceforge.net> | |
Mon, 25 Feb 2008 00:04:24 +0000 (00:04 +0000) | ||
committer | jfbarraud <jfbarraud@users.sourceforge.net> | |
Mon, 25 Feb 2008 00:04:24 +0000 (00:04 +0000) |
src/live_effects/Makefile_insert | patch | blob | history | |
src/live_effects/effect.cpp | patch | blob | history | |
src/live_effects/effect.h | patch | blob | history | |
src/live_effects/lpe-knot.cpp | [new file with mode: 0644] | patch | blob |
src/live_effects/lpe-knot.h | [new file with mode: 0644] | patch | blob |
src/live_effects/lpe-sketch.cpp | [new file with mode: 0644] | patch | blob |
src/live_effects/lpe-sketch.h | [new file with mode: 0644] | patch | blob |
src/live_effects/lpe-vonkoch.cpp | [new file with mode: 0644] | patch | blob |
src/live_effects/lpe-vonkoch.h | [new file with mode: 0644] | patch | blob |
index 2c9192468cf222c08b268ffd4a83b4584d19e815..d639bb42d459601c468b4c09cadfd6aff041eaeb 100644 (file)
live_effects/lpe-skeletalstrokes.h \\r
live_effects/lpe-pathalongpath.cpp \\r
live_effects/lpe-pathalongpath.h \\r
+ live_effects/lpe-sketch.cpp \\r
+ live_effects/lpe-sketch.h \\r
+ live_effects/lpe-knot.cpp \\r
+ live_effects/lpe-knot.h \\r
+ live_effects/lpe-vonkoch.cpp \\r
+ live_effects/lpe-vonkoch.h \\r
live_effects/lpe-curvestitch.cpp \\r
live_effects/lpe-curvestitch.h \\r
live_effects/lpe-gears.cpp \\r
index bdbc4dd52e1142612ecde365ca8e2426ffecc2de..777be6e77a2796ab92c3a90cb0ddf9a7b7649938 100644 (file)
// include effects:
#include "live_effects/lpe-skeletalstrokes.h"
#include "live_effects/lpe-pathalongpath.h"
+//here!!
+#include "live_effects/lpe-sketch.h"
+#include "live_effects/lpe-vonkoch.h"
+#include "live_effects/lpe-knot.h"
#include "live_effects/lpe-slant.h"
#include "live_effects/lpe-test-doEffect-stack.h"
#include "live_effects/lpe-gears.h"
// {constant defined in effect.h, N_("name of your effect"), "name of your effect in SVG"}
{PATH_ALONG_PATH, N_("Bend Path"), "bend_path"},
{SKELETAL_STROKES, N_("Pattern Along Path"), "skeletal"},
+ {SKETCH, N_("Sketch"), "sketch"},
+ {VONKOCH, N_("VonKoch"), "vonkoch"},
+ {KNOT, N_("Knot"), "knot"},
#ifdef LPE_ENABLE_TEST_EFFECTS
{SLANT, N_("Slant"), "slant"},
{DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"},
case PATH_ALONG_PATH:
neweffect = (Effect*) new LPEPathAlongPath(lpeobj);
break;
+//here!!
+ case SKETCH:
+ neweffect = (Effect*) new LPESketch(lpeobj);
+ break;
+ case VONKOCH:
+ neweffect = (Effect*) new LPEVonKoch(lpeobj);
+ break;
+ case KNOT:
+ neweffect = (Effect*) new LPEKnot(lpeobj);
+ break;
#ifdef LPE_ENABLE_TEST_EFFECTS
case SLANT:
neweffect = (Effect*) new LPESlant(lpeobj);
index 8354c218b1809d4ca4a4b2a9e3097131e795bae3..fb5e85b1bc60d0c72946521aadcd78f88c7c616f 100644 (file)
enum EffectType {
PATH_ALONG_PATH = 0,
SKELETAL_STROKES,
+ SKETCH,
+ VONKOCH,
+ KNOT,
#ifdef LPE_ENABLE_TEST_EFFECTS
SLANT,
DOEFFECTSTACK_TEST,
diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp
--- /dev/null
@@ -0,0 +1,260 @@
+#define INKSCAPE_LPE_KNOT_CPP\r
+/** \file\r
+ * LPE <knot> implementation\r
+ */\r
+/*\r
+ * Authors:\r
+ * Johan Engelen\r
+*\r
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/lpe-knot.h"\r
+#include "display/curve.h"\r
+#include <libnr/n-art-bpath.h>\r
+\r
+// You might need to include other 2geom files. You can add them here:\r
+#include <2geom/path.h>\r
+#include <2geom/sbasis.h>\r
+#include <2geom/sbasis-geometric.h>\r
+#include <2geom/bezier-to-sbasis.h>\r
+#include <2geom/sbasis-to-bezier.h>\r
+#include <2geom/d2.h>\r
+#include <2geom/sbasis-math.h>\r
+#include <2geom/piecewise.h>\r
+#include <2geom/crossing.h>\r
+#include <2geom/path-intersection.h>\r
+\r
+namespace Inkscape {\r
+namespace LivePathEffect {\r
+\r
+LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) :\r
+ Effect(lpeobject),\r
+ // initialise your parameters here:\r
+ interruption_width(_("Interruption width"), _("Howmuch the lower strand is obscured by the upper."), "interruption_width", &wr, this, 1.2)\r
+{\r
+ // register all your parameters here, so Inkscape knows which parameters this effect has:\r
+ registerParameter( dynamic_cast<Parameter *>(&interruption_width) );\r
+}\r
+\r
+LPEKnot::~LPEKnot()\r
+{\r
+\r
+}\r
+\r
+\r
+/* ########################\r
+ * Choose to implement one of the doEffect functions. You can delete or comment out the others.\r
+*/\r
+\r
+/*\r
+void\r
+LPEKnot::doEffect (SPCurve * curve)\r
+{\r
+ // spice this up to make the effect actually *do* something!\r
+}\r
+\r
+NArtBpath *\r
+LPEKnot::doEffect_nartbpath (NArtBpath * path_in)\r
+{\r
+ NArtBpath *path_out;\r
+ unsigned ret = 0;\r
+ while ( path_in[ret].code != NR_END ) {\r
+ ++ret;\r
+ }\r
+ unsigned len = ++ret;\r
+ path_out = g_new(NArtBpath, len);\r
+\r
+ memcpy(path_out, path_in, len * sizeof(NArtBpath)); // spice this up to make the effect actually *do* something!\r
+\r
+ return path_out;\r
+}\r
+*/\r
+\r
+std::vector<Geom::Interval> complementOf(Geom::Interval I, std::vector<Geom::Interval> domain){\r
+ std::vector<Geom::Interval> ret;\r
+ double min = domain.front().min();\r
+ double max = domain.back().max();\r
+ Geom::Interval I1 = Geom::Interval(min,I.min());\r
+ Geom::Interval I2 = Geom::Interval(I.max(),max);\r
+\r
+ for (unsigned i = 0; i<domain.size(); i++){\r
+ boost::optional<Geom::Interval> I1i = intersect(domain.at(i),I1);\r
+ if (I1i) ret.push_back(I1i.get());\r
+ boost::optional<Geom::Interval> I2i = intersect(domain.at(i),I2);\r
+ if (I2i) ret.push_back(I2i.get());\r
+ }\r
+ return ret;\r
+}\r
+\r
+Geom::Interval\r
+findShadowedTime(Geom::Path &patha, \r
+ Geom::Path &pathb, \r
+ Geom::Crossing crossing, \r
+ unsigned idx, double width){\r
+ using namespace Geom;\r
+ double curveidx, timeoncurve = modf(crossing.getOtherTime(idx),&curveidx);\r
+ if(curveidx == pathb.size() && timeoncurve == 0) { curveidx--; timeoncurve = 0.99999;}\r
+ assert(curveidx >= 0 && curveidx < pathb.size());\r
+ \r
+ std::vector<Point> MV = pathb[unsigned(curveidx)].pointAndDerivatives(timeoncurve,2);\r
+ Point T = unit_vector(MV.at(1));\r
+ Point N = T.cw();\r
+ Point A = MV.at(0)-10*width*T, B = MV.at(0)+10*width*T;\r
+ \r
+ std::vector<Geom::Path> cutter;\r
+ Geom::Path cutterLeft = Geom::Path();\r
+ Geom::Path cutterRight = Geom::Path();\r
+ cutterLeft.append (LineSegment (A-width*N, B-width*N));\r
+ cutterRight.append(LineSegment (A+width*N, B+width*N));\r
+ cutter.push_back(cutterLeft);\r
+ cutter.push_back(cutterRight);\r
+ \r
+ std::vector<Geom::Path> patha_as_vect = std::vector<Geom::Path>(1,patha);\r
+ \r
+ CrossingSet crossingTable = crossings (patha_as_vect, cutter);\r
+ double t0 = crossing.getTime(idx);\r
+ double tmin = 0,tmax = patha.size()-0.0001;\r
+ assert(crossingTable.size()>=1);\r
+ for (unsigned c=0; c<crossingTable.front().size(); c++){\r
+ double t = crossingTable.front().at(c).ta;\r
+ assert(crossingTable.front().at(c).a==0);\r
+ if (t>tmin and t<t0) tmin = t;\r
+ if (t<tmax and t>t0) tmax = t;\r
+ }\r
+ //return Interval(t0-0.1,t0+0.1);\r
+ return Interval(tmin,tmax);\r
+} \r
+\r
+\r
+std::vector<Geom::Path>\r
+LPEKnot::doEffect_path (std::vector<Geom::Path> & path_in)\r
+{\r
+ using namespace Geom;\r
+ std::vector<Geom::Path> path_out;\r
+ double width = interruption_width;\r
+ \r
+ CrossingSet crossingTable = crossings_among(path_in);\r
+ for (unsigned i = 0; i < crossingTable.size(); i++){\r
+ std::vector<Interval> dom;\r
+ dom.push_back(Interval(0.,path_in.at(i).size()-0.00001));\r
+ //TODO: handle closed curves...\r
+ for (unsigned crs = 0; crs < crossingTable.at(i).size(); crs++){\r
+ Crossing crossing = crossingTable.at(i).at(crs);\r
+ unsigned j = crossing.getOther(i);\r
+ //TODO: select dir according to a parameter...\r
+ if ((crossing.dir and crossing.a==i) or (not crossing.dir and crossing.b==i) or (i==j)){\r
+ if (i==j and not crossing.dir) {\r
+ double temp = crossing.ta;\r
+ crossing.ta = crossing.tb; \r
+ crossing.tb = temp; \r
+ crossing.dir = not crossing.dir;\r
+ }\r
+ Interval hidden = findShadowedTime(path_in.at(i),path_in.at(j),crossing,i,width); \r
+ dom = complementOf(hidden,dom);\r
+ }\r
+ }\r
+ for (unsigned comp = 0; comp < dom.size(); comp++){\r
+ assert(dom.at(comp).min() >=0 and dom.at(comp).max() < path_in.at(i).size());\r
+ path_out.push_back(path_in.at(i).portion(dom.at(comp)));\r
+ }\r
+ \r
+// std::vector<Point> MV = path_in[0][0].pointAndDerivatives(crossingTable[0][0].getTime(0),2);\r
+// Point U = unit_vector(MV[1]);\r
+// Point N = U.cw();\r
+// Point A = MV[0]-10.*width*U, B = MV[0]+10*width*U;\r
+ \r
+// Geom::Path cutter;\r
+// cutter = Geom::Path();\r
+// cutter.append( LineSegment(A+width*N,B+width*N));\r
+// path_out.push_back(cutter);\r
+// cutter = Geom::Path();\r
+// cutter.append( LineSegment(A-width*N,B-width*N));\r
+// path_out.push_back(cutter);\r
+\r
+ } \r
+ return path_out;\r
+}\r
+\r
+\r
+/*\r
+Geom::Piecewise<Geom::D2<Geom::SBasis> >\r
+addLinearEnds (Geom::Piecewise<Geom::D2<Geom::SBasis> > & m){\r
+ using namespace Geom;\r
+ Piecewise<D2<SBasis> > output;\r
+ Piecewise<D2<SBasis> > start;\r
+ Piecewise<D2<SBasis> > end;\r
+ double x,y,vx,vy;\r
+\r
+ x = m.segs.front()[0].at0();\r
+ y = m.segs.front()[1].at0();\r
+ vx = m.segs.front()[0][1][0]+Tri(m.segs.front()[0][0]);\r
+ vy = m.segs.front()[1][1][0]+Tri(m.segs.front()[1][0]);\r
+ start = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x-vx,x),Linear (y-vy,y)));\r
+ start.offsetDomain(m.cuts.front()-1.);\r
+\r
+ x = m.segs.back()[0].at1();\r
+ y = m.segs.back()[1].at1();\r
+ vx = -m.segs.back()[0][1][1]+Tri(m.segs.back()[0][0]);;\r
+ vy = -m.segs.back()[1][1][1]+Tri(m.segs.back()[1][0]);;\r
+ end = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x,x+vx),Linear (y,y+vy)));\r
+ //end.offsetDomain(m.cuts.back());\r
+\r
+ output = start;\r
+ output.concat(m);\r
+ output.concat(end);\r
+ return output;\r
+}\r
+\r
+Geom::Piecewise<Geom::D2<Geom::SBasis> >\r
+LPEKnot::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)\r
+{\r
+ using namespace Geom;\r
+\r
+\r
+ Piecewise<D2<SBasis> > output;\r
+ Piecewise<D2<SBasis> > m = addLinearEnds(pwd2_in);\r
+\r
+ Piecewise<D2<SBasis> > v = derivative(pwd2_in);\r
+ Piecewise<D2<SBasis> > n = unitVector(v);\r
+\r
+// // -------- Pleins et delies vs courbure ou direction...\r
+// Piecewise<D2<SBasis> > a = derivative(v);\r
+// Piecewise<SBasis> a_cross_n = cross(a,n);\r
+// Piecewise<SBasis> v_dot_n = dot(v,n);\r
+// //Piecewise<D2<SBasis> > rfrac = sectionize(D2<Piecewise<SBasis> >(a_cross_n,v_dot_n));\r
+// //Piecewise<SBasis> h = atan2(rfrac)*interruption_width;\r
+// Piecewise<SBasis> h = reciprocal(curvature(pwd2_in))*interruption_width;\r
+//\r
+// // Piecewise<D2<SBasis> > dir = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(0),Linear(-1)));\r
+// // Piecewise<SBasis> h = dot(n,dir)+1.;\r
+// // h *= h*(interruption_width/4.);\r
+//\r
+// n = rot90(n);\r
+// output = pwd2_in+h*n;\r
+// output.concat(pwd2_in-h*n);\r
+//\r
+// //-----------\r
+\r
+ //output.concat(m);\r
+ return output;\r
+}\r
+*/\r
+\r
+/* ######################## */\r
+\r
+} //namespace LivePathEffect (setq default-directory "c:/Documents And Settings/jf/Mes Documents/InkscapeSVN")\r
+} /* namespace Inkscape */\r
+\r
+/*\r
+ Local Variables:\r
+ mode:c++\r
+ c-file-style:"stroustrup"\r
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+ indent-tabs-mode:nil\r
+ fill-column:99\r
+ End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
diff --git a/src/live_effects/lpe-knot.h b/src/live_effects/lpe-knot.h
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef INKSCAPE_LPE_KNOT_H\r
+#define INKSCAPE_LPE_KNOT_H\r
+\r
+/** \file\r
+ * LPE <knot> implementation, see lpe-knot.cpp.\r
+ */\r
+\r
+/*\r
+ * Authors:\r
+ * JFB, but derived from Johan Engelen!\r
+*\r
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/effect.h"\r
+#include "live_effects/parameter/parameter.h"\r
+#include "live_effects/parameter/point.h"\r
+\r
+namespace Inkscape {\r
+namespace LivePathEffect {\r
+\r
+class LPEKnot : public Effect {\r
+public:\r
+ LPEKnot(LivePathEffectObject *lpeobject);\r
+ virtual ~LPEKnot();\r
+\r
+// Choose to implement one of the doEffect functions. You can delete or comment out the others.\r
+// virtual void doEffect (SPCurve * curve);\r
+// virtual NArtBpath * doEffect_nartbpath (NArtBpath * path_in);\r
+ virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> & path_in);\r
+// virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in);\r
+\r
+private:\r
+ // add the parameters for your effect here:\r
+ ScalarParam interruption_width;\r
+ // there are all kinds of parameters. Check the /live_effects/parameter directory which types exist!\r
+\r
+ LPEKnot(const LPEKnot&);\r
+ LPEKnot& operator=(const LPEKnot&);\r
+};\r
+\r
+} //namespace LivePathEffect\r
+} //namespace Inkscape\r
+\r
+#endif\r
diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp
--- /dev/null
@@ -0,0 +1,347 @@
+#define INKSCAPE_LPE_SKETCH_CPP\r
+/** \file\r
+ * LPE <sketch> implementation\r
+ */\r
+/*\r
+ * Authors:\r
+ * Johan Engelen\r
+*\r
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/lpe-sketch.h"\r
+#include "display/curve.h"\r
+#include <libnr/n-art-bpath.h>\r
+\r
+// You might need to include other 2geom files. You can add them here:\r
+#include <2geom/path.h>\r
+#include <2geom/sbasis.h>\r
+#include <2geom/sbasis-geometric.h>\r
+#include <2geom/bezier-to-sbasis.h>\r
+#include <2geom/sbasis-to-bezier.h>\r
+#include <2geom/d2.h>\r
+#include <2geom/sbasis-math.h>\r
+#include <2geom/piecewise.h>\r
+#include <2geom/crossing.h>\r
+#include <2geom/path-intersection.h>\r
+\r
+namespace Inkscape {\r
+namespace LivePathEffect {\r
+\r
+LPESketch::LPESketch(LivePathEffectObject *lpeobject) :\r
+ Effect(lpeobject),\r
+ // initialise your parameters here:\r
+ //testpointA(_("Test Point A"), _("Test A"), "ptA", &wr, this, Geom::Point(100,100)),\r
+ nbiter_approxstrokes(_("Nb of iterations"), _("Draw that many approximating strokes sequences."), "nbiter_approxstrokes", &wr, this, 5),\r
+ strokelength(_("Max stroke length"), _("Maximal length of approximated strokes."), "strokelength", &wr, this, 100.),\r
+ strokelength_rdm(_("Randomness"), _("Random variation of stroke length (relative to max. length)."), "strokelength_rdm", &wr, this, .3),\r
+ strokeoverlap(_("Max. overlap"), _("How much successive strokes should overlap (relative to max. length)."), "strokeoverlap", &wr, this, .3),\r
+ strokeoverlap_rdm(_("Randomness"), _("Random variation of overlap (relative to max. overlap)"), "strokeoverlap_rdm", &wr, this, .3),\r
+ ends_tolerance(_("Max. ends tolerance"), _("Max. distance between original and approximated paths ends (relative to max. length)."), "ends_tolerance", &wr, this, .1),\r
+ parallel_offset(_("Average offset"), _("Average distance to original stroke(try 0.)."), "parallel_offset", &wr, this, 5.),\r
+ tremble_size(_("Max. tremble"), _("Maximal tremble magnitude."), "tremble_size", &wr, this, 5.),\r
+ tremble_frequency(_("Tremble frequency"), _("Typical nb of tremble 'period' in a stroke."), "tremble_frequency", &wr, this, 1.),\r
+ nbtangents(_("Nb of construction Lines"), _("How many construction lines (tangents) to draw?"), "nbtangents", &wr, this, 5),\r
+ tgtscale(_("Scale"), _("Scale factor relating curvature and length of construction lines(try 5*avarage offset) )"), "tgtscale", &wr, this, 10.0),\r
+ tgtlength(_("Max. length"), _("Max. length of construction lines."), "tgtlength", &wr, this, 100.0),\r
+ tgtlength_rdm(_("Randomness"), _("Random variation of construction lines length."), "tgtlength_rdm", &wr, this, .3)\r
+{\r
+ // register all your parameters here, so Inkscape knows which parameters this effect has:\r
+ //Add some comment in the UI: *warning* the precise output of this effect might change in future releases!\r
+ //convert to path if you want to keep exact output unchanged in future releases...\r
+ //registerParameter( dynamic_cast<Parameter *>(&testpointA) );\r
+ registerParameter( dynamic_cast<Parameter *>(&nbiter_approxstrokes) );\r
+ registerParameter( dynamic_cast<Parameter *>(&strokelength) );\r
+ registerParameter( dynamic_cast<Parameter *>(&strokelength_rdm) );\r
+ registerParameter( dynamic_cast<Parameter *>(&strokeoverlap) );\r
+ registerParameter( dynamic_cast<Parameter *>(&strokeoverlap_rdm) );\r
+ registerParameter( dynamic_cast<Parameter *>(&ends_tolerance) );\r
+ registerParameter( dynamic_cast<Parameter *>(¶llel_offset) );\r
+ registerParameter( dynamic_cast<Parameter *>(&tremble_size) );\r
+ registerParameter( dynamic_cast<Parameter *>(&tremble_frequency) );\r
+ registerParameter( dynamic_cast<Parameter *>(&nbtangents) );\r
+ registerParameter( dynamic_cast<Parameter *>(&tgtscale) );\r
+ registerParameter( dynamic_cast<Parameter *>(&tgtlength) );\r
+ registerParameter( dynamic_cast<Parameter *>(&tgtlength_rdm) );\r
+\r
+\r
+ nbiter_approxstrokes.param_make_integer();\r
+ nbiter_approxstrokes.param_set_range(0, NR_HUGE);\r
+ strokelength.param_set_range(1, NR_HUGE);\r
+ strokelength.param_set_increments(1., 5.);\r
+ strokelength_rdm.param_set_range(0, 1.);\r
+ strokeoverlap.param_set_range(0, 1.);\r
+ strokeoverlap.param_set_increments(0.1, 0.30);\r
+ ends_tolerance.param_set_range(0., 1.);\r
+ parallel_offset.param_set_range(0, NR_HUGE);\r
+ tremble_frequency.param_set_range(0.01, 100.);\r
+ tremble_frequency.param_set_increments(.5, 1.5);\r
+ strokeoverlap_rdm.param_set_range(0, 1.);\r
+\r
+ nbtangents.param_make_integer();\r
+ nbtangents.param_set_range(0, NR_HUGE);\r
+ tgtscale.param_set_range(0, NR_HUGE);\r
+ tgtscale.param_set_increments(.1, .5);\r
+ tgtlength.param_set_range(0, NR_HUGE);\r
+ tgtlength.param_set_increments(1., 5.);\r
+ tgtlength_rdm.param_set_range(0, 1.);\r
+}\r
+\r
+LPESketch::~LPESketch()\r
+{\r
+\r
+}\r
+\r
+/*\r
+Geom::Piecewise<Geom::D2<Geom::SBasis> >\r
+addLinearEnds (Geom::Piecewise<Geom::D2<Geom::SBasis> > & m){\r
+ using namespace Geom;\r
+ Piecewise<D2<SBasis> > output;\r
+ Piecewise<D2<SBasis> > start;\r
+ Piecewise<D2<SBasis> > end;\r
+ double x,y,vx,vy;\r
+\r
+ x = m.segs.front()[0].at0();\r
+ y = m.segs.front()[1].at0();\r
+ vx = m.segs.front()[0][1][0]+Tri(m.segs.front()[0][0]);\r
+ vy = m.segs.front()[1][1][0]+Tri(m.segs.front()[1][0]);\r
+ start = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x-vx,x),Linear (y-vy,y)));\r
+ start.offsetDomain(m.cuts.front()-1.);\r
+\r
+ x = m.segs.back()[0].at1();\r
+ y = m.segs.back()[1].at1();\r
+ vx = -m.segs.back()[0][1][1]+Tri(m.segs.back()[0][0]);;\r
+ vy = -m.segs.back()[1][1][1]+Tri(m.segs.back()[1][0]);;\r
+ end = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x,x+vx),Linear (y,y+vy)));\r
+ //end.offsetDomain(m.cuts.back());\r
+\r
+ output = start;\r
+ output.concat(m);\r
+ output.concat(end);\r
+ return output;\r
+}\r
+*/\r
+\r
+//TODO: does this already exist in 2Geom? if not, move this there...\r
+std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > \r
+split_at_discontinuities (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwsbin, double tol = .0001)\r
+{\r
+ using namespace Geom;\r
+ std::vector<Piecewise<D2<SBasis> > > ret;\r
+ unsigned piece_start = 0;\r
+ for (unsigned i=0; i<pwsbin.segs.size(); i++){\r
+ if (i==(pwsbin.segs.size()-1) || L2(pwsbin.segs[i].at1()- pwsbin.segs[i+1].at0()) > tol){\r
+ Piecewise<D2<SBasis> > piece;\r
+ piece.cuts.push_back(pwsbin.cuts[piece_start]);\r
+ for (unsigned j = piece_start; j<i+1; j++){\r
+ piece.segs.push_back(pwsbin.segs[j]);\r
+ piece.cuts.push_back(pwsbin.cuts[j+1]); \r
+ }\r
+ ret.push_back(piece);\r
+ piece_start = i+1;\r
+ }\r
+ }\r
+ return ret;\r
+}\r
+\r
+//This returns a random perturbation. Notice the domain is [s0,s0+first multiple of period>s1]...\r
+Geom::Piecewise<Geom::D2<Geom::SBasis> > \r
+LPESketch::computePerturbation (double s0, double s1){\r
+ using namespace Geom;\r
+ Piecewise<D2<SBasis> >res;\r
+ \r
+ //global offset for this stroke.\r
+ double offsetX = parallel_offset-parallel_offset.get_value();\r
+ double offsetY = parallel_offset-parallel_offset.get_value();\r
+ Point A,dA,B,dB,offset = Point(offsetX,offsetY);\r
+ //start point A\r
+ for (unsigned dim=0; dim<2; dim++){\r
+ A[dim] = offset[dim] + 2*tremble_size-tremble_size.get_value();\r
+ dA[dim] = 2*tremble_size-tremble_size.get_value();\r
+ }\r
+ //compute howmany deg 3 sbasis to concat according to frequency.\r
+ unsigned count = unsigned((s1-s0)/strokelength*tremble_frequency)+1; \r
+ for (unsigned i=0; i<count; i++){\r
+ D2<SBasis> perturb = D2<SBasis>();\r
+ for (unsigned dim=0; dim<2; dim++){\r
+ B[dim] = offset[dim] + 2*tremble_size-tremble_size.get_value();\r
+ perturb[dim].push_back(Linear(A[dim],B[dim]));\r
+ dA[dim] = dA[dim]-B[dim]+A[dim];\r
+ dB[dim] = 2*tremble_size-tremble_size.get_value();\r
+ perturb[dim].push_back(Linear(dA[dim],dB[dim]));\r
+ }\r
+ A = B;\r
+ dA = B-A-dB;\r
+ res.concat(Piecewise<D2<SBasis> >(perturb));\r
+ }\r
+ res.setDomain(Interval(s0,s0+count*strokelength/tremble_frequency));\r
+ return res;\r
+}\r
+\r
+\r
+// Main effect body...\r
+Geom::Piecewise<Geom::D2<Geom::SBasis> >\r
+LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)\r
+{\r
+ using namespace Geom;\r
+ Piecewise<D2<SBasis> > output;\r
+\r
+\r
+ //init random parameters.\r
+ parallel_offset.resetRandomizer();\r
+ strokelength_rdm.resetRandomizer();\r
+ strokeoverlap_rdm.resetRandomizer();\r
+ tgtlength_rdm.resetRandomizer();\r
+\r
+ // some variables for futur use.\r
+ // notations will be : t = path time, s = distance from start along the path.\r
+ Piecewise<SBasis> pathlength;\r
+ std::vector<double> times; \r
+ double total_length;\r
+\r
+ //TODO: split Construction Lines/Approximated Strokes into two separate effects?\r
+\r
+ //----- Approximated Strokes.\r
+ //TODO: choose length & offset according to curvature?\r
+ \r
+ //TODO: retrieve components from path, dont merge to separate afterward! + know if closed!\r
+ std::vector<Piecewise<D2<SBasis> > > pieces_in = split_at_discontinuities (pwd2_in);\r
+\r
+ //work separately on each component.\r
+ for (unsigned pieceidx = 0; pieceidx < pieces_in.size(); pieceidx++){\r
+\r
+ Piecewise<D2<SBasis> > piece = pieces_in[pieceidx];\r
+ Piecewise<SBasis> piecelength = arcLengthSb(piece,.1);\r
+ pathlength.concat(piecelength);\r
+ \r
+ total_length = piecelength.segs.back().at1()-piecelength.segs.front().at0();\r
+\r
+ //TODO: better check this on the Geom::Path.\r
+ bool closed = piece.segs.front().at0() == piece.segs.back().at1(); \r
+ if (closed){ \r
+ piece.concat(piece);\r
+ piecelength.concat(piecelength+total_length);\r
+ }\r
+\r
+ for (unsigned i = 0; i<nbiter_approxstrokes; i++){\r
+ //Basic steps: \r
+ //- Choose a rdm seg [s0,s1], find coresponding [t0,t1], \r
+ //- Pick a rdm perturbation delta(s), collect 'piece(t)+delta(s(t))' over [t0,t1] into output.\r
+\r
+ // pick a point where to start the stroke (s0 = dist from start).\r
+ double s1=0.,s0 = ends_tolerance*strokelength+0.0001;//the root finder might miss 0. \r
+ double t1, t0;\r
+ double s0_initial = s0;\r
+ bool done = false;// was the end of the component reached?\r
+\r
+ while (!done){\r
+ // if the start point is already too far... do nothing. (this should not happen!)\r
+ assert (s0>=0);//this should not happen!!\r
+ if (!closed && s1>total_length - ends_tolerance.get_value()*strokelength) break;\r
+ if ( closed && s0>total_length + s0_initial) break;\r
+\r
+ times = roots(piecelength-s0); \r
+ if (times.size()==0) break;//we should not be there.\r
+ t0 = times[0];\r
+ \r
+ // pick a new end point (s1 = s0 + strokelength).\r
+ s1 = s0 + strokelength*(1-strokelength_rdm);\r
+ // don't let it go beyond the end of the orgiginal path.\r
+ // TODO/FIXME: this might result in short strokes near the end...\r
+ if (!closed && s1>total_length-ends_tolerance.get_value()*strokelength){\r
+ done = true;\r
+ //!!the root solver might miss s1==total_length...\r
+ if (s1>total_length){s1 = total_length - ends_tolerance*strokelength-0.0001;}\r
+ }\r
+ if (closed && s1>total_length + s0_initial){\r
+ done = true;\r
+ if (closed && s1>2*total_length){s1 = 2*total_length - strokeoverlap*(1-strokeoverlap_rdm)*strokelength-0.0001;}\r
+ }\r
+ times = roots(piecelength-s1); \r
+ if (times.size()==0) break;//we should not be there.\r
+ t1 = times[0];\r
+ \r
+ //pick a rdm perturbation, and collect the perturbed piece into output.\r
+ Piecewise<D2<SBasis> > pwperturb = computePerturbation(s0,s1);\r
+ pwperturb = compose(pwperturb,portion(piecelength,t0,t1));\r
+ output.concat(portion(piece,t0,t1)+pwperturb);\r
+ \r
+ //step points: s0 = s1 - overlap.\r
+ //TODO: make sure this has to end?\r
+ s0 = s1 - strokeoverlap*(1-strokeoverlap_rdm)*strokelength;\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ //----- Construction lines.\r
+ //TODO: choose places according to curvature?.\r
+\r
+ //at this point we have:\r
+ //pathlength = arcLengthSb(pwd2_in,.1);\r
+ total_length = pathlength.segs.back().at1();\r
+ Piecewise<D2<SBasis> > m = pwd2_in;\r
+ Piecewise<D2<SBasis> > v = derivative(pwd2_in);\r
+ Piecewise<D2<SBasis> > a = derivative(v);\r
+ for (unsigned i=0; i<nbtangents; i++){\r
+ // pick a point where to draw a tangent (s = dist from start along path).\r
+ double s = total_length * ( i + tgtlength_rdm ) / (nbtangents+1.);\r
+ times = roots(pathlength-s);\r
+ assert(times.size()>0);//there should be one and only one solution!\r
+ double t = times[0];\r
+ Point m_t = m(t), v_t = v(t), a_t = a(t);\r
+ //Compute tgt length according to curvature (not exceeding tgtlength) so that \r
+ // dist to origninal curve ~ 4 * (parallel_offset+tremble_size).\r
+ //TODO: put this 4 as a parameter in the UI...\r
+ //TODO: what if with v=0?\r
+ double l = tgtlength*(1-tgtlength_rdm)/v_t.length();\r
+ double r = pow(v_t.length(),3)/cross(a_t,v_t);\r
+ r = sqrt((2*fabs(r)-tgtscale)*tgtscale)/v_t.length();\r
+ l=(r<l)?r:l;\r
+ //collect the tgt segment into output.\r
+ D2<SBasis> tgt = D2<SBasis>();\r
+ for (unsigned dim=0; dim<2; dim++){\r
+ tgt[dim] = SBasis(Linear(m_t[dim]-v_t[dim]*l, m_t[dim]+v_t[dim]*l));\r
+ }\r
+ output.concat(Piecewise<D2<SBasis> >(tgt));\r
+ }\r
+\r
+// // -------- Pleins et delies vs courbure ou direction...\r
+// Piecewise<D2<SBasis> > a = derivative(v);\r
+// Piecewise<SBasis> a_cross_n = cross(a,n);\r
+// Piecewise<SBasis> v_dot_n = dot(v,n);\r
+// //Piecewise<D2<SBasis> > rfrac = sectionize(D2<Piecewise<SBasis> >(a_cross_n,v_dot_n));\r
+// //Piecewise<SBasis> h = atan2(rfrac)*para1;\r
+// Piecewise<SBasis> h = reciprocal(curvature(piece))*para1;\r
+//\r
+// // Piecewise<D2<SBasis> > dir = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(0),Linear(-1)));\r
+// // Piecewise<SBasis> h = dot(n,dir)+1.;\r
+// // h *= h*(para1/4.);\r
+//\r
+// n = rot90(n);\r
+// output = piece+h*n;\r
+// output.concat(piece-h*n);\r
+//\r
+// //-----------\r
+\r
+ //output.concat(m);\r
+ return output;\r
+}\r
+\r
+/* ######################## */\r
+\r
+} //namespace LivePathEffect (setq default-directory "c:/Documents And Settings/jf/Mes Documents/InkscapeSVN")\r
+} /* namespace Inkscape */\r
+\r
+/*\r
+ Local Variables:\r
+ mode:c++\r
+ c-file-style:"stroustrup"\r
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+ indent-tabs-mode:nil\r
+ fill-column:99\r
+ End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
diff --git a/src/live_effects/lpe-sketch.h b/src/live_effects/lpe-sketch.h
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef INKSCAPE_LPE_SKETCH_H\r
+#define INKSCAPE_LPE_SKETCH_H\r
+\r
+/** \file\r
+ * LPE <sketch> implementation, see lpe-sketch.cpp.\r
+ */\r
+\r
+/*\r
+ * Authors:\r
+ * JFB, but derived from Johan Engelen!\r
+*\r
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/effect.h"\r
+#include "live_effects/parameter/parameter.h"\r
+#include "live_effects/parameter/random.h"\r
+#include "live_effects/parameter/point.h"\r
+\r
+namespace Inkscape {\r
+namespace LivePathEffect {\r
+\r
+class LPESketch : public Effect {\r
+public:\r
+ LPESketch(LivePathEffectObject *lpeobject);\r
+ virtual ~LPESketch();\r
+\r
+// Choose to implement one of the doEffect functions. You can delete or comment out the others.\r
+// virtual void doEffect (SPCurve * curve);\r
+// virtual NArtBpath * doEffect_nartbpath (NArtBpath * path_in);\r
+// virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> & path_in);\r
+ virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in);\r
+\r
+private:\r
+ // add the parameters for your effect here:\r
+ //PointParam testpointA;\r
+ ScalarParam nbiter_approxstrokes;\r
+ ScalarParam strokelength;\r
+ RandomParam strokelength_rdm;\r
+ ScalarParam strokeoverlap;\r
+ RandomParam strokeoverlap_rdm;\r
+ RandomParam ends_tolerance;\r
+ RandomParam parallel_offset;\r
+ RandomParam tremble_size;\r
+ ScalarParam tremble_frequency;\r
+ ScalarParam nbtangents;\r
+ ScalarParam tgtscale;\r
+ ScalarParam tgtlength;\r
+ RandomParam tgtlength_rdm;\r
+\r
+ LPESketch(const LPESketch&);\r
+ LPESketch& operator=(const LPESketch&);\r
+\r
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > computePerturbation (double s0, double s1);\r
+\r
+};\r
+\r
+} //namespace LivePathEffect\r
+} //namespace Inkscape\r
+\r
+#endif\r
diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp
--- /dev/null
@@ -0,0 +1,158 @@
+#define INKSCAPE_LPE_VONKOCH_CPP
+
+/*
+ * 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-vonkoch.h"
+#include "sp-shape.h"
+#include "sp-item.h"
+#include "sp-path.h"
+#include "display/curve.h"
+#include <libnr/n-art-bpath.h>
+#include <libnr/nr-matrix-fns.h>
+#include "live_effects/n-art-bpath-2geom.h"
+#include "svg/svg.h"
+#include "ui/widget/scalar.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/piecewise.h>
+
+#include <algorithm>
+using std::vector;
+
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPEVonKoch::LPEVonKoch(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ generator(_("Generating path"), _("Path whos segments define the fractal"), "generator", &wr, this, "M0,0 L3,0 M0,1 L1,1 M 2,1 L3,1"),
+ nbgenerations(_("Nb of generations"), _("Depth of the recursion --- keep low!!"), "nbgenerations", &wr, this, 1),
+ drawall(_("Draw all generations"), _("If unchecked, draw only the last generation"), "drawall", &wr, this, false),
+ vertical_pattern(_("Original path is vertical"), _("Rotates the original 90 degrees, before generating the fractal"), "vertical", &wr, this, false)
+{
+ registerParameter( dynamic_cast<Parameter *>(&generator) );
+ registerParameter( dynamic_cast<Parameter *>(&nbgenerations) );
+ registerParameter( dynamic_cast<Parameter *>(&drawall) );
+ registerParameter( dynamic_cast<Parameter *>(&vertical_pattern) );
+
+ nbgenerations.param_make_integer();
+ nbgenerations.param_set_range(0, NR_HUGE);
+}
+
+LPEVonKoch::~LPEVonKoch()
+{
+
+}
+
+
+std::vector<Geom::Path>
+LPEVonKoch::doEffect_path (std::vector<Geom::Path> & path_in)
+{
+ using namespace Geom;
+ std::vector<Geom::Path> generating_path = path_from_piecewise(generator,.01);//TODO what should that tolerance be?
+ Point p = generating_path[0].pointAt(0.001);
+ Point u = generating_path[0].pointAt(0.999)-generating_path[0].pointAt(0.001);
+ Matrix m0 = Matrix(u[X], u[Y],-u[Y], u[X], p[X], p[Y]);
+ m0 = m0.inverse();
+
+ std::vector<Matrix> transforms;
+ for (unsigned i=0; i<generating_path.size(); i++){
+ for (unsigned j = (i==0)?1:0; j<generating_path[i].size(); j++){
+ p = generating_path[i].pointAt(j);
+ u = generating_path[i].pointAt(j+0.999)-generating_path[i].pointAt(j+0.001);
+ Matrix m = Matrix(u[X], u[Y],-u[Y], u[X], p[X], p[Y]);
+ m = m0*m;
+ transforms.push_back(m);
+ }
+ }
+/*
+ assert(generating_path.size()>0);
+
+ std::vector<Matrix> transforms;
+ transforms.push_back(Matrix(.5, 0., 0., .5, 0.,50.));
+ transforms.push_back(Matrix(.5, 0., 0., .5, 100., 0.));
+*/
+
+ std::vector<Geom::Path> pathi = path_in;
+ std::vector<Geom::Path> path_out = path_in;
+
+ for (unsigned i = 0; i<nbgenerations; i++){
+ path_out = (drawall.get_value())? path_in : std::vector<Geom::Path>();
+ for (unsigned j = 0; j<transforms.size(); j++){
+ for (unsigned k = 0; k<pathi.size(); k++){
+ path_out.push_back(pathi[k]*transforms[j]);
+ }
+ }
+ pathi = path_out;
+ }
+ return path_out;
+}
+
+void
+LPEVonKoch::resetDefaults(SPItem * item)
+{
+ if (!SP_IS_PATH(item)) return;
+
+ using namespace Geom;
+
+ // set the bend path to run horizontally in the middle of the bounding box of the original path
+ Piecewise<D2<SBasis> > pwd2;
+ std::vector<Geom::Path> temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d"));
+ for (unsigned int i=0; i < temppath.size(); i++) {
+ pwd2.concat( temppath[i].toPwSb() );
+ }
+
+ D2<Piecewise<SBasis> > d2pw = make_cuts_independant(pwd2);
+ Interval bndsX = bounds_exact(d2pw[0]);
+ Interval bndsY = bounds_exact(d2pw[1]);
+ Point start(bndsX.min(), (bndsY.max()+bndsY.min())/2);
+ Point end(bndsX.max(), (bndsY.max()+bndsY.min())/2);
+
+ std::vector<Geom::Path> paths;
+ Geom::Path path;
+ path = Geom::Path();
+ path.start( start );
+ path.appendNew<Geom::LineSegment>( end );
+ paths.push_back(path);
+ paths.push_back(path * Matrix(1./3,0,0,1./3,start[X]*2./3,start[Y]*2./3 + bndsY.extent()/2));
+ paths.push_back(path * Matrix(1./3,0,0,1./3, end[X]*2./3, end[Y]*2./3 + bndsY.extent()/2));
+
+ //generator.param_set_and_write_new_value( path.toPwSb() );
+ generator.param_set_and_write_new_value( paths_to_pw(paths) );
+
+
+// Piecewise<D2<SBasis> > default_gen;
+// default_gen.concat(Piecewise<D2<SBasis> >(D2<SBasis>(Linear(bndsX.min(),bndsX.max()),Linear((bndsY.min()+bndsY.max())/2))));
+// default_gen.concat(Piecewise<D2<SBasis> >(D2<SBasis>(Linear(bndsX.max(),bndsX.max()+bndsX.extent()/2),Linear((bndsY.min()+bndsY.max())/2))));
+// generator.param_set_and_write_new_value( default_gen );
+}
+
+void
+LPEVonKoch::transform_multiply(Geom::Matrix const& postmul, bool set)
+{
+ // TODO: implement correct transformation instead of this default behavior
+ Effect::transform_multiply(postmul, set);
+}
+
+
+} // 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 :
diff --git a/src/live_effects/lpe-vonkoch.h b/src/live_effects/lpe-vonkoch.h
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef INKSCAPE_LPE_VONKOCH_H
+#define INKSCAPE_LPE_VONKOCH_H
+
+/*
+ * Inkscape::LPEVonKoch
+ *
+* 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/effect.h"
+#include "live_effects/parameter/path.h"
+#include "live_effects/parameter/enum.h"
+#include "live_effects/parameter/bool.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPEVonKoch : public Effect {
+public:
+ LPEVonKoch(LivePathEffectObject *lpeobject);
+ virtual ~LPEVonKoch();
+
+ virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> & path_in);
+
+ virtual void resetDefaults(SPItem * item);
+
+ virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
+
+private:
+ ScalarParam nbgenerations;
+ PathParam generator;
+ BoolParam drawall;
+ BoolParam vertical_pattern;
+
+ void on_pattern_pasted();
+
+ LPEVonKoch(const LPEVonKoch&);
+ LPEVonKoch& operator=(const LPEVonKoch&);
+};
+
+}; //namespace LivePathEffect
+}; //namespace Inkscape
+
+#endif