lpe-sketch.cpp revision 798610678beb5729b3d2819f747a82390bf20cbc
#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 <libnr/n-art-bpath.h>
// You might need to include other 2geom files. You can add them here:
namespace Inkscape {
namespace LivePathEffect {
// 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"),
strokelength_rdm(_("Stroke length variation"),
_("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(_("Overlap variation"),
ends_tolerance(_("Max. ends tolerance"),
_("Max. distance between original and approximated paths ends (relative to max. length)."), "ends_tolerance", &wr, this, .1),
parallel_offset(_("Parallel offset"),
tremble_size(_("Max. tremble"),
tremble_frequency(_("Tremble frequency"),
nbtangents(_("Nb of construction Lines"),
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(_("Length variation"), _("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) );
}
{
}
/*
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();
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();
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...
{
using namespace Geom;
unsigned piece_start = 0;
for (unsigned j = piece_start; j<i+1; j++){
}
piece_start = i+1;
}
}
return ret;
}
//This returns a random perturbation. Notice the domain is [s0,s0+first multiple of period>s1]...
using namespace Geom;
//global offset for this stroke.
//start point A
}
//compute howmany deg 3 sbasis to concat according to frequency.
for (unsigned i=0; i<count; i++){
}
A = B;
}
return res;
}
// Main effect body...
{
using namespace Geom;
//init random parameters.
// some variables for futur use.
// notations will be : t = path time, s = distance from start along the path.
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!
//work separately on each component.
//TODO: better check this on the Geom::Path.
if (closed){
}
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 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!)
// pick a new end point (s1 = s0 + strokelength).
// don't let it go beyond the end of the orgiginal path.
done = true;
//!!the root solver might miss s1==total_length...
}
done = true;
if (closed && s1>2*total_length){s1 = 2*total_length - strokeoverlap*(1-strokeoverlap_rdm)*strokelength-0.0001;}
}
//pick a rdm perturbation, and collect the perturbed piece into output.
//step points: s0 = s1 - overlap.
//TODO: make sure this has to end?
}
}
}
//----- Construction lines.
//TODO: choose places according to curvature?.
//at this point we have:
//pathlength = arcLengthSb(pwd2_in,.1);
for (unsigned i=0; i<nbtangents; i++){
// pick a point where to draw a tangent (s = dist from start along path).
double t = times[0];
//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?
l=(r<l)?r:l;
//collect the tgt segment into output.
}
}
// // -------- 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 :