lpe-powerstroke.cpp revision ef8d59570ad27dee15e5c0038760980a8c1b4a35
/**
* @file
* PowerStroke LPE implementation. Creates curves with modifiable stroke width.
*/
/* Authors:
* Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
* Copyright (C) 2010-2012 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "live_effects/lpe-powerstroke.h"
#include "live_effects/lpe-powerstroke-interpolators.h"
#include "sp-shape.h"
#include "style.h"
#include "spiro.h"
namespace Geom {
// should all be moved to 2geom at some point
/** Find the point where two straight lines cross.
*/
{
}
}
{
}
/**
* document this!
* very quick: this finds the ellipse with minimum eccentricity
passing through point P and Q, with tangent PO at P and QO at Q
*/
{
Point p = P - O;
Point q = Q - O;
double cross = p[Y]*q[X] - p[X]*q[Y];
double a = -q[Y]/cross;
double b = q[X]/cross;
double c = (O[X]*q[Y] - O[Y]*q[X])/cross;
double d = p[Y]/cross;
double e = -p[X]/cross;
double f = (-O[X]*p[Y] + O[Y]*p[X])/cross;
// Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
double A = (a*d*K+d*d+a*a);
double B = (a*e*K+b*d*K+2*d*e+2*a*b);
double C = (b*e*K+e*e+b*b);
double D = (a*f*K+c*d*K+2*d*f-2*d+2*a*c-2*a);
double E = (b*f*K+c*e*K+2*e*f-2*e+2*b*c-2*b);
double F = c*f*K+f*f-2*f+c*c-2*c+1;
return Ellipse(A, B, C, D, E, F);
}
} // namespace Geom
namespace Inkscape {
namespace LivePathEffect {
};
static const Util::EnumDataConverter<unsigned> InterpolatorTypeConverter(InterpolatorTypeData, sizeof(InterpolatorTypeData)/sizeof(*InterpolatorTypeData));
enum LineCapType {
};
};
static const Util::EnumDataConverter<unsigned> LineCapTypeConverter(LineCapTypeData, sizeof(LineCapTypeData)/sizeof(*LineCapTypeData));
enum LineJoinType {
};
};
static const Util::EnumDataConverter<unsigned> LineJoinTypeConverter(LineJoinTypeData, sizeof(LineJoinTypeData)/sizeof(*LineJoinTypeData));
sort_points(_("Sort points"), _("Sort offset points according to their time value along the curve."), "sort_points", &wr, this, true),
interpolator_type(_("Interpolator type"), _("Determines which kind of interpolator will be used to interpolate between stroke width along the path."), "interpolator_type", InterpolatorTypeConverter, &wr, this, Geom::Interpolate::INTERP_CUBICBEZIER_JOHAN),
interpolator_beta(_("Smoothness"), _("Sets the smoothness for the CubicBezierJohan interpolator. 0 = linear interpolation, 1 = smooth"), "interpolator_beta", &wr, this, 0.2),
start_linecap_type(_("Start cap"), _("Determines the shape of the path's start."), "start_linecap_type", LineCapTypeConverter, &wr, this, LINECAP_ROUND),
linejoin_type(_("Join"), _("Specifies the shape of the path's corners."), "linejoin_type", LineJoinTypeConverter, &wr, this, LINEJOIN_ROUND),
miter_limit(_("Miter limit"), _("Maximum length of the miter (in units of stroke width)"), "miter_limit", &wr, this, 4.),
end_linecap_type(_("End cap"), _("Determines the shape of the path's end."), "end_linecap_type", LineCapTypeConverter, &wr, this, LINECAP_ROUND)
{
show_orig_path = true;
/// @todo offset_points are initialized with empty path, is that bug-save?
interpolator_beta.addSlider(true);
}
{
}
void
{
if (SP_IS_SHAPE(lpeitem)) {
} else {
}
}
} else {
g_warning("LPE Powerstroke can only be applied to shapes (not groups).");
}
}
void
{
}
}
{
}
double miter_limit,
bool /*forward_direction*/,
{
/* per definition, each discontinuity should be fixed with a join-ending, as defined by linejoin_type
*/
if (B.size() == 0) {
}
unsigned prev_i = 0;
for (unsigned i=1; i < B.size(); i++) {
// if segment is degenerate, skip it
// the degeneracy/constancy test had to be loosened (eps > 1e-5)
if (B[i].isConstant(1e-4)) {
continue;
}
{ // discontinuity found, so fix it :-)
if (on_outside) {
// we are on the outside: add some type of join!
switch (jointype) {
case LINEJOIN_ROUND: {
/* for constant width paths, the rounding is a circular arc (rx == ry),
for non-constant width paths, the rounding can be done with an ellipse but is hard and ambiguous.
The elliptical arc should go through the discontinuity's start and end points (of course!)
and also should match the discontinuity tangents at those start and end points.
To resolve the ambiguity, the elliptical arc with minimal eccentricity should be chosen.
A 2Geom method was created to do exactly this :)
*/
if (!O) {
// no center found, i.e. 180 degrees round
break;
}
try {
}
catch (Geom::LogicalError &e) {
// 2geom did not find a fitting ellipse, this happens for weird thick paths :)
// do bevel, and break
break;
}
break;
}
case LINEJOIN_EXTRP_MITER: {
// empty crossing: default to bevel
} else {
// check size of miter
// miter too big: default to bevel
} else {
}
}
break;
}
case LINEJOIN_MITER: {
if (p) {
// check size of miter
// miter OK
}
}
break;
}
case LINEJOIN_SPIRO: {
break;
}
case LINEJOIN_BEVEL:
default:
break;
}
} else {
// we are on inside of corner!
// empty crossing or too many crossings: default to bevel
} else {
// :-) quick hack:
}
}
}
} else {
}
prev_i = i;
}
}
{
using namespace Geom;
return path_out;
}
// for now, only regard first subpath and ignore the rest
return path_out;
}
if (sort_points) {
}
// add extra points for interpolation between first and last point
} else {
// add width data for first and last point on the path
// depending on cap type, these first and last points have width zero or take the width from the closest width point.
}
// create stroke path where points (x,y) := (t, offset)
Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast<Geom::Interpolate::InterpolatorType>(interpolator_type.get_value()));
if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast<Geom::Interpolate::CubicBezierJohan*>(interpolator)) {
}
delete interpolator;
// find time values for which x lies outside path domain
// and only take portion of x and y that lies within those time values
}
Geom::Path fixed_path = path_from_piecewise_fix_cusps( pwd2_out, y, jointype, miter_limit, LPE_CONVERSION_TOLERANCE);
Geom::Path fixed_mirrorpath = path_from_piecewise_fix_cusps( mirrorpath, reverse(y), jointype, miter_limit, LPE_CONVERSION_TOLERANCE);
fixed_path.close(true);
fixed_mirrorpath.close(true);
} else {
// add linecaps...
switch (end_linecap) {
case LINECAP_ZERO_WIDTH:
// do nothing
break;
case LINECAP_PEAK:
{
break;
}
case LINECAP_SQUARE:
{
break;
}
case LINECAP_BUTT:
{
break;
}
case LINECAP_ROUND:
default:
{
fixed_path.appendNew<SVGEllipticalArc>( radius1, radius1, M_PI/2., false, y.lastValue() < 0, mirrorpath.firstValue() );
break;
}
}
switch (start_linecap) {
case LINECAP_ZERO_WIDTH:
// do nothing
break;
case LINECAP_PEAK:
{
break;
}
case LINECAP_SQUARE:
{
break;
}
case LINECAP_BUTT:
{
break;
}
case LINECAP_ROUND:
default:
{
fixed_path.appendNew<SVGEllipticalArc>( radius2, radius2, M_PI/2., false, y.firstValue() < 0, pwd2_out.firstValue() );
break;
}
}
fixed_path.close(true);
}
return path_out;
}
/* ######################## */
} //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:fileencoding=utf-8:textwidth=99 :