1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#define INKSCAPE_LPE_POWERSTROKE_CPP
/** \file
* @brief PowerStroke LPE implementation. Creates curves with modifiable stroke width.
*/
/* Authors:
* Johan Engelen <j.b.c.engelen@utwente.nl>
*
* Copyright (C) 2010 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "live_effects/lpe-powerstroke.h"
#include "sp-shape.h"
#include "display/curve.h"
#include <2geom/path.h>
#include <2geom/piecewise.h>
#include <2geom/sbasis-geometric.h>
#include <2geom/svg-elliptical-arc.h>
#include <2geom/transforms.h>
namespace Inkscape {
namespace LivePathEffect {
LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
offset_1(_("Start Offset"), _("Handle to control the distance of the offset from the curve"), "offset_1", &wr, this),
offset_2(_("End Offset"), _("Handle to control the distance of the offset from the curve"), "offset_2", &wr, this),
offset_3(_("End Offset"), _("Handle to control the distance of the offset from the curve"), "offset_3", &wr, this),
offset_points(_("Offset points"), _("Offset points"), "offset_points", &wr, this)
{
show_orig_path = true;
registerParameter( dynamic_cast<Parameter *>(&offset_1) );
registerParameter( dynamic_cast<Parameter *>(&offset_2) );
registerParameter( dynamic_cast<Parameter *>(&offset_3) );
registerParameter( dynamic_cast<Parameter *>(&offset_points) );
}
LPEPowerStroke::~LPEPowerStroke()
{
}
void
LPEPowerStroke::doOnApply(SPLPEItem *lpeitem)
{
offset_1.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->curve->first_point()));
offset_2.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->curve->last_point()));
offset_3.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->curve->last_point()));
}
static void append_half_circle(Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
Geom::Point const center, Geom::Point const &dir) {
using namespace Geom;
double r = L2(dir);
SVGEllipticalArc cap(center + dir, r, r, angle_between(Point(1,0), dir), false, false, center - dir);
Piecewise<D2<SBasis> > cap_pwd2(cap.toSBasis());
pwd2.continuousConcat(cap_pwd2);
}
Geom::Piecewise<Geom::D2<Geom::SBasis> >
LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
{
using namespace Geom;
double t1 = nearest_point(offset_1, pwd2_in);
double offset1 = L2(pwd2_in.valueAt(t1) - offset_1);
double t2 = nearest_point(offset_2, pwd2_in);
double offset2 = L2(pwd2_in.valueAt(t2) - offset_2);
double t3 = nearest_point(offset_3, pwd2_in);
double offset3 = L2(pwd2_in.valueAt(t3) - offset_3);
/*
unsigned number_of_points = offset_points.data.size();
double* t = new double[number_of_points];
Point* offset = new double[number_of_points];
for (unsigned i = 0; i < number_of_points; ++i) {
t[i] = nearest_point(offset_points.data[i], pwd2_in);
Point A = pwd2_in.valueAt(t[i]);
offset[i] = L2(A - offset_points.data[i]);
}
*/
// create stroke path where points (x,y) = (t, offset)
Path strokepath;
strokepath.start( Point(pwd2_in.domain().min(),0) );
strokepath.appendNew<Geom::LineSegment>( Point(t1, offset1) );
strokepath.appendNew<Geom::LineSegment>( Point(t2, offset2) );
strokepath.appendNew<Geom::LineSegment>( Point(t3, offset3) );
strokepath.appendNew<Geom::LineSegment>( Point(pwd2_in.domain().max(), 0) );
strokepath.appendNew<Geom::LineSegment>( Point(t3, -offset3) );
strokepath.appendNew<Geom::LineSegment>( Point(t2, -offset2) );
strokepath.appendNew<Geom::LineSegment>( Point(t1, -offset1) );
strokepath.close();
D2<Piecewise<SBasis> > patternd2 = make_cuts_independent(strokepath.toPwSb());
Piecewise<SBasis> x = Piecewise<SBasis>(patternd2[0]);
Piecewise<SBasis> y = Piecewise<SBasis>(patternd2[1]);
Piecewise<D2<SBasis> > der = unitVector(derivative(pwd2_in));
Piecewise<D2<SBasis> > n = rot90(der);
// output = pwd2_in + n * offset;
// append_half_circle(output, pwd2_in.lastValue(), n.lastValue() * offset);
// output.continuousConcat(reverse(pwd2_in - n * offset));
// append_half_circle(output, pwd2_in.firstValue(), -n.firstValue() * offset);
Piecewise<D2<SBasis> > output = compose(pwd2_in,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 :
|