summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dc98acc)
raw | patch | inline | side by side (parent: dc98acc)
| author | joncruz <joncruz@users.sourceforge.net> | |
| Mon, 25 Feb 2008 04:49:39 +0000 (04:49 +0000) | ||
| committer | joncruz <joncruz@users.sourceforge.net> | |
| Mon, 25 Feb 2008 04:49:39 +0000 (04:49 +0000) |
index d639bb42d459601c468b4c09cadfd6aff041eaeb..d7cc55939a3e012cff2c8d03011b8172c5a517e2 100644 (file)
-## Makefile.am fragment sourced by src/Makefile.am.\r
-\r
-live_effects/all: live_effects/liblive_effects.a live_effects/parameter/all\r
-\r
-live_effects/clean:\r
- rm -f live_effects/liblive_effects.a $(live_effects_liblive_effects_a_OBJECTS)\r
-\r
-live_effects_liblive_effects_a_SOURCES = \\r
- live_effects/effect.cpp \\r
- live_effects/effect.h \\r
- live_effects/lpeobject.cpp \\r
- live_effects/lpeobject.h \\r
- live_effects/lpeobject-reference.cpp \\r
- live_effects/lpeobject-reference.h \\r
- live_effects/n-art-bpath-2geom.cpp \\r
- live_effects/n-art-bpath-2geom.h \\r
- live_effects/lpe-skeletalstrokes.cpp \\r
- 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
- live_effects/lpe-gears.h \\r
- live_effects/lpe-test-doEffect-stack.cpp \\r
- live_effects/lpe-test-doEffect-stack.h \\r
- live_effects/lpe-slant.cpp \\r
- live_effects/lpe-slant.h\r
-\r
-\r
-\r
+## Makefile.am fragment sourced by src/Makefile.am.
+
+live_effects/all: live_effects/liblive_effects.a live_effects/parameter/all
+
+live_effects/clean:
+ rm -f live_effects/liblive_effects.a $(live_effects_liblive_effects_a_OBJECTS)
+
+live_effects_liblive_effects_a_SOURCES = \
+ live_effects/effect.cpp \
+ live_effects/effect.h \
+ live_effects/lpeobject.cpp \
+ live_effects/lpeobject.h \
+ live_effects/lpeobject-reference.cpp \
+ live_effects/lpeobject-reference.h \
+ live_effects/n-art-bpath-2geom.cpp \
+ live_effects/n-art-bpath-2geom.h \
+ live_effects/lpe-skeletalstrokes.cpp \
+ live_effects/lpe-skeletalstrokes.h \
+ live_effects/lpe-pathalongpath.cpp \
+ live_effects/lpe-pathalongpath.h \
+ live_effects/lpe-sketch.cpp \
+ live_effects/lpe-sketch.h \
+ live_effects/lpe-knot.cpp \
+ live_effects/lpe-knot.h \
+ live_effects/lpe-vonkoch.cpp \
+ live_effects/lpe-vonkoch.h \
+ live_effects/lpe-curvestitch.cpp \
+ live_effects/lpe-curvestitch.h \
+ live_effects/lpe-gears.cpp \
+ live_effects/lpe-gears.h \
+ live_effects/lpe-test-doEffect-stack.cpp \
+ live_effects/lpe-test-doEffect-stack.h \
+ live_effects/lpe-slant.cpp \
+ live_effects/lpe-slant.h
+
index 3e87bc51bbf03bb03d8548f9f2364e316ae314a5..2590cda82959f328c05ec58debcca914c4d9df7a 100644 (file)
-#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
+#define INKSCAPE_LPE_KNOT_CPP
+/** \file
+ * LPE <knot> implementation
+ */
+/*
+ * 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-knot.h"
+#include "display/curve.h"
+#include <libnr/n-art-bpath.h>
+
+// You might need to include other 2geom files. You can add them here:
+#include <2geom/path.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/sbasis-math.h>
+#include <2geom/piecewise.h>
+#include <2geom/crossing.h>
+#include <2geom/path-intersection.h>
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ // initialise your parameters here:
+ interruption_width(_("Interruption width"), _("Howmuch the lower strand is obscured by the upper."), "interruption_width", &wr, this, 1.2)
+{
+ // register all your parameters here, so Inkscape knows which parameters this effect has:
+ registerParameter( dynamic_cast<Parameter *>(&interruption_width) );
+}
+
+LPEKnot::~LPEKnot()
+{
+
+}
+
+
+/* ########################
+ * Choose to implement one of the doEffect functions. You can delete or comment out the others.
+*/
+
+/*
+void
+LPEKnot::doEffect (SPCurve * curve)
+{
+ // spice this up to make the effect actually *do* something!
+}
+
+NArtBpath *
+LPEKnot::doEffect_nartbpath (NArtBpath * path_in)
+{
+ NArtBpath *path_out;
+ unsigned ret = 0;
+ while ( path_in[ret].code != NR_END ) {
+ ++ret;
+ }
+ unsigned len = ++ret;
+ path_out = g_new(NArtBpath, len);
+
+ memcpy(path_out, path_in, len * sizeof(NArtBpath)); // spice this up to make the effect actually *do* something!
+
+ return path_out;
+}
+*/
+
+std::vector<Geom::Interval> complementOf(Geom::Interval I, std::vector<Geom::Interval> domain){
+ std::vector<Geom::Interval> ret;
+ double min = domain.front().min();
+ double max = domain.back().max();
+ Geom::Interval I1 = Geom::Interval(min,I.min());
+ Geom::Interval I2 = Geom::Interval(I.max(),max);
+
+ for (unsigned i = 0; i<domain.size(); i++){
+ boost::optional<Geom::Interval> I1i = intersect(domain.at(i),I1);
+ if (I1i) ret.push_back(I1i.get());
+ boost::optional<Geom::Interval> I2i = intersect(domain.at(i),I2);
+ if (I2i) ret.push_back(I2i.get());
+ }
+ return ret;
+}
+
+Geom::Interval
+findShadowedTime(Geom::Path &patha,
+ Geom::Path &pathb,
+ Geom::Crossing crossing,
+ unsigned idx, double width){
+ using namespace Geom;
+ double curveidx, timeoncurve = modf(crossing.getOtherTime(idx),&curveidx);
+ if(curveidx == pathb.size() && timeoncurve == 0) { curveidx--; timeoncurve = 0.99999;}
+ assert(curveidx >= 0 && curveidx < pathb.size());
+
+ std::vector<Point> MV = pathb[unsigned(curveidx)].pointAndDerivatives(timeoncurve,2);
+ Point T = unit_vector(MV.at(1));
+ Point N = T.cw();
+ Point A = MV.at(0)-10*width*T, B = MV.at(0)+10*width*T;
+
+ std::vector<Geom::Path> cutter;
+ Geom::Path cutterLeft = Geom::Path();
+ Geom::Path cutterRight = Geom::Path();
+ cutterLeft.append (LineSegment (A-width*N, B-width*N));
+ cutterRight.append(LineSegment (A+width*N, B+width*N));
+ cutter.push_back(cutterLeft);
+ cutter.push_back(cutterRight);
+
+ std::vector<Geom::Path> patha_as_vect = std::vector<Geom::Path>(1,patha);
+
+ CrossingSet crossingTable = crossings (patha_as_vect, cutter);
+ double t0 = crossing.getTime(idx);
+ double tmin = 0,tmax = patha.size()-0.0001;
+ assert(crossingTable.size()>=1);
+ for (unsigned c=0; c<crossingTable.front().size(); c++){
+ double t = crossingTable.front().at(c).ta;
+ assert(crossingTable.front().at(c).a==0);
+ if (t>tmin and t<t0) tmin = t;
+ if (t<tmax and t>t0) tmax = t;
+ }
+ //return Interval(t0-0.1,t0+0.1);
+ return Interval(tmin,tmax);
+}
+
+
+std::vector<Geom::Path>
+LPEKnot::doEffect_path (std::vector<Geom::Path> & path_in)
+{
+ using namespace Geom;
+ std::vector<Geom::Path> path_out;
+ double width = interruption_width;
+
+ CrossingSet crossingTable = crossings_among(path_in);
+ for (unsigned i = 0; i < crossingTable.size(); i++){
+ std::vector<Interval> dom;
+ dom.push_back(Interval(0.,path_in.at(i).size()-0.00001));
+ //TODO: handle closed curves...
+ for (unsigned crs = 0; crs < crossingTable.at(i).size(); crs++){
+ Crossing crossing = crossingTable.at(i).at(crs);
+ unsigned j = crossing.getOther(i);
+ //TODO: select dir according to a parameter...
+ if ((crossing.dir and crossing.a==i) or (not crossing.dir and crossing.b==i) or (i==j)){
+ if (i==j and not crossing.dir) {
+ double temp = crossing.ta;
+ crossing.ta = crossing.tb;
+ crossing.tb = temp;
+ crossing.dir = not crossing.dir;
+ }
+ Interval hidden = findShadowedTime(path_in.at(i),path_in.at(j),crossing,i,width);
+ dom = complementOf(hidden,dom);
+ }
+ }
+ for (unsigned comp = 0; comp < dom.size(); comp++){
+ assert(dom.at(comp).min() >=0 and dom.at(comp).max() < path_in.at(i).size());
+ path_out.push_back(path_in.at(i).portion(dom.at(comp)));
+ }
+
+// std::vector<Point> MV = path_in[0][0].pointAndDerivatives(crossingTable[0][0].getTime(0),2);
+// Point U = unit_vector(MV[1]);
+// Point N = U.cw();
+// Point A = MV[0]-10.*width*U, B = MV[0]+10*width*U;
+
+// Geom::Path cutter;
+// cutter = Geom::Path();
+// cutter.append( LineSegment(A+width*N,B+width*N));
+// path_out.push_back(cutter);
+// cutter = Geom::Path();
+// cutter.append( LineSegment(A-width*N,B-width*N));
+// path_out.push_back(cutter);
+
+ }
+ return path_out;
+}
+
+
+/*
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+addLinearEnds (Geom::Piecewise<Geom::D2<Geom::SBasis> > & m){
+ using namespace Geom;
+ Piecewise<D2<SBasis> > output;
+ Piecewise<D2<SBasis> > start;
+ Piecewise<D2<SBasis> > end;
+ double x,y,vx,vy;
+
+ x = m.segs.front()[0].at0();
+ y = m.segs.front()[1].at0();
+ vx = m.segs.front()[0][1][0]+Tri(m.segs.front()[0][0]);
+ vy = m.segs.front()[1][1][0]+Tri(m.segs.front()[1][0]);
+ start = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x-vx,x),Linear (y-vy,y)));
+ start.offsetDomain(m.cuts.front()-1.);
+
+ x = m.segs.back()[0].at1();
+ y = m.segs.back()[1].at1();
+ vx = -m.segs.back()[0][1][1]+Tri(m.segs.back()[0][0]);;
+ vy = -m.segs.back()[1][1][1]+Tri(m.segs.back()[1][0]);;
+ end = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x,x+vx),Linear (y,y+vy)));
+ //end.offsetDomain(m.cuts.back());
+
+ output = start;
+ output.concat(m);
+ output.concat(end);
+ return output;
+}
+
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPEKnot::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
+{
+ using namespace Geom;
+
+
+ Piecewise<D2<SBasis> > output;
+ Piecewise<D2<SBasis> > m = addLinearEnds(pwd2_in);
+
+ Piecewise<D2<SBasis> > v = derivative(pwd2_in);
+ Piecewise<D2<SBasis> > n = unitVector(v);
+
+// // -------- Pleins et delies vs courbure ou direction...
+// Piecewise<D2<SBasis> > a = derivative(v);
+// Piecewise<SBasis> a_cross_n = cross(a,n);
+// Piecewise<SBasis> v_dot_n = dot(v,n);
+// //Piecewise<D2<SBasis> > rfrac = sectionize(D2<Piecewise<SBasis> >(a_cross_n,v_dot_n));
+// //Piecewise<SBasis> h = atan2(rfrac)*interruption_width;
+// Piecewise<SBasis> h = reciprocal(curvature(pwd2_in))*interruption_width;
+//
+// // Piecewise<D2<SBasis> > dir = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(0),Linear(-1)));
+// // Piecewise<SBasis> h = dot(n,dir)+1.;
+// // h *= h*(interruption_width/4.);
+//
+// n = rot90(n);
+// output = pwd2_in+h*n;
+// output.concat(pwd2_in-h*n);
+//
+// //-----------
+
+ //output.concat(m);
+ return output;
+}
+*/
+
+/* ######################## */
+
+} //namespace LivePathEffect (setq default-directory "c:/Documents And Settings/jf/Mes Documents/InkscapeSVN")
+} /* 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 :
index 589413285f6614839accdd9ff56c626196cf3e0c..f456ab2ce516d9c17fd544c611f7960372c70c6d 100644 (file)
-#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
+#ifndef INKSCAPE_LPE_KNOT_H
+#define INKSCAPE_LPE_KNOT_H
+
+/** \file
+ * LPE <knot> implementation, see lpe-knot.cpp.
+ */
+
+/*
+ * Authors:
+ * JFB, but derived from 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/effect.h"
+#include "live_effects/parameter/parameter.h"
+#include "live_effects/parameter/point.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPEKnot : public Effect {
+public:
+ LPEKnot(LivePathEffectObject *lpeobject);
+ virtual ~LPEKnot();
+
+// Choose to implement one of the doEffect functions. You can delete or comment out the others.
+// virtual void doEffect (SPCurve * curve);
+// virtual NArtBpath * doEffect_nartbpath (NArtBpath * path_in);
+ virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> & path_in);
+// virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in);
+
+private:
+ // add the parameters for your effect here:
+ ScalarParam interruption_width;
+ // there are all kinds of parameters. Check the /live_effects/parameter directory which types exist!
+
+ LPEKnot(const LPEKnot&);
+ LPEKnot& operator=(const LPEKnot&);
+};
+
+} //namespace LivePathEffect
+} //namespace Inkscape
+
+#endif
index 9b49122fe3b4b322abd3fcaf87b2e05fc92dd00a..d7333033a5dbc0b56055c226bd013c6d289e2c44 100644 (file)
-#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
+#define INKSCAPE_LPE_SKETCH_CPP
+/** \file
+ * LPE <sketch> implementation
+ */
+/*
+ * 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-sketch.h"
+#include "display/curve.h"
+#include <libnr/n-art-bpath.h>
+
+// You might need to include other 2geom files. You can add them here:
+#include <2geom/path.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/sbasis-math.h>
+#include <2geom/piecewise.h>
+#include <2geom/crossing.h>
+#include <2geom/path-intersection.h>
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPESketch::LPESketch(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ // initialise your parameters here:
+ //testpointA(_("Test Point A"), _("Test A"), "ptA", &wr, this, Geom::Point(100,100)),
+ nbiter_approxstrokes(_("Nb of iterations"), _("Draw that many approximating strokes sequences."), "nbiter_approxstrokes", &wr, this, 5),
+ strokelength(_("Max stroke length"), _("Maximal length of approximated strokes."), "strokelength", &wr, this, 100.),
+ strokelength_rdm(_("Randomness"), _("Random variation of stroke length (relative to max. length)."), "strokelength_rdm", &wr, this, .3),
+ strokeoverlap(_("Max. overlap"), _("How much successive strokes should overlap (relative to max. length)."), "strokeoverlap", &wr, this, .3),
+ strokeoverlap_rdm(_("Randomness"), _("Random variation of overlap (relative to max. overlap)"), "strokeoverlap_rdm", &wr, this, .3),
+ ends_tolerance(_("Max. ends tolerance"), _("Max. distance between original and approximated paths ends (relative to max. length)."), "ends_tolerance", &wr, this, .1),
+ parallel_offset(_("Average offset"), _("Average distance to original stroke(try 0.)."), "parallel_offset", &wr, this, 5.),
+ tremble_size(_("Max. tremble"), _("Maximal tremble magnitude."), "tremble_size", &wr, this, 5.),
+ tremble_frequency(_("Tremble frequency"), _("Typical nb of tremble 'period' in a stroke."), "tremble_frequency", &wr, this, 1.),
+ nbtangents(_("Nb of construction Lines"), _("How many construction lines (tangents) to draw?"), "nbtangents", &wr, this, 5),
+ tgtscale(_("Scale"), _("Scale factor relating curvature and length of construction lines(try 5*avarage offset) )"), "tgtscale", &wr, this, 10.0),
+ tgtlength(_("Max. length"), _("Max. length of construction lines."), "tgtlength", &wr, this, 100.0),
+ tgtlength_rdm(_("Randomness"), _("Random variation of construction lines length."), "tgtlength_rdm", &wr, this, .3)
+{
+ // register all your parameters here, so Inkscape knows which parameters this effect has:
+ //Add some comment in the UI: *warning* the precise output of this effect might change in future releases!
+ //convert to path if you want to keep exact output unchanged in future releases...
+ //registerParameter( dynamic_cast<Parameter *>(&testpointA) );
+ registerParameter( dynamic_cast<Parameter *>(&nbiter_approxstrokes) );
+ registerParameter( dynamic_cast<Parameter *>(&strokelength) );
+ registerParameter( dynamic_cast<Parameter *>(&strokelength_rdm) );
+ registerParameter( dynamic_cast<Parameter *>(&strokeoverlap) );
+ registerParameter( dynamic_cast<Parameter *>(&strokeoverlap_rdm) );
+ registerParameter( dynamic_cast<Parameter *>(&ends_tolerance) );
+ registerParameter( dynamic_cast<Parameter *>(¶llel_offset) );
+ registerParameter( dynamic_cast<Parameter *>(&tremble_size) );
+ registerParameter( dynamic_cast<Parameter *>(&tremble_frequency) );
+ registerParameter( dynamic_cast<Parameter *>(&nbtangents) );
+ registerParameter( dynamic_cast<Parameter *>(&tgtscale) );
+ registerParameter( dynamic_cast<Parameter *>(&tgtlength) );
+ registerParameter( dynamic_cast<Parameter *>(&tgtlength_rdm) );
+
+
+ nbiter_approxstrokes.param_make_integer();
+ nbiter_approxstrokes.param_set_range(0, NR_HUGE);
+ strokelength.param_set_range(1, NR_HUGE);
+ strokelength.param_set_increments(1., 5.);
+ strokelength_rdm.param_set_range(0, 1.);
+ strokeoverlap.param_set_range(0, 1.);
+ strokeoverlap.param_set_increments(0.1, 0.30);
+ ends_tolerance.param_set_range(0., 1.);
+ parallel_offset.param_set_range(0, NR_HUGE);
+ tremble_frequency.param_set_range(0.01, 100.);
+ tremble_frequency.param_set_increments(.5, 1.5);
+ strokeoverlap_rdm.param_set_range(0, 1.);
+
+ nbtangents.param_make_integer();
+ nbtangents.param_set_range(0, NR_HUGE);
+ tgtscale.param_set_range(0, NR_HUGE);
+ tgtscale.param_set_increments(.1, .5);
+ tgtlength.param_set_range(0, NR_HUGE);
+ tgtlength.param_set_increments(1., 5.);
+ tgtlength_rdm.param_set_range(0, 1.);
+}
+
+LPESketch::~LPESketch()
+{
+
+}
+
+/*
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+addLinearEnds (Geom::Piecewise<Geom::D2<Geom::SBasis> > & m){
+ using namespace Geom;
+ Piecewise<D2<SBasis> > output;
+ Piecewise<D2<SBasis> > start;
+ Piecewise<D2<SBasis> > end;
+ double x,y,vx,vy;
+
+ x = m.segs.front()[0].at0();
+ y = m.segs.front()[1].at0();
+ vx = m.segs.front()[0][1][0]+Tri(m.segs.front()[0][0]);
+ vy = m.segs.front()[1][1][0]+Tri(m.segs.front()[1][0]);
+ start = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x-vx,x),Linear (y-vy,y)));
+ start.offsetDomain(m.cuts.front()-1.);
+
+ x = m.segs.back()[0].at1();
+ y = m.segs.back()[1].at1();
+ vx = -m.segs.back()[0][1][1]+Tri(m.segs.back()[0][0]);;
+ vy = -m.segs.back()[1][1][1]+Tri(m.segs.back()[1][0]);;
+ end = Piecewise<D2<SBasis> >(D2<SBasis>(Linear (x,x+vx),Linear (y,y+vy)));
+ //end.offsetDomain(m.cuts.back());
+
+ output = start;
+ output.concat(m);
+ output.concat(end);
+ return output;
+}
+*/
+
+//TODO: does this already exist in 2Geom? if not, move this there...
+std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > >
+split_at_discontinuities (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwsbin, double tol = .0001)
+{
+ using namespace Geom;
+ std::vector<Piecewise<D2<SBasis> > > ret;
+ unsigned piece_start = 0;
+ for (unsigned i=0; i<pwsbin.segs.size(); i++){
+ if (i==(pwsbin.segs.size()-1) || L2(pwsbin.segs[i].at1()- pwsbin.segs[i+1].at0()) > tol){
+ Piecewise<D2<SBasis> > piece;
+ piece.cuts.push_back(pwsbin.cuts[piece_start]);
+ for (unsigned j = piece_start; j<i+1; j++){
+ piece.segs.push_back(pwsbin.segs[j]);
+ piece.cuts.push_back(pwsbin.cuts[j+1]);
+ }
+ ret.push_back(piece);
+ piece_start = i+1;
+ }
+ }
+ return ret;
+}
+
+//This returns a random perturbation. Notice the domain is [s0,s0+first multiple of period>s1]...
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPESketch::computePerturbation (double s0, double s1){
+ using namespace Geom;
+ Piecewise<D2<SBasis> >res;
+
+ //global offset for this stroke.
+ double offsetX = parallel_offset-parallel_offset.get_value();
+ double offsetY = parallel_offset-parallel_offset.get_value();
+ Point A,dA,B,dB,offset = Point(offsetX,offsetY);
+ //start point A
+ for (unsigned dim=0; dim<2; dim++){
+ A[dim] = offset[dim] + 2*tremble_size-tremble_size.get_value();
+ dA[dim] = 2*tremble_size-tremble_size.get_value();
+ }
+ //compute howmany deg 3 sbasis to concat according to frequency.
+ unsigned count = unsigned((s1-s0)/strokelength*tremble_frequency)+1;
+ for (unsigned i=0; i<count; i++){
+ D2<SBasis> perturb = D2<SBasis>();
+ for (unsigned dim=0; dim<2; dim++){
+ B[dim] = offset[dim] + 2*tremble_size-tremble_size.get_value();
+ perturb[dim].push_back(Linear(A[dim],B[dim]));
+ dA[dim] = dA[dim]-B[dim]+A[dim];
+ dB[dim] = 2*tremble_size-tremble_size.get_value();
+ perturb[dim].push_back(Linear(dA[dim],dB[dim]));
+ }
+ A = B;
+ dA = B-A-dB;
+ res.concat(Piecewise<D2<SBasis> >(perturb));
+ }
+ res.setDomain(Interval(s0,s0+count*strokelength/tremble_frequency));
+ return res;
+}
+
+
+// Main effect body...
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
+{
+ using namespace Geom;
+ Piecewise<D2<SBasis> > output;
+
+
+ //init random parameters.
+ parallel_offset.resetRandomizer();
+ strokelength_rdm.resetRandomizer();
+ strokeoverlap_rdm.resetRandomizer();
+ tgtlength_rdm.resetRandomizer();
+
+ // some variables for futur use.
+ // notations will be : t = path time, s = distance from start along the path.
+ Piecewise<SBasis> pathlength;
+ std::vector<double> times;
+ double total_length;
+
+ //TODO: split Construction Lines/Approximated Strokes into two separate effects?
+
+ //----- Approximated Strokes.
+ //TODO: choose length & offset according to curvature?
+
+ //TODO: retrieve components from path, dont merge to separate afterward! + know if closed!
+ std::vector<Piecewise<D2<SBasis> > > pieces_in = split_at_discontinuities (pwd2_in);
+
+ //work separately on each component.
+ for (unsigned pieceidx = 0; pieceidx < pieces_in.size(); pieceidx++){
+
+ Piecewise<D2<SBasis> > piece = pieces_in[pieceidx];
+ Piecewise<SBasis> piecelength = arcLengthSb(piece,.1);
+ pathlength.concat(piecelength);
+
+ total_length = piecelength.segs.back().at1()-piecelength.segs.front().at0();
+
+ //TODO: better check this on the Geom::Path.
+ bool closed = piece.segs.front().at0() == piece.segs.back().at1();
+ if (closed){
+ piece.concat(piece);
+ piecelength.concat(piecelength+total_length);
+ }
+
+ for (unsigned i = 0; i<nbiter_approxstrokes; i++){
+ //Basic steps:
+ //- Choose a rdm seg [s0,s1], find coresponding [t0,t1],
+ //- Pick a rdm perturbation delta(s), collect 'piece(t)+delta(s(t))' over [t0,t1] into output.
+
+ // pick a point where to start the stroke (s0 = dist from start).
+ double s1=0.,s0 = ends_tolerance*strokelength+0.0001;//the root finder might miss 0.
+ double t1, t0;
+ double s0_initial = s0;
+ bool done = false;// was the end of the component reached?
+
+ while (!done){
+ // if the start point is already too far... do nothing. (this should not happen!)
+ assert (s0>=0);//this should not happen!!
+ if (!closed && s1>total_length - ends_tolerance.get_value()*strokelength) break;
+ if ( closed && s0>total_length + s0_initial) break;
+
+ times = roots(piecelength-s0);
+ if (times.size()==0) break;//we should not be there.
+ t0 = times[0];
+
+ // pick a new end point (s1 = s0 + strokelength).
+ s1 = s0 + strokelength*(1-strokelength_rdm);
+ // don't let it go beyond the end of the orgiginal path.
+ // TODO/FIXME: this might result in short strokes near the end...
+ if (!closed && s1>total_length-ends_tolerance.get_value()*strokelength){
+ done = true;
+ //!!the root solver might miss s1==total_length...
+ if (s1>total_length){s1 = total_length - ends_tolerance*strokelength-0.0001;}
+ }
+ if (closed && s1>total_length + s0_initial){
+ done = true;
+ if (closed && s1>2*total_length){s1 = 2*total_length - strokeoverlap*(1-strokeoverlap_rdm)*strokelength-0.0001;}
+ }
+ times = roots(piecelength-s1);
+ if (times.size()==0) break;//we should not be there.
+ t1 = times[0];
+
+ //pick a rdm perturbation, and collect the perturbed piece into output.
+ Piecewise<D2<SBasis> > pwperturb = computePerturbation(s0,s1);
+ pwperturb = compose(pwperturb,portion(piecelength,t0,t1));
+ output.concat(portion(piece,t0,t1)+pwperturb);
+
+ //step points: s0 = s1 - overlap.
+ //TODO: make sure this has to end?
+ s0 = s1 - strokeoverlap*(1-strokeoverlap_rdm)*strokelength;
+ }
+ }
+ }
+
+
+ //----- Construction lines.
+ //TODO: choose places according to curvature?.
+
+ //at this point we have:
+ //pathlength = arcLengthSb(pwd2_in,.1);
+ total_length = pathlength.segs.back().at1();
+ Piecewise<D2<SBasis> > m = pwd2_in;
+ Piecewise<D2<SBasis> > v = derivative(pwd2_in);
+ Piecewise<D2<SBasis> > a = derivative(v);
+ for (unsigned i=0; i<nbtangents; i++){
+ // pick a point where to draw a tangent (s = dist from start along path).
+ double s = total_length * ( i + tgtlength_rdm ) / (nbtangents+1.);
+ times = roots(pathlength-s);
+ assert(times.size()>0);//there should be one and only one solution!
+ double t = times[0];
+ Point m_t = m(t), v_t = v(t), a_t = a(t);
+ //Compute tgt length according to curvature (not exceeding tgtlength) so that
+ // dist to origninal curve ~ 4 * (parallel_offset+tremble_size).
+ //TODO: put this 4 as a parameter in the UI...
+ //TODO: what if with v=0?
+ double l = tgtlength*(1-tgtlength_rdm)/v_t.length();
+ double r = pow(v_t.length(),3)/cross(a_t,v_t);
+ r = sqrt((2*fabs(r)-tgtscale)*tgtscale)/v_t.length();
+ l=(r<l)?r:l;
+ //collect the tgt segment into output.
+ D2<SBasis> tgt = D2<SBasis>();
+ for (unsigned dim=0; dim<2; dim++){
+ tgt[dim] = SBasis(Linear(m_t[dim]-v_t[dim]*l, m_t[dim]+v_t[dim]*l));
+ }
+ output.concat(Piecewise<D2<SBasis> >(tgt));
+ }
+
+// // -------- Pleins et delies vs courbure ou direction...
+// Piecewise<D2<SBasis> > a = derivative(v);
+// Piecewise<SBasis> a_cross_n = cross(a,n);
+// Piecewise<SBasis> v_dot_n = dot(v,n);
+// //Piecewise<D2<SBasis> > rfrac = sectionize(D2<Piecewise<SBasis> >(a_cross_n,v_dot_n));
+// //Piecewise<SBasis> h = atan2(rfrac)*para1;
+// Piecewise<SBasis> h = reciprocal(curvature(piece))*para1;
+//
+// // Piecewise<D2<SBasis> > dir = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(0),Linear(-1)));
+// // Piecewise<SBasis> h = dot(n,dir)+1.;
+// // h *= h*(para1/4.);
+//
+// n = rot90(n);
+// output = piece+h*n;
+// output.concat(piece-h*n);
+//
+// //-----------
+
+ //output.concat(m);
+ return output;
+}
+
+/* ######################## */
+
+} //namespace LivePathEffect (setq default-directory "c:/Documents And Settings/jf/Mes Documents/InkscapeSVN")
+} /* 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 :
index fb6bdda3a35ed9e2feeef3555477affc8cb373c2..95d9ea94f0fa1ac7955cadf1d14106671c8710f7 100644 (file)
-#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
+#ifndef INKSCAPE_LPE_SKETCH_H
+#define INKSCAPE_LPE_SKETCH_H
+
+/** \file
+ * LPE <sketch> implementation, see lpe-sketch.cpp.
+ */
+
+/*
+ * Authors:
+ * JFB, but derived from 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/effect.h"
+#include "live_effects/parameter/parameter.h"
+#include "live_effects/parameter/random.h"
+#include "live_effects/parameter/point.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPESketch : public Effect {
+public:
+ LPESketch(LivePathEffectObject *lpeobject);
+ virtual ~LPESketch();
+
+// Choose to implement one of the doEffect functions. You can delete or comment out the others.
+// virtual void doEffect (SPCurve * curve);
+// virtual NArtBpath * doEffect_nartbpath (NArtBpath * path_in);
+// virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> & path_in);
+ virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in);
+
+private:
+ // add the parameters for your effect here:
+ //PointParam testpointA;
+ ScalarParam nbiter_approxstrokes;
+ ScalarParam strokelength;
+ RandomParam strokelength_rdm;
+ ScalarParam strokeoverlap;
+ RandomParam strokeoverlap_rdm;
+ RandomParam ends_tolerance;
+ RandomParam parallel_offset;
+ RandomParam tremble_size;
+ ScalarParam tremble_frequency;
+ ScalarParam nbtangents;
+ ScalarParam tgtscale;
+ ScalarParam tgtlength;
+ RandomParam tgtlength_rdm;
+
+ LPESketch(const LPESketch&);
+ LPESketch& operator=(const LPESketch&);
+
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > computePerturbation (double s0, double s1);
+
+};
+
+} //namespace LivePathEffect
+} //namespace Inkscape
+
+#endif
diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert
index 1a92c80a1a454c07253bb195cfe09430a9913182..45049327071644d1c2bca4ba43dbf0c16b3ae347 100644 (file)
-## Makefile.am fragment sourced by src/Makefile.am.\r
-\r
-live_effects/parameter/all: live_effects/parameter/liblpeparam.a\r
-\r
-live_effects/parameter/clean:\r
- rm -f live_effects/parameter/liblpeparam.a $(live_effects_parameter_liblpeparam_a_OBJECTS)\r
-\r
-live_effects_parameter_liblpeparam_a_SOURCES = \\r
- live_effects/parameter/parameter.cpp \\r
- live_effects/parameter/parameter.h \\r
- live_effects/parameter/bool.cpp \\r
- live_effects/parameter/bool.h \\r
- live_effects/parameter/random.cpp \\r
- live_effects/parameter/random.h \\r
- live_effects/parameter/point.cpp \\r
- live_effects/parameter/point.h \\r
- live_effects/parameter/enum.h \\r
- live_effects/parameter/path.cpp \\r
- live_effects/parameter/path.h \r
-\r
-\r
-\r
+## Makefile.am fragment sourced by src/Makefile.am.
+
+live_effects/parameter/all: live_effects/parameter/liblpeparam.a
+
+live_effects/parameter/clean:
+ rm -f live_effects/parameter/liblpeparam.a $(live_effects_parameter_liblpeparam_a_OBJECTS)
+
+live_effects_parameter_liblpeparam_a_SOURCES = \
+ live_effects/parameter/parameter.cpp \
+ live_effects/parameter/parameter.h \
+ live_effects/parameter/bool.cpp \
+ live_effects/parameter/bool.h \
+ live_effects/parameter/random.cpp \
+ live_effects/parameter/random.h \
+ live_effects/parameter/point.cpp \
+ live_effects/parameter/point.h \
+ live_effects/parameter/enum.h \
+ live_effects/parameter/path.cpp \
+ live_effects/parameter/path.h
+
+