From: johanengelen Date: Sun, 12 Apr 2009 16:27:25 +0000 (+0000) Subject: add LPE recursive skeleton (experimental) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=afa1e71af5a64b54df797ac1f0bcf32c6613b371;p=inkscape.git add LPE recursive skeleton (experimental) --- diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index 8831bb135..d992dd7bb 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -69,6 +69,8 @@ ink_common_sources += \ live_effects/lpe-offset.h \ live_effects/lpe-ruler.cpp \ live_effects/lpe-ruler.h \ + live_effects/lpe-recursiveskeleton.cpp \ + live_effects/lpe-recursiveskeleton.h \ live_effects/lpe-text_label.cpp \ live_effects/lpe-text_label.h \ live_effects/lpe-path_length.cpp \ diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index 50001c841..1911c6e20 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -46,6 +46,7 @@ enum EffectType { LINE_SEGMENT, DOEFFECTSTACK_TEST, DYNASTROKE, + RECURSIVE_SKELETON, INVALID_LPE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan) }; diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 0af6cce72..d8fe6bfcf 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -73,6 +73,7 @@ #include "live_effects/lpe-text_label.h" #include "live_effects/lpe-path_length.h" #include "live_effects/lpe-line_segment.h" +#include "live_effects/lpe-recursiveskeleton.h" namespace Inkscape { @@ -98,6 +99,7 @@ const Util::EnumData LPETypeData[] = { {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, + {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, {RULER, N_("Ruler"), "ruler"}, {SKETCH, N_("Sketch"), "sketch"}, {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, @@ -226,6 +228,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case DYNASTROKE: neweffect = static_cast ( new LPEDynastroke(lpeobj) ); break; + case RECURSIVE_SKELETON: + neweffect = static_cast ( new LPERecursiveSkeleton(lpeobj) ); + break; default: g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); neweffect = NULL; diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp new file mode 100644 index 000000000..3cbac5829 --- /dev/null +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -0,0 +1,132 @@ +#define INKSCAPE_LPE_RECURSIVESKELETON_CPP +/** \file + * @brief + * + * Inspired by Hofstadter's 'Goedel Escher Bach', chapter V. + */ +/* Authors: + * Johan Engelen + * + * Copyright (C) 2007-2009 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-recursiveskeleton.h" + +#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/piecewise.h> + +namespace Inkscape { +namespace LivePathEffect { + +LPERecursiveSkeleton::LPERecursiveSkeleton(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + iterations(_("Iterations"), _("recursivity"), "iterations", &wr, this, 2) +{ + show_orig_path = true; + concatenate_before_pwd2 = true; + iterations.param_make_integer(true); + iterations.param_set_range(1, 15); + registerParameter( dynamic_cast(&iterations) ); + +} + +LPERecursiveSkeleton::~LPERecursiveSkeleton() +{ + +} + + +Geom::Piecewise > +LPERecursiveSkeleton::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) +{ + using namespace Geom; + + Piecewise > output; + std::vector > > pre_output; + + double prop_scale = 1.0; + double fuse_tolerance = 0; + + D2 > patternd2 = make_cuts_independent(pwd2_in); + Piecewise x0 = false /*vertical_pattern.get_value()*/ ? Piecewise(patternd2[1]) : Piecewise(patternd2[0]); + Piecewise y0 = false /*vertical_pattern.get_value()*/ ? Piecewise(patternd2[0]) : Piecewise(patternd2[1]); + OptInterval pattBndsX = bounds_exact(x0); + OptInterval pattBndsY = bounds_exact(y0); + + if ( !pattBndsX || !pattBndsY) { + return pwd2_in; + } + + x0 -= pattBndsX->min(); + y0 -= pattBndsY->middle(); + + double xspace = 0;//spacing; + double noffset = 0;//normal_offset; + double toffset = 0;//tang_offset; + if (false /*prop_units.get_value()*/){ + xspace *= pattBndsX->extent(); + noffset *= pattBndsY->extent(); + toffset *= pattBndsX->extent(); + } + + y0+=noffset; + + output = pwd2_in; + + for (int i = 0; i < iterations; ++i) { + std::vector > > skeleton = split_at_discontinuities(output); + + output.clear(); + for (unsigned idx = 0; idx < skeleton.size(); idx++){ + Piecewise > path_i = skeleton[idx]; + Piecewise x = x0; + Piecewise y = y0; + Piecewise > uskeleton = arc_length_parametrization(path_i,2,.1); + uskeleton = remove_short_cuts(uskeleton,.01); + Piecewise > n = rot90(derivative(uskeleton)); + n = force_continuity(remove_short_cuts(n,.1)); + + double scaling = 1; + scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent(); + + double pattWidth = pattBndsX->extent() * scaling; + + if (scaling != 1.0) { + x*=scaling; + } + + if ( true /*scale_y_rel.get_value()*/ ) { + y*=(scaling*prop_scale); + } else { + if (prop_scale != 1.0) y *= prop_scale; + } + x += toffset; + + output.concat(compose(uskeleton,x)+y*compose(n,x)); + } + } + + return output; +} + + +} //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:encoding=utf-8:textwidth=99 : diff --git a/src/live_effects/lpe-recursiveskeleton.h b/src/live_effects/lpe-recursiveskeleton.h new file mode 100644 index 000000000..2fc9f8b68 --- /dev/null +++ b/src/live_effects/lpe-recursiveskeleton.h @@ -0,0 +1,50 @@ +/** @file + * @brief see lpe-recursiveskeleton.cpp. + */ +/* Authors: + * Johan Engelen + * + * Copyright (C) 2007-2009 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_LPE_RECURSIVESKELETON_H +#define INKSCAPE_LPE_RECURSIVESKELETON_H + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { +namespace LivePathEffect { + + +class LPERecursiveSkeleton : public Effect { +public: + LPERecursiveSkeleton(LivePathEffectObject *lpeobject); + virtual ~LPERecursiveSkeleton(); + + virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + +private: + ScalarParam iterations; + + LPERecursiveSkeleton(const LPERecursiveSkeleton&); + LPERecursiveSkeleton& operator=(const LPERecursiveSkeleton&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif + +/* + 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:encoding=utf-8:textwidth=99 :