|
Krita Source Code Documentation
|
Classes | |
| class | BezierSegment |
| struct | Range |
Functions | |
| QPointF | bezierCurve (const QList< QPointF > &points, qreal t) |
| QPointF | bezierCurve (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t) |
| QPointF | bezierCurveDeriv (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t) |
| QPointF | bezierCurveDeriv2 (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t) |
| int | bezierDegree (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3) |
| template<typename Func > | |
| std::pair< Range, Range > | calcTightSrcRectRangeInParamSpace1D (const Range &searchParamRange, const Range &searchSrcRange, const Range &rect, Func func, qreal srcPrecision, std::optional< Range > squeezeRange=std::nullopt) |
| QPointF | calculateGlobalPos (const std::array< QPointF, 12 > &points, const QPointF &localPoint) |
| calculates global coordinate corresponding to the patch coordinate (u, v) | |
| template<class PatchMethod > | |
| QPointF | calculateGlobalPosImpl (const std::array< QPointF, 12 > &points, const QPointF &localPoint) |
| QPointF | calculateGlobalPosSVG2 (const std::array< QPointF, 12 > &points, const QPointF &localPoint) |
| calculates global coordinate corresponding to the patch coordinate (u, v) | |
| QPointF | calculateLocalPos (const std::array< QPointF, 12 > &points, const QPointF &globalPoint) |
calculates local (u,v) coordinates of the patch corresponding to globalPoint | |
| template<class PatchMethod > | |
| QPointF | calculateLocalPosImpl (const std::array< QPointF, 12 > &points, const QPointF &globalPoint) |
| QPointF | calculateLocalPosSVG2 (const std::array< QPointF, 12 > &points, const QPointF &globalPoint) |
calculates local (u,v) coordinates of the patch corresponding to globalPoint | |
| int | controlPolygonZeros (const QList< QPointF > &controlPoints) |
| qreal | curveLength (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, const qreal error) |
| qreal | curveLengthAtPoint (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t, const qreal error) |
| qreal | curveParamByProportion (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal proportion, const qreal error) |
| qreal | curveParamBySegmentLength (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal expectedLength, qreal totalLength, const qreal error) |
| qreal | curveProportionByParam (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t, const qreal error) |
| void | deCasteljau (const QPointF &q0, const QPointF &q1, const QPointF &q2, const QPointF &q3, qreal t, QPointF *p0, QPointF *p1, QPointF *p2, QPointF *p3, QPointF *p4) |
| QPointF | interpolateQuadric (const QPointF &p0, const QPointF &p2, const QPointF &pt, qreal t) |
| Interpolates quadric curve passing through given points. | |
| QVector< qreal > | intersectWithLine (const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const QLineF &line, qreal eps) |
| QVector< qreal > | intersectWithLineImpl (const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const QLineF &line, qreal eps, qreal alpha, qreal beta) |
| boost::optional< qreal > | intersectWithLineNearest (const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const QLineF &line, const QPointF &nearestAnchor, qreal eps) |
| bool | isLinearSegmentByControlPoints (const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const qreal eps=1e-4) |
| bool | isLinearSegmentByDerivatives (const QPointF &p0, const QPointF &d0, const QPointF &p1, const QPointF &d1, const qreal eps=1e-4) |
| QVector< qreal > | linearizeCurve (const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, const qreal eps) |
| QVector< qreal > | mergeLinearizationSteps (const QVector< qreal > &a, const QVector< qreal > &b) |
| qreal | nearestPoint (const QList< QPointF > controlPoints, const QPointF &point, qreal *resultDistance, QPointF *resultPoint) |
| std::pair< QPointF, QPointF > | offsetSegment (qreal t, const QPointF &offset) |
moves point t of the curve by offset offset | |
| QDebug | operator<< (QDebug dbg, const Range &r) |
| std::pair< QPointF, QPointF > | removeBezierNode (const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &q1, const QPointF &q2, const QPointF &q3) |
| Adjusts position for the bezier control points after removing a node. | |
|
inline |
Definition at line 113 of file KisBezierUtils.h.
References bezierCurve(), KIS_SAFE_ASSERT_RECOVER_NOOP, and lerp().
|
inline |
Definition at line 88 of file KisBezierUtils.h.
References deCasteljau(), p0, p1, p2, p3, pow2(), q0, q1, q2, and q3.
|
inline |
|
inline |
|
inline |
Definition at line 158 of file KisBezierUtils.h.
References eps, KisAlgebra2D::fuzzyPointCompare(), isLinearSegmentByControlPoints(), p0, p1, p2, and p3.
| std::pair< Range, Range > KisBezierUtils::calcTightSrcRectRangeInParamSpace1D | ( | const Range & | searchParamRange, |
| const Range & | searchSrcRange, | ||
| const Range & | rect, | ||
| Func | func, | ||
| qreal | srcPrecision, | ||
| std::optional< Range > | squeezeRange = std::nullopt ) |
Approximate the rect in param-space of the bezier patch that fully covers passed rect in the source-space. Due to the nature of the patch mapping, the result cannot be calculated precisely (easily). The passed srcPresition is only meant to be used for approximation algorithm termination. There is no guarantee that the result covers rect with this precision.
The function uses a simple binary search approach to estimate the borders of the rectangle in question.
To get better precision use iterational approach by combining X- and Y-axis approximation using searchParamRange and squeezeRange.
| searchParamRange | the range in param-space where the passed rect is searched for. The rect must be guaranteed to be present in this range, otherwise the behavior is undeifned. When doing iterational precision search, pass externalRange from the previous pass here. |
| searchSrcRange | the range in source-space, where the rect is placed. It is only used to check is the rect is placed exactly at the border of that range. |
| rect | rect in source-space that is searched for |
| func | the functor that maps a param in the param-space into a range in the source space |
| srcPrecision | src-space precision at which the search is stopped |
| squeezeRange | when doing iterational search, pass the opposite-axis range of the rectangle |
Definition at line 135 of file KisBezierPatchParamSpaceUtils.h.
References KisBezierUtils::Range::end, KisBezierUtils::Range::forwardDistanceTo(), KisBezierUtils::Range::isEmpty(), KIS_SAFE_ASSERT_RECOVER_BREAK, KIS_SAFE_ASSERT_RECOVER_NOOP, KisBezierUtils::Range::mid(), qFuzzyCompare(), qFuzzyIsNull(), KisBezierUtils::Range::squeezeRange(), and KisBezierUtils::Range::start.
| KRITAGLOBAL_EXPORT QPointF KisBezierUtils::calculateGlobalPos | ( | const std::array< QPointF, 12 > & | points, |
| const QPointF & | localPoint ) |
calculates global coordinate corresponding to the patch coordinate (u, v)
The function uses Krita's own level-based patch interpolation algorithm
| points | control points as laid out in KisBezierPatch |
| localPoint | point in local coordinates |
Definition at line 915 of file KisBezierUtils.cpp.
| QPointF KisBezierUtils::calculateGlobalPosImpl | ( | const std::array< QPointF, 12 > & | points, |
| const QPointF & | localPoint ) |
Definition at line 882 of file KisBezierUtils.cpp.
References KisBezierPatch::BL, KisBezierPatch::BL_HC, KisBezierPatch::BL_VC, KisBezierPatch::BR, KisBezierPatch::BR_HC, KisBezierPatch::BR_VC, p, KisBezierPatch::TL, KisBezierPatch::TL_HC, KisBezierPatch::TL_VC, KisBezierPatch::TR, KisBezierPatch::TR_HC, and KisBezierPatch::TR_VC.
| KRITAGLOBAL_EXPORT QPointF KisBezierUtils::calculateGlobalPosSVG2 | ( | const std::array< QPointF, 12 > & | points, |
| const QPointF & | localPoint ) |
calculates global coordinate corresponding to the patch coordinate (u, v)
The function uses SVG2 toon patches algorithm
| points | control points as laid out in KisBezierPatch |
| localPoint | point in local coordinates |
Definition at line 925 of file KisBezierUtils.cpp.
| KRITAGLOBAL_EXPORT QPointF KisBezierUtils::calculateLocalPos | ( | const std::array< QPointF, 12 > & | points, |
| const QPointF & | globalPoint ) |
calculates local (u,v) coordinates of the patch corresponding to globalPoint
The function uses Krita's own level-based patch interpolation algorithm
| points | control points as laid out in KisBezierPatch |
| globalPoint | point in global coordinates |
Definition at line 910 of file KisBezierUtils.cpp.
| QPointF KisBezierUtils::calculateLocalPosImpl | ( | const std::array< QPointF, 12 > & | points, |
| const QPointF & | globalPoint ) |
Definition at line 780 of file KisBezierUtils.cpp.
References KisAlgebra2D::absoluteToRelative(), KisAlgebra2D::accumulateBounds(), KisBezierPatch::BL, KisBezierPatch::BL_HC, KisBezierPatch::BL_VC, KisBezierPatch::BR, KisBezierPatch::BR_HC, KisBezierPatch::BR_VC, KIS_SAFE_ASSERT_RECOVER_NOOP, p, KisBezierPatch::TL, KisBezierPatch::TL_HC, KisBezierPatch::TL_VC, KisBezierPatch::TR, KisBezierPatch::TR_HC, and KisBezierPatch::TR_VC.
| KRITAGLOBAL_EXPORT QPointF KisBezierUtils::calculateLocalPosSVG2 | ( | const std::array< QPointF, 12 > & | points, |
| const QPointF & | globalPoint ) |
calculates local (u,v) coordinates of the patch corresponding to globalPoint
The function uses SVG2 toon patches algorithm
| points | control points as laid out in KisBezierPatch |
| globalPoint | point in global coordinates |
Definition at line 920 of file KisBezierUtils.cpp.
| KRITAGLOBAL_EXPORT int KisBezierUtils::controlPolygonZeros | ( | const QList< QPointF > & | controlPoints | ) |
Definition at line 491 of file KisBezierUtils.cpp.
References KisBezierUtils::BezierSegment::controlPolygonZeros().
| KRITAGLOBAL_EXPORT qreal KisBezierUtils::curveLength | ( | const QPointF | p0, |
| const QPointF | p1, | ||
| const QPointF | p2, | ||
| const QPointF | p3, | ||
| const qreal | error ) |
Definition at line 980 of file KisBezierUtils.cpp.
References bezierDegree(), curveLength(), deCasteljau(), kisDistance(), p0, p1, p2, p3, q0, q1, q2, and q3.
| KRITAGLOBAL_EXPORT qreal KisBezierUtils::curveLengthAtPoint | ( | const QPointF | p0, |
| const QPointF | p1, | ||
| const QPointF | p2, | ||
| const QPointF | p3, | ||
| qreal | t, | ||
| const qreal | error ) |
Definition at line 1041 of file KisBezierUtils.cpp.
References curveLength(), deCasteljau(), p0, p1, p2, p3, q0, q1, q2, and q3.
| KRITAGLOBAL_EXPORT qreal KisBezierUtils::curveParamByProportion | ( | const QPointF | p0, |
| const QPointF | p1, | ||
| const QPointF | p2, | ||
| const QPointF | p3, | ||
| qreal | proportion, | ||
| const qreal | error ) |
Definition at line 1068 of file KisBezierUtils.cpp.
References curveLength(), curveParamBySegmentLength(), p0, p1, p2, and p3.
| qreal KisBezierUtils::curveParamBySegmentLength | ( | const QPointF | p0, |
| const QPointF | p1, | ||
| const QPointF | p2, | ||
| const QPointF | p3, | ||
| qreal | expectedLength, | ||
| qreal | totalLength, | ||
| const qreal | error ) |
Definition at line 1049 of file KisBezierUtils.cpp.
References curveLength(), curveParamBySegmentLength(), deCasteljau(), p0, p1, p2, p3, q0, q1, q2, and q3.
| KRITAGLOBAL_EXPORT qreal KisBezierUtils::curveProportionByParam | ( | const QPointF | p0, |
| const QPointF | p1, | ||
| const QPointF | p2, | ||
| const QPointF | p3, | ||
| qreal | t, | ||
| const qreal | error ) |
Definition at line 1076 of file KisBezierUtils.cpp.
References curveLength(), curveLengthAtPoint(), p0, p1, p2, and p3.
|
inline |
Definition at line 52 of file KisBezierUtils.h.
| KRITAGLOBAL_EXPORT QPointF KisBezierUtils::interpolateQuadric | ( | const QPointF & | p0, |
| const QPointF & | p2, | ||
| const QPointF & | pt, | ||
| qreal | t ) |
Interpolates quadric curve passing through given points.
Interpolates quadric curve passing through p0, pt and p2 with ensuring that pt placed at position t
Definition at line 930 of file KisBezierUtils.cpp.
| KRITAGLOBAL_EXPORT QVector< qreal > KisBezierUtils::intersectWithLine | ( | const QPointF & | p0, |
| const QPointF & | p1, | ||
| const QPointF & | p2, | ||
| const QPointF & | p3, | ||
| const QLineF & | line, | ||
| qreal | eps ) |
Find intersection points (their parameter values) between a cubic Bezier curve and a line.
Curve: p0, p1, p2, p3 Line: line
For cubic Bezier curves there can be at most three intersection points.
Definition at line 1242 of file KisBezierUtils.cpp.
References eps, intersectWithLineImpl(), p0, p1, p2, and p3.
| QVector< qreal > KisBezierUtils::intersectWithLineImpl | ( | const QPointF & | p0, |
| const QPointF & | p1, | ||
| const QPointF & | p2, | ||
| const QPointF & | p3, | ||
| const QLineF & | line, | ||
| qreal | eps, | ||
| qreal | alpha, | ||
| qreal | beta ) |
Definition at line 1208 of file KisBezierUtils.cpp.
References deCasteljau(), eps, KisAlgebra2D::intersectLines(), intersectWithLineImpl(), kisDistance(), length(), p0, p1, p2, p3, q0, q1, q2, and q3.
| KRITAGLOBAL_EXPORT boost::optional< qreal > KisBezierUtils::intersectWithLineNearest | ( | const QPointF & | p0, |
| const QPointF & | p1, | ||
| const QPointF & | p2, | ||
| const QPointF & | p3, | ||
| const QLineF & | line, | ||
| const QPointF & | nearestAnchor, | ||
| qreal | eps ) |
Find new nearest intersection point between a cubic Bezier curve and a line. The resulting point will be the nearest to nearestAnchor.
Definition at line 1247 of file KisBezierUtils.cpp.
References bezierCurve(), distance(), eps, intersectWithLine(), kisDistance(), p0, p1, p2, and p3.
|
inline |
Definition at line 151 of file KisBezierUtils.h.
References eps, isLinearSegmentByDerivatives(), p0, p1, p2, and p3.
|
inline |
Definition at line 131 of file KisBezierUtils.h.
References KisAlgebra2D::crossProduct(), eps, KisAlgebra2D::norm(), p0, and p1.
| KRITAGLOBAL_EXPORT QVector< qreal > KisBezierUtils::linearizeCurve | ( | const QPointF | p0, |
| const QPointF | p1, | ||
| const QPointF | p2, | ||
| const QPointF | p3, | ||
| const qreal | eps ) |
Definition at line 29 of file KisBezierUtils.cpp.
References bezierCurve(), bezierCurveDeriv(), eps, isLinearSegmentByDerivatives(), kisDistance(), p, p0, p1, p2, and p3.
| KRITAGLOBAL_EXPORT QVector< qreal > KisBezierUtils::mergeLinearizationSteps | ( | const QVector< qreal > & | a, |
| const QVector< qreal > & | b ) |
Definition at line 69 of file KisBezierUtils.cpp.
| KRITAGLOBAL_EXPORT qreal KisBezierUtils::nearestPoint | ( | const QList< QPointF > | controlPoints, |
| const QPointF & | point, | ||
| qreal * | resultDistance, | ||
| QPointF * | resultPoint ) |
Definition at line 324 of file KisBezierUtils.cpp.
References bezierCurve(), kisSquareDistance(), KisBezierUtils::BezierSegment::point(), KisBezierUtils::BezierSegment::roots(), KisBezierUtils::BezierSegment::setDegree(), KisBezierUtils::BezierSegment::setPoint(), and u.
| KRITAGLOBAL_EXPORT std::pair< QPointF, QPointF > KisBezierUtils::offsetSegment | ( | qreal | t, |
| const QPointF & | offset ) |
moves point t of the curve by offset offset
Definition at line 953 of file KisBezierUtils.cpp.
| QDebug KisBezierUtils::operator<< | ( | QDebug | dbg, |
| const Range & | r ) |
Definition at line 96 of file KisBezierPatchParamSpaceUtils.h.
| KRITAGLOBAL_EXPORT std::pair< QPointF, QPointF > KisBezierUtils::removeBezierNode | ( | const QPointF & | p0, |
| const QPointF & | p1, | ||
| const QPointF & | p2, | ||
| const QPointF & | p3, | ||
| const QPointF & | q1, | ||
| const QPointF & | q2, | ||
| const QPointF & | q3 ) |
Adjusts position for the bezier control points after removing a node.
First source curve P: p0, p1, p2, p3 Second source curve Q: p3, q1, q2, q3
Node to remove: p3 and its control points p2 and q1
p1 and q2 Calculates the curve control point after removal of a node by minimizing squared error for the following problem:
Given two consequent 3rd order curves P and Q with lengths Lp and Lq, find 3rd order curve B, so that when splitting it at t = Lp / (Lp + Lq) (using de Casteljau algorithm) the control points of the resulting curves will have least square errors, compared to the corresponding control points of curves P and Q.
First we represent curves in matrix form:
B(t) = T * M * B, P(t) = T * Z1 * M * P, Q(t) = T * Z2 * M * Q,
where T = [1, t, t^2, t^3] M — 4x4 matrix of Bezier coefficients B, P, Q — vector of control points for the curves
Z1 — conversion matrix that splits the curve into range [0.0...t] Z2 — conversion matrix that splits the curve into range [t...1.0]
Then we represent vectors P and Q via B:
P = M^(-1) * Z1 * M * B Q = M^(-1) * Z2 * M * B
which in block matrix form looks like:
[ P ] [ M^(-1) * Z1 * M ] | | = | | * B [ Q ] [ M^(-1) * Z2 * M ]
[ M^(-1) * Z1 * M ]
let C = | |, [ M^(-1) * Z2 * M ]
[ P ] R = | | [ Q ]
then
R = C * B
applying normal equation to find a solution with least square error, get the final result:
B = (C'C)^(-1) * C' * R
Definition at line 1081 of file KisBezierUtils.cpp.
References C, curveLength(), p0, p1, p2, p3, pow2(), pow3(), q1, q2, q3, and R.