1 #define INKSCAPE_LPE_ROUGH_HATCHES_CPP
2 /** \file
3 * LPE Curve Stitching implementation, used as an example for a base starting class
4 * when implementing new LivePathEffects.
5 *
6 */
7 /*
8 * Authors:
9 * JF Barraud.
10 *
11 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include "live_effects/lpe-rough-hatches.h"
18 #include "sp-item.h"
19 #include "sp-path.h"
20 #include "svg/svg.h"
21 #include "xml/repr.h"
23 #include <2geom/path.h>
24 #include <2geom/piecewise.h>
25 #include <2geom/sbasis.h>
26 #include <2geom/sbasis-math.h>
27 #include <2geom/sbasis-geometric.h>
28 #include <2geom/bezier-to-sbasis.h>
29 #include <2geom/sbasis-to-bezier.h>
30 #include <2geom/d2.h>
31 #include <2geom/matrix.h>
33 #include "ui/widget/scalar.h"
34 #include "libnr/nr-values.h"
36 namespace Inkscape {
37 namespace LivePathEffect {
39 using namespace Geom;
41 //------------------------------------------------
42 // Some goodies to navigate through curve's levels.
43 //------------------------------------------------
44 struct LevelCrossing{
45 Point pt;
46 double t;
47 bool sign;
48 bool used;
49 std::pair<unsigned,unsigned> next_on_curve;
50 std::pair<unsigned,unsigned> prev_on_curve;
51 };
52 struct LevelCrossingOrder {
53 bool operator()(LevelCrossing a, LevelCrossing b) {
54 return ( a.pt[Y] < b.pt[Y] );// a.pt[X] == b.pt[X] since we are supposed to be on the same level...
55 //return ( a.pt[X] < b.pt[X] || ( a.pt[X] == b.pt[X] && a.pt[Y] < b.pt[Y] ) );
56 }
57 };
58 struct LevelCrossingInfo{
59 double t;
60 unsigned level;
61 unsigned idx;
62 };
63 struct LevelCrossingInfoOrder {
64 bool operator()(LevelCrossingInfo a, LevelCrossingInfo b) {
65 return a.t < b.t;
66 }
67 };
69 typedef std::vector<LevelCrossing> LevelCrossings;
71 std::vector<double>
72 discontinuities(Piecewise<D2<SBasis> > const &f){
73 std::vector<double> result;
74 if (f.size()==0) return result;
75 result.push_back(f.cuts[0]);
76 Point prev_pt = f.segs[0].at1();
77 //double old_t = f.cuts[0];
78 for(unsigned i=1; i<f.size(); i++){
79 if ( f.segs[i].at0()!=prev_pt){
80 result.push_back(f.cuts[i]);
81 //old_t = f.cuts[i];
82 //assert(f.segs[i-1].at1()==f.valueAt(old_t));
83 }
84 prev_pt = f.segs[i].at1();
85 }
86 result.push_back(f.cuts.back());
87 //assert(f.segs.back().at1()==f.valueAt(old_t));
88 return result;
89 }
91 class LevelsCrossings: public std::vector<LevelCrossings>{
92 public:
93 LevelsCrossings():std::vector<LevelCrossings>(){};
94 LevelsCrossings(std::vector<std::vector<double> > const ×,
95 Piecewise<D2<SBasis> > const &f,
96 Piecewise<SBasis> const &dx){
98 for (unsigned i=0; i<times.size(); i++){
99 LevelCrossings lcs;
100 for (unsigned j=0; j<times[i].size(); j++){
101 LevelCrossing lc;
102 lc.pt = f.valueAt(times[i][j]);
103 lc.t = times[i][j];
104 lc.sign = ( dx.valueAt(times[i][j])>0 );
105 lc.used = false;
106 lcs.push_back(lc);
107 }
108 std::sort(lcs.begin(), lcs.end(), LevelCrossingOrder());
109 push_back(lcs);
110 }
111 //Now create time ordering.
112 std::vector<LevelCrossingInfo>temp;
113 for (unsigned i=0; i<size(); i++){
114 for (unsigned j=0; j<(*this)[i].size(); j++){
115 LevelCrossingInfo elem;
116 elem.t = (*this)[i][j].t;
117 elem.level = i;
118 elem.idx = j;
119 temp.push_back(elem);
120 }
121 }
122 std::sort(temp.begin(),temp.end(),LevelCrossingInfoOrder());
123 std::vector<double> jumps = discontinuities(f);
124 unsigned jump_idx = 0;
125 unsigned first_in_comp = 0;
126 for (unsigned i=0; i<temp.size(); i++){
127 unsigned lvl = temp[i].level, idx = temp[i].idx;
128 if ( i == temp.size()-1 || temp[i+1].t > jumps[jump_idx+1]){
129 std::pair<unsigned,unsigned>next_data(temp[first_in_comp].level,temp[first_in_comp].idx);
130 (*this)[lvl][idx].next_on_curve = next_data;
131 first_in_comp = i+1;
132 jump_idx += 1;
133 }else{
134 std::pair<unsigned,unsigned> next_data(temp[i+1].level,temp[i+1].idx);
135 (*this)[lvl][idx].next_on_curve = next_data;
136 }
137 }
139 for (unsigned i=0; i<size(); i++){
140 for (unsigned j=0; j<(*this)[i].size(); j++){
141 std::pair<unsigned,unsigned> next = (*this)[i][j].next_on_curve;
142 (*this)[next.first][next.second].prev_on_curve = std::pair<unsigned,unsigned>(i,j);
143 }
144 }
145 }
147 void findFirstUnused(unsigned &level, unsigned &idx){
148 level = size();
149 idx = 0;
150 for (unsigned i=0; i<size(); i++){
151 for (unsigned j=0; j<(*this)[i].size(); j++){
152 if (!(*this)[i][j].used){
153 level = i;
154 idx = j;
155 return;
156 }
157 }
158 }
159 }
160 //set indexes to point to the next point in the "snake walk"
161 //follow_level's meaning:
162 // 0=yes upward
163 // 1=no, last move was upward,
164 // 2=yes downward
165 // 3=no, last move was downward.
166 void step(unsigned &level, unsigned &idx, int &direction){
167 if ( direction % 2 == 0 ){
168 if (direction == 0) {
169 if ( idx >= (*this)[level].size()-1 || (*this)[level][idx+1].used ) {
170 level = size();
171 return;
172 }
173 idx += 1;
174 }else{
175 if ( idx <= 0 || (*this)[level][idx-1].used ) {
176 level = size();
177 return;
178 }
179 idx -= 1;
180 }
181 direction += 1;
182 return;
183 }
184 //double t = (*this)[level][idx].t;
185 double sign = ((*this)[level][idx].sign ? 1 : -1);
186 //---double next_t = t;
187 //level += 1;
188 direction = (direction + 1)%4;
189 if (level == size()){
190 return;
191 }
193 std::pair<unsigned,unsigned> next;
194 if ( sign > 0 ){
195 next = (*this)[level][idx].next_on_curve;
196 }else{
197 next = (*this)[level][idx].prev_on_curve;
198 }
200 if ( level+1 != next.first || (*this)[next.first][next.second].used ) {
201 level = size();
202 return;
203 }
204 level = next.first;
205 idx = next.second;
206 return;
207 }
208 };
210 //-------------------------------------------------------
211 // Bend a path...
212 //-------------------------------------------------------
214 Piecewise<D2<SBasis> > bend(Piecewise<D2<SBasis> > const &f, Piecewise<SBasis> bending){
215 D2<Piecewise<SBasis> > ff = make_cuts_independent(f);
216 ff[X] += compose(bending, ff[Y]);
217 return sectionize(ff);
218 }
220 //--------------------------------------------------------
221 // The RoughHatches lpe.
222 //--------------------------------------------------------
223 LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) :
224 Effect(lpeobject),
225 hatch_dist(0),
226 dist_rdm(_("Frequency randomness:"), _("Variation of distance between hatches, in %."), "dist_rdm", &wr, this, 75),
227 growth(_("Growth:"), _("Growth of distance between hatches."), "growth", &wr, this, 0.),
228 //FIXME: top/bottom names are inverted in the UI/svg and in the code!!
229 scale_tf(_("Half-turns smoothness: 1st side, in:"), _("Set smoothness/sharpness of path when reaching a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bf", &wr, this, 1.),
230 scale_tb(_("1st side, out:"), _("Set smoothness/sharpness of path when leaving a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bb", &wr, this, 1.),
231 scale_bf(_("2nd side, in:"), _("Set smoothness/sharpness of path when reaching a 'top' half-turn. 0=sharp, 1=default"), "scale_tf", &wr, this, 1.),
232 scale_bb(_("2nd side, out:"), _("Set smoothness/sharpness of path when leaving a 'top' half-turn. 0=sharp, 1=default"), "scale_tb", &wr, this, 1.),
233 top_edge_variation(_("Magnitude jitter: 1st side:"), _("Randomly moves 'bottom' half-turns to produce magnitude variations."), "bottom_edge_variation", &wr, this, 0),
234 bot_edge_variation(_("2nd side:"), _("Randomly moves 'top' half-turns to produce magnitude variations."), "top_edge_variation", &wr, this, 0),
235 top_tgt_variation(_("Parallelism jitter: 1st side:"), _("Add direction randomness by moving 'bottom' half-turns tangentially to the boundary."), "bottom_tgt_variation", &wr, this, 0),
236 bot_tgt_variation(_("2nd side:"), _("Add direction randomness by randomly moving 'top' half-turns tangentially to the boundary."), "top_tgt_variation", &wr, this, 0),
237 top_smth_variation(_("Variance: 1st side:"), _("Randomness of 'bottom' half-turns smoothness"), "top_smth_variation", &wr, this, 0),
238 bot_smth_variation(_("2nd side:"), _("Randomness of 'top' half-turns smoothness"), "bottom_smth_variation", &wr, this, 0),
239 //
240 fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varying width"), "fat_output", &wr, this, true),
241 do_bend(_("Bend hatches"), _("Add a global bend to the hatches (slower)"), "do_bend", &wr, this, true),
242 stroke_width_top(_("Thickness: at 1st side:"), _("Width at 'bottom' half-turns"), "stroke_width_top", &wr, this, 1.),
243 stroke_width_bot(_("at 2nd side:"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.),
244 //
245 front_thickness(_("from 2nd to 1st side:"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.),
246 back_thickness(_("from 1st to 2nd side:"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25),
248 direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0)),
249 //
250 //bender(_("Global bending"), _("Relative position to a reference point defines global bending direction and amount"), "bender", &wr, this, NULL, Geom::Point(-5,0)),
251 bender(_("Global bending"), _("Relative position to a reference point defines global bending direction and amount"), "bender", &wr, this, Geom::Point(-5,0))
252 {
253 registerParameter( dynamic_cast<Parameter *>(&direction) );
254 registerParameter( dynamic_cast<Parameter *>(&dist_rdm) );
255 registerParameter( dynamic_cast<Parameter *>(&growth) );
256 registerParameter( dynamic_cast<Parameter *>(&do_bend) );
257 registerParameter( dynamic_cast<Parameter *>(&bender) );
258 registerParameter( dynamic_cast<Parameter *>(&top_edge_variation) );
259 registerParameter( dynamic_cast<Parameter *>(&bot_edge_variation) );
260 registerParameter( dynamic_cast<Parameter *>(&top_tgt_variation) );
261 registerParameter( dynamic_cast<Parameter *>(&bot_tgt_variation) );
262 registerParameter( dynamic_cast<Parameter *>(&scale_tf) );
263 registerParameter( dynamic_cast<Parameter *>(&scale_tb) );
264 registerParameter( dynamic_cast<Parameter *>(&scale_bf) );
265 registerParameter( dynamic_cast<Parameter *>(&scale_bb) );
266 registerParameter( dynamic_cast<Parameter *>(&top_smth_variation) );
267 registerParameter( dynamic_cast<Parameter *>(&bot_smth_variation) );
268 registerParameter( dynamic_cast<Parameter *>(&fat_output) );
269 registerParameter( dynamic_cast<Parameter *>(&stroke_width_top) );
270 registerParameter( dynamic_cast<Parameter *>(&stroke_width_bot) );
271 registerParameter( dynamic_cast<Parameter *>(&front_thickness) );
272 registerParameter( dynamic_cast<Parameter *>(&back_thickness) );
274 //hatch_dist.param_set_range(0.1, NR_HUGE);
275 growth.param_set_range(0, NR_HUGE);
276 dist_rdm.param_set_range(0, 99.);
277 stroke_width_top.param_set_range(0, NR_HUGE);
278 stroke_width_bot.param_set_range(0, NR_HUGE);
279 front_thickness.param_set_range(0, NR_HUGE);
280 back_thickness.param_set_range(0, NR_HUGE);
282 // hide the widgets for direction and bender vectorparams
283 direction.widget_is_visible = false;
284 bender.widget_is_visible = false;
286 concatenate_before_pwd2 = false;
287 show_orig_path = true;
288 }
290 LPERoughHatches::~LPERoughHatches()
291 {
293 }
295 Geom::Piecewise<Geom::D2<Geom::SBasis> >
296 LPERoughHatches::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in){
298 //std::cout<<"doEffect_pwd2:\n";
300 Piecewise<D2<SBasis> > result;
302 Piecewise<D2<SBasis> > transformed_pwd2_in = pwd2_in;
303 Point start = pwd2_in.segs.front().at0();
304 Point end = pwd2_in.segs.back().at1();
305 if (end != start ){
306 transformed_pwd2_in.push_cut( transformed_pwd2_in.cuts.back() + 1 );
307 D2<SBasis> stitch( SBasis( 1, Linear(end[X],start[X]) ), SBasis( 1, Linear(end[Y],start[Y]) ) );
308 transformed_pwd2_in.push_seg( stitch );
309 }
310 Point transformed_org = direction.getOrigin();
311 Piecewise<SBasis> tilter;//used to bend the hatches
312 Matrix bend_mat;//used to bend the hatches
314 if (do_bend.get_value()){
315 Point bend_dir = -rot90(unit_vector(bender.getVector()));
316 double bend_amount = L2(bender.getVector());
317 bend_mat = Matrix(-bend_dir[Y], bend_dir[X], bend_dir[X], bend_dir[Y],0,0);
318 transformed_pwd2_in = transformed_pwd2_in * bend_mat;
319 tilter = Piecewise<SBasis>(shift(Linear(-bend_amount),1));
320 OptRect bbox = bounds_exact( transformed_pwd2_in );
321 if (not(bbox)) return pwd2_in;
322 tilter.setDomain((*bbox)[Y]);
323 transformed_pwd2_in = bend(transformed_pwd2_in, tilter);
324 transformed_pwd2_in = transformed_pwd2_in * bend_mat.inverse();
325 }
326 hatch_dist = Geom::L2(direction.getVector())/5;
327 Point hatches_dir = rot90(unit_vector(direction.getVector()));
328 Matrix mat(-hatches_dir[Y], hatches_dir[X], hatches_dir[X], hatches_dir[Y],0,0);
329 transformed_pwd2_in = transformed_pwd2_in * mat;
330 transformed_org *= mat;
332 std::vector<std::vector<Point> > snakePoints;
333 snakePoints = linearSnake(transformed_pwd2_in, transformed_org);
334 if ( snakePoints.size() > 0 ){
335 Piecewise<D2<SBasis> >smthSnake = smoothSnake(snakePoints);
336 smthSnake = smthSnake*mat.inverse();
337 if (do_bend.get_value()){
338 smthSnake = smthSnake*bend_mat;
339 smthSnake = bend(smthSnake, -tilter);
340 smthSnake = smthSnake*bend_mat.inverse();
341 }
342 return (smthSnake);
343 }
344 return pwd2_in;
345 }
347 //------------------------------------------------
348 // Generate the levels with random, growth...
349 //------------------------------------------------
350 std::vector<double>
351 LPERoughHatches::generateLevels(Interval const &domain, double x_org){
352 std::vector<double> result;
353 int n = int((domain.min()-x_org)/hatch_dist);
354 double x = x_org + n * hatch_dist;
355 //double x = domain.min() + double(hatch_dist)/2.;
356 double step = double(hatch_dist);
357 double scale = 1+(hatch_dist*growth/domain.extent());
358 while (x < domain.max()){
359 result.push_back(x);
360 double rdm = 1;
361 if (dist_rdm.get_value() != 0)
362 rdm = 1.+ double((2*dist_rdm - dist_rdm.get_value()))/100.;
363 x+= step*rdm;
364 step*=scale;//(1.+double(growth));
365 }
366 return result;
367 }
370 //-------------------------------------------------------
371 // Walk through the intersections to create linear hatches
372 //-------------------------------------------------------
373 std::vector<std::vector<Point> >
374 LPERoughHatches::linearSnake(Piecewise<D2<SBasis> > const &f, Point const &org){
376 //std::cout<<"linearSnake:\n";
377 std::vector<std::vector<Point> > result;
378 Piecewise<SBasis> x = make_cuts_independent(f)[X];
379 //Remark: derivative is computed twice in the 2 lines below!!
380 Piecewise<SBasis> dx = derivative(x);
381 OptInterval range = bounds_exact(x);
383 if (not range) return result;
384 std::vector<double> levels = generateLevels(*range, org[X]);
385 std::vector<std::vector<double> > times;
386 times = multi_roots(x,levels);
387 //TODO: fix multi_roots!!!*****************************************
388 //remove doubles :-(
389 std::vector<std::vector<double> > cleaned_times(levels.size(),std::vector<double>());
390 for (unsigned i=0; i<times.size(); i++){
391 if ( times[i].size()>0 ){
392 double last_t = times[i][0]-1;//ugly hack!!
393 for (unsigned j=0; j<times[i].size(); j++){
394 if (times[i][j]-last_t >0.000001){
395 last_t = times[i][j];
396 cleaned_times[i].push_back(last_t);
397 }
398 }
399 }
400 }
401 times = cleaned_times;
402 //*******************************************************************
404 LevelsCrossings lscs(times,f,dx);
406 unsigned i,j;
407 lscs.findFirstUnused(i,j);
409 std::vector<Point> result_component;
410 int n = int((range->min()-org[X])/hatch_dist);
412 while ( i < lscs.size() ){
413 int dir = 0;
414 //switch orientation of first segment according to starting point.
415 if ((i % 2 == n % 2) && ((j + 1) < lscs[i].size()) && !lscs[i][j].used){
416 j += 1;
417 dir = 2;
418 }
420 while ( i < lscs.size() ){
421 result_component.push_back(lscs[i][j].pt);
422 lscs[i][j].used = true;
423 lscs.step(i,j, dir);
424 }
425 result.push_back(result_component);
426 result_component = std::vector<Point>();
427 lscs.findFirstUnused(i,j);
428 }
429 return result;
430 }
432 //-------------------------------------------------------
433 // Smooth the linear hatches according to params...
434 //-------------------------------------------------------
435 Piecewise<D2<SBasis> >
436 LPERoughHatches::smoothSnake(std::vector<std::vector<Point> > const &linearSnake){
438 Piecewise<D2<SBasis> > result;
439 for (unsigned comp=0; comp<linearSnake.size(); comp++){
440 if (linearSnake[comp].size()>=2){
441 Point last_pt = linearSnake[comp][0];
442 Point last_top = linearSnake[comp][0];
443 Point last_bot = linearSnake[comp][0];
444 Point last_hdle = linearSnake[comp][0];
445 Point last_top_hdle = linearSnake[comp][0];
446 Point last_bot_hdle = linearSnake[comp][0];
447 Geom::Path res_comp(last_pt);
448 Geom::Path res_comp_top(last_pt);
449 Geom::Path res_comp_bot(last_pt);
450 unsigned i=1;
451 //bool is_top = true;//Inversion here; due to downward y?
452 bool is_top = ( linearSnake[comp][0][Y] < linearSnake[comp][1][Y] );
454 while( i+1<linearSnake[comp].size() ){
455 Point pt0 = linearSnake[comp][i];
456 Point pt1 = linearSnake[comp][i+1];
457 Point new_pt = (pt0+pt1)/2;
458 double scale_in = (is_top ? scale_tf : scale_bf );
459 double scale_out = (is_top ? scale_tb : scale_bb );
460 if (is_top){
461 if (top_edge_variation.get_value() != 0)
462 new_pt[Y] += double(top_edge_variation)-top_edge_variation.get_value()/2.;
463 if (top_tgt_variation.get_value() != 0)
464 new_pt[X] += double(top_tgt_variation)-top_tgt_variation.get_value()/2.;
465 if (top_smth_variation.get_value() != 0) {
466 scale_in*=(100.-double(top_smth_variation))/100.;
467 scale_out*=(100.-double(top_smth_variation))/100.;
468 }
469 }else{
470 if (bot_edge_variation.get_value() != 0)
471 new_pt[Y] += double(bot_edge_variation)-bot_edge_variation.get_value()/2.;
472 if (bot_tgt_variation.get_value() != 0)
473 new_pt[X] += double(bot_tgt_variation)-bot_tgt_variation.get_value()/2.;
474 if (bot_smth_variation.get_value() != 0) {
475 scale_in*=(100.-double(bot_smth_variation))/100.;
476 scale_out*=(100.-double(bot_smth_variation))/100.;
477 }
478 }
479 Point new_hdle_in = new_pt + (pt0-pt1) * (scale_in /2.);
480 Point new_hdle_out = new_pt - (pt0-pt1) * (scale_out/2.);
482 if ( fat_output.get_value() ){
483 //double scaled_width = double((is_top ? stroke_width_top : stroke_width_bot))/(pt1[X]-pt0[X]);
484 double scaled_width = 1./(pt1[X]-pt0[X]);
485 Point hdle_offset = (pt1-pt0)*scaled_width;
486 Point inside = new_pt;
487 Point inside_hdle_in;
488 Point inside_hdle_out;
489 inside[Y]+= double((is_top ? -stroke_width_top : stroke_width_bot));
490 inside_hdle_in = inside + (new_hdle_in -new_pt);// + hdle_offset * double((is_top ? front_thickness : back_thickness));
491 inside_hdle_out = inside + (new_hdle_out-new_pt);// - hdle_offset * double((is_top ? back_thickness : front_thickness));
493 inside_hdle_in += (pt1-pt0)/2*( double((is_top ? front_thickness : back_thickness)) / (pt1[X]-pt0[X]) );
494 inside_hdle_out -= (pt1-pt0)/2*( double((is_top ? back_thickness : front_thickness)) / (pt1[X]-pt0[X]) );
496 new_hdle_in -= (pt1-pt0)/2*( double((is_top ? front_thickness : back_thickness)) / (pt1[X]-pt0[X]) );
497 new_hdle_out += (pt1-pt0)/2*( double((is_top ? back_thickness : front_thickness)) / (pt1[X]-pt0[X]) );
498 //TODO: find a good way to handle limit cases (small smthness, large stroke).
499 //if (inside_hdle_in[X] > inside[X]) inside_hdle_in = inside;
500 //if (inside_hdle_out[X] < inside[X]) inside_hdle_out = inside;
502 if (is_top){
503 res_comp_top.appendNew<CubicBezier>(last_top_hdle,new_hdle_in,new_pt);
504 res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,inside_hdle_in,inside);
505 last_top_hdle = new_hdle_out;
506 last_bot_hdle = inside_hdle_out;
507 }else{
508 res_comp_top.appendNew<CubicBezier>(last_top_hdle,inside_hdle_in,inside);
509 res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,new_hdle_in,new_pt);
510 last_top_hdle = inside_hdle_out;
511 last_bot_hdle = new_hdle_out;
512 }
513 }else{
514 res_comp.appendNew<CubicBezier>(last_hdle,new_hdle_in,new_pt);
515 }
517 last_hdle = new_hdle_out;
518 i+=2;
519 is_top = !is_top;
520 }
521 if ( i<linearSnake[comp].size() ){
522 if ( fat_output.get_value() ){
523 res_comp_top.appendNew<CubicBezier>(last_top_hdle,linearSnake[comp][i],linearSnake[comp][i]);
524 res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,linearSnake[comp][i],linearSnake[comp][i]);
525 }else{
526 res_comp.appendNew<CubicBezier>(last_hdle,linearSnake[comp][i],linearSnake[comp][i]);
527 }
528 }
529 if ( fat_output.get_value() ){
530 res_comp = res_comp_bot;
531 res_comp.append(res_comp_top.reverse(),Geom::Path::STITCH_DISCONTINUOUS);
532 }
533 result.concat(res_comp.toPwSb());
534 }
535 }
536 return result;
537 }
539 void
540 LPERoughHatches::doBeforeEffect (SPLPEItem */*lpeitem*/)
541 {
542 using namespace Geom;
543 top_edge_variation.resetRandomizer();
544 bot_edge_variation.resetRandomizer();
545 top_tgt_variation.resetRandomizer();
546 bot_tgt_variation.resetRandomizer();
547 top_smth_variation.resetRandomizer();
548 bot_smth_variation.resetRandomizer();
549 dist_rdm.resetRandomizer();
551 //original_bbox(lpeitem);
552 }
555 void
556 LPERoughHatches::resetDefaults(SPItem * item)
557 {
558 Effect::resetDefaults(item);
560 Geom::OptRect bbox = item->getBounds(Geom::identity(), SPItem::GEOMETRIC_BBOX);
561 Geom::Point origin(0.,0.);
562 Geom::Point vector(50.,0.);
563 if (bbox) {
564 origin = bbox->midpoint();
565 vector = Geom::Point((*bbox)[X].extent()/4, 0.);
566 top_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 );
567 bot_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 );
568 top_edge_variation.write_to_SVG();
569 bot_edge_variation.write_to_SVG();
570 }
571 //direction.set_and_write_new_values(origin, vector);
572 //bender.param_set_and_write_new_value( origin + Geom::Point(5,0) );
573 direction.set_and_write_new_values(origin + Geom::Point(0,-5), vector);
574 bender.set_and_write_new_values( origin, Geom::Point(5,0) );
575 hatch_dist = Geom::L2(vector)/2;
576 }
579 } //namespace LivePathEffect
580 } /* namespace Inkscape */
582 /*
583 Local Variables:
584 mode:c++
585 c-file-style:"stroustrup"
586 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
587 indent-tabs-mode:nil
588 fill-column:99
589 End:
590 */
591 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :