1 #define INKSCAPE_LPE_RECURSIVESKELETON_CPP
2 /** \file
3 * @brief
4 *
5 * Inspired by Hofstadter's 'Goedel Escher Bach', chapter V.
6 */
7 /* Authors:
8 * Johan Engelen <j.b.c.engelen@utwente.nl>
9 *
10 * Copyright (C) 2007-2009 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include "live_effects/lpe-recursiveskeleton.h"
17 #include <2geom/path.h>
18 #include <2geom/sbasis.h>
19 #include <2geom/sbasis-geometric.h>
20 #include <2geom/bezier-to-sbasis.h>
21 #include <2geom/sbasis-to-bezier.h>
22 #include <2geom/d2.h>
23 #include <2geom/piecewise.h>
25 namespace Inkscape {
26 namespace LivePathEffect {
28 LPERecursiveSkeleton::LPERecursiveSkeleton(LivePathEffectObject *lpeobject) :
29 Effect(lpeobject),
30 iterations(_("Iterations"), _("recursivity"), "iterations", &wr, this, 2)
31 {
32 show_orig_path = true;
33 concatenate_before_pwd2 = true;
34 iterations.param_make_integer(true);
35 iterations.param_set_range(1, 15);
36 registerParameter( dynamic_cast<Parameter *>(&iterations) );
38 }
40 LPERecursiveSkeleton::~LPERecursiveSkeleton()
41 {
43 }
46 Geom::Piecewise<Geom::D2<Geom::SBasis> >
47 LPERecursiveSkeleton::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
48 {
49 using namespace Geom;
51 Piecewise<D2<SBasis> > output;
52 std::vector<Piecewise<D2<SBasis> > > pre_output;
54 double prop_scale = 1.0;
56 D2<Piecewise<SBasis> > patternd2 = make_cuts_independent(pwd2_in);
57 Piecewise<SBasis> x0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[1]) : Piecewise<SBasis>(patternd2[0]);
58 Piecewise<SBasis> y0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[0]) : Piecewise<SBasis>(patternd2[1]);
59 OptInterval pattBndsX = bounds_exact(x0);
60 OptInterval pattBndsY = bounds_exact(y0);
62 if ( !pattBndsX || !pattBndsY) {
63 return pwd2_in;
64 }
66 x0 -= pattBndsX->min();
67 y0 -= pattBndsY->middle();
69 double xspace = 0;//spacing;
70 double noffset = 0;//normal_offset;
71 double toffset = 0;//tang_offset;
72 if (false /*prop_units.get_value()*/){
73 xspace *= pattBndsX->extent();
74 noffset *= pattBndsY->extent();
75 toffset *= pattBndsX->extent();
76 }
78 y0+=noffset;
80 output = pwd2_in;
82 for (int i = 0; i < iterations; ++i) {
83 std::vector<Piecewise<D2<SBasis> > > skeleton = split_at_discontinuities(output);
85 output.clear();
86 for (unsigned idx = 0; idx < skeleton.size(); idx++){
87 Piecewise<D2<SBasis> > path_i = skeleton[idx];
88 Piecewise<SBasis> x = x0;
89 Piecewise<SBasis> y = y0;
90 Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2,.1);
91 uskeleton = remove_short_cuts(uskeleton,.01);
92 Piecewise<D2<SBasis> > n = rot90(derivative(uskeleton));
93 n = force_continuity(remove_short_cuts(n,.1));
95 double scaling = 1;
96 scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent();
98 // TODO investigate why pattWidth is not being used:
99 double pattWidth = pattBndsX->extent() * scaling;
101 if (scaling != 1.0) {
102 x*=scaling;
103 }
105 if ( true /*scale_y_rel.get_value()*/ ) {
106 y*=(scaling*prop_scale);
107 } else {
108 if (prop_scale != 1.0) y *= prop_scale;
109 }
110 x += toffset;
112 output.concat(compose(uskeleton,x)+y*compose(n,x));
113 }
114 }
116 return output;
117 }
120 } //namespace LivePathEffect
121 } /* namespace Inkscape */
123 /*
124 Local Variables:
125 mode:c++
126 c-file-style:"stroustrup"
127 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
128 indent-tabs-mode:nil
129 fill-column:99
130 End:
131 */
132 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :