Code

fix compositing for premultiplication and non-alpha cases
[inkscape.git] / src / live_effects / lpe-curvestitch.cpp
1 #define INKSCAPE_LPE_EXPRESSION_CPP\r
2 /** \file\r
3  * SVG <skeleton> implementation, used as an example for a base starting class\r
4  * when implementing new LivePathEffects.\r
5  *\r
6  */\r
7 /*\r
8  * Authors:\r
9  *   Johan Engelen\r
10 *\r
11 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
12  *\r
13  * Released under GNU GPL, read the file 'COPYING' for more information\r
14  */\r
15 \r
16 #include "live_effects/lpe-curvestitch.h"\r
17 #include "display/curve.h"\r
18 #include <libnr/n-art-bpath.h>\r
19 \r
20 #include <2geom/path.h>\r
21 #include <2geom/piecewise.h>\r
22 #include <2geom/sbasis.h>\r
23 #include <2geom/sbasis-geometric.h>\r
24 #include <2geom/bezier-to-sbasis.h>\r
25 #include <2geom/sbasis-to-bezier.h>\r
26 #include <2geom/d2.h>\r
27 \r
28 #include "ui/widget/scalar.h"\r
29 #include "libnr/nr-values.h"\r
30 \r
31 namespace Inkscape {\r
32 namespace LivePathEffect {\r
33 \r
34 using namespace Geom;\r
35 \r
36 LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) :\r
37     Effect(lpeobject),\r
38     strokepath(_("Stroke path"), _("The path that will be stroked, whatever, think of good text here."), "strokepath", &wr, this, "M0,0 L1,1"),\r
39     nrofpaths(_("Nr of paths"), _("The number of paths that will be generated."), "count", &wr, this, 5),\r
40     startpoint_variation(_("Startpoint variation"), _("..."), "startpoint_variation", &wr, this, 0),\r
41     endpoint_variation(_("Endpoint variation"), _("..."), "endpoint_variation", &wr, this, 0)\r
42 {\r
43     registerParameter( dynamic_cast<Parameter *>(&nrofpaths) );\r
44 //    registerParameter( dynamic_cast<Parameter *>(&startpoint_variation) );\r
45 //    registerParameter( dynamic_cast<Parameter *>(&endpoint_variation) );\r
46 \r
47     nrofpaths.param_make_integer();\r
48     nrofpaths.param_set_range(2, NR_HUGE);\r
49 \r
50 //    startpoint_variation.param_set_range(-NR_HUGE, 1);\r
51 //    endpoint_variation.param_set_range(-1, NR_HUGE);\r
52 }\r
53 \r
54 LPECurveStitch::~LPECurveStitch()\r
55 {\r
56 \r
57 }\r
58 \r
59 std::vector<Geom::Path>\r
60 LPECurveStitch::doEffect (std::vector<Geom::Path> & path_in)\r
61 {\r
62     if (path_in.size() >= 2) {\r
63         std::vector<Geom::Path> path_out (nrofpaths);\r
64 \r
65         // do this for all permutations if there are more than 2 paths? realllly cool!\r
66         Piecewise<D2<SBasis> > A = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[0].toPwSb()),2,.1);\r
67         Piecewise<D2<SBasis> > B = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[1].toPwSb()),2,.1);\r
68         Interval bndsA = A.domain();\r
69         Interval bndsB = B.domain();\r
70         gdouble incrementA = (bndsA.max()-bndsA.min()) / (nrofpaths-1);\r
71         gdouble incrementB = (bndsB.max()-bndsB.min()) / (nrofpaths-1);\r
72         gdouble tA = bndsA.min();\r
73         gdouble tB = bndsB.min();\r
74         for (int i = 0; i < nrofpaths; i++) {\r
75             Point start = A(tA);\r
76             Point end = B(tB);\r
77             if (startpoint_variation != 0)\r
78                 start = start + g_random_double_range(0, startpoint_variation) * (end - start);\r
79             if (endpoint_variation != 0)\r
80                 end = end + g_random_double_range(0, endpoint_variation) * (end - start);\r
81 \r
82             path_out[i].start( start );\r
83             path_out[i].appendNew<LineSegment>( end );\r
84             tA += incrementA;\r
85             tB += incrementB;\r
86         }\r
87 \r
88         return path_out;\r
89     } else {\r
90         return path_in;\r
91     }\r
92 }\r
93 \r
94 } //namespace LivePathEffect\r
95 } /* namespace Inkscape */\r
96 \r
97 /*\r
98   Local Variables:\r
99   mode:c++\r
100   c-file-style:"stroustrup"\r
101   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
102   indent-tabs-mode:nil\r
103   fill-column:99\r
104   End:\r
105 */\r
106 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r