Code

3cbac5829babe66aee719e8f419c668c4903c9b4
[inkscape.git] / src / live_effects / lpe-recursiveskeleton.cpp
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;
55     double fuse_tolerance = 0;
57     D2<Piecewise<SBasis> > patternd2 = make_cuts_independent(pwd2_in);
58     Piecewise<SBasis> x0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[1]) : Piecewise<SBasis>(patternd2[0]);
59     Piecewise<SBasis> y0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[0]) : Piecewise<SBasis>(patternd2[1]);
60     OptInterval pattBndsX = bounds_exact(x0);
61     OptInterval pattBndsY = bounds_exact(y0);
63     if ( !pattBndsX || !pattBndsY) {
64         return pwd2_in;
65     }
67     x0 -= pattBndsX->min();
68     y0 -= pattBndsY->middle();
70     double xspace  = 0;//spacing;
71     double noffset = 0;//normal_offset;
72     double toffset = 0;//tang_offset;
73     if (false /*prop_units.get_value()*/){
74         xspace  *= pattBndsX->extent();
75         noffset *= pattBndsY->extent();
76         toffset *= pattBndsX->extent();
77     }
79     y0+=noffset;
81     output = pwd2_in;
83     for (int i = 0; i < iterations; ++i) {
84         std::vector<Piecewise<D2<SBasis> > > skeleton = split_at_discontinuities(output);
86         output.clear();
87         for (unsigned idx = 0; idx < skeleton.size(); idx++){
88             Piecewise<D2<SBasis> > path_i = skeleton[idx];
89             Piecewise<SBasis> x = x0;
90             Piecewise<SBasis> y = y0;
91             Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2,.1);
92             uskeleton = remove_short_cuts(uskeleton,.01);
93             Piecewise<D2<SBasis> > n = rot90(derivative(uskeleton));
94             n = force_continuity(remove_short_cuts(n,.1));
96             double scaling = 1;
97             scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent();
98             
99             double pattWidth = pattBndsX->extent() * scaling;
100             
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;
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:encoding=utf-8:textwidth=99 :