16#include <QVarLengthArray>
27 int nbPoints =
p.size();
28 QVarLengthArray<qreal> w(nbPoints);
30 QPointF pStar(0, 0), qStar(0, 0);
31 QVarLengthArray<QPointF> pHat(nbPoints), qHat(nbPoints);
33 for (
int i = 0; i < nbPoints; ++i) {
37 QVector2D
tmp(
p[i] -
v);
38 w[i] = 1. / pow(
tmp.lengthSquared(), alpha);
46 qreal A_tmp[4] = {0, 0, 0, 0};
47 for (
int i = 0; i < nbPoints; ++i) {
48 pHat[i] =
p[i] - pStar;
49 qHat[i] = q[i] - qStar;
51 A_tmp[0] += w[i] * pow(pHat[i].x(), 2);
52 A_tmp[3] += w[i] * pow(pHat[i].y(), 2);
53 A_tmp[1] += w[i] * pHat[i].x() * pHat[i].y();
56 qreal det_A_tmp = A_tmp[0] * A_tmp[3] - A_tmp[1] * A_tmp[2];
63 A_tmp_inv[0] = A_tmp[3] / det_A_tmp;
64 A_tmp_inv[1] = - A_tmp[1] / det_A_tmp;
65 A_tmp_inv[2] = A_tmp_inv[1];
66 A_tmp_inv[3] = A_tmp[0] / det_A_tmp;
68 QPointF t =
v - pStar;
69 QPointF A_precalc(t.x() * A_tmp_inv[0] + t.y() * A_tmp_inv[1], t.x() * A_tmp_inv[2] + t.y() * A_tmp_inv[3]);
73 for (
int j = 0; j < nbPoints; ++j) {
74 A_j = A_precalc.x() * pHat[j].x() + A_precalc.y() * pHat[j].y();
76 res += w[j] * A_j * qHat[j];
84 int nbPoints =
p.size();
85 QVarLengthArray<qreal> w(nbPoints);
87 QPointF pStar(0, 0), qStar(0, 0);
88 QVarLengthArray<QPointF> pHat(nbPoints), qHat(nbPoints);
90 for (
int i = 0; i < nbPoints; ++i) {
94 QVector2D
tmp(
p[i] -
v);
95 w[i] = 1. / pow(
tmp.lengthSquared(), alpha);
104 QPointF res_tmp(0, 0);
105 qreal qx, qy, px, py;
106 for (
int i = 0; i < nbPoints; ++i) {
107 pHat[i] =
p[i] - pStar;
108 qHat[i] = q[i] - qStar;
110 QVector2D
tmp(pHat[i]);
111 mu_s += w[i] *
tmp.lengthSquared();
113 qx = w[i] * qHat[i].x();
114 qy = w[i] * qHat[i].y();
118 res_tmp += QPointF(qx * px + qy * py, qx * py - qy * px);
122 QPointF v_m_pStar(
v - pStar);
123 QPointF res(res_tmp.x() * v_m_pStar.x() + res_tmp.y() * v_m_pStar.y(), res_tmp.x() * v_m_pStar.y() - res_tmp.y() * v_m_pStar.x());
131 int nbPoints =
p.size();
132 QVarLengthArray<qreal> w(nbPoints);
134 QPointF pStar(0, 0), qStar(0, 0);
135 QVarLengthArray<QPointF> pHat(nbPoints), qHat(nbPoints);
137 for (
int i = 0; i < nbPoints; ++i) {
141 QVector2D
tmp(
p[i] -
v);
142 w[i] = 1. / pow(
tmp.lengthSquared(), alpha);
143 pStar += w[i] *
p[i];
144 qStar += w[i] * q[i];
150 QVector2D res_tmp(0, 0);
151 qreal qx, qy, px, py;
152 for (
int i = 0; i < nbPoints; ++i) {
153 pHat[i] =
p[i] - pStar;
154 qHat[i] = q[i] - qStar;
156 qx = w[i] * qHat[i].x();
157 qy = w[i] * qHat[i].y();
161 res_tmp += QVector2D(qx * px + qy * py, qx * py - qy * px);
164 QPointF f_arrow(res_tmp.normalized().toPointF());
165 QVector2D v_m_pStar(
v - pStar);
166 QPointF res(f_arrow.x() * v_m_pStar.x() + f_arrow.y() * v_m_pStar.y(), f_arrow.x() * v_m_pStar.y() - f_arrow.y() * v_m_pStar.x());
173 : m_progress(progress)
236 dstDev->
moveTo(translate.toPoint());
244 const int pixelPrecision = 8;
249 srcBounds, pixelPrecision);
256 const qreal margin = 0.05;
274 const QImage& srcImage,
275 const QPointF &srcQImageOffset,
298 if (!warpMathFunction ||
299 origPoint.isEmpty() ||
300 origPoint.size() != transfPoint.size()) {
305 if (origPoint.size() == 1) {
306 *newOffset = srcQImageOffset + (transfPoint[0] - origPoint[0]).toPoint();
312 const QRectF srcBounds = QRectF(srcQImageOffset, srcImage.size());
316 QPolygonF testPoints;
317 testPoints << srcBounds.topLeft();
318 testPoints << srcBounds.topRight();
319 testPoints << srcBounds.bottomRight();
320 testPoints << srcBounds.bottomLeft();
321 testPoints << srcBounds.topLeft();
323 QPolygonF::iterator it = testPoints.begin() + 1;
325 while (it != testPoints.end()) {
326 it = testPoints.insert(it, 0.5 * (*it + *(it - 1)));
330 it = testPoints.begin();
332 while (it != testPoints.end()) {
333 *it = functionOp(*it);
337 dstBounds = testPoints.boundingRect();
340 QPointF dstQImageOffset = dstBounds.topLeft();
341 *newOffset = dstQImageOffset;
343 QRect dstBoundsI = dstBounds.toAlignedRect();
344 QImage dstImage(dstBoundsI.size(), srcImage.format());
347 const int pixelPrecision = 32;
void makeCloneFromRough(KisPaintDeviceSP src, const QRect &minimalRect)
const KoColorSpace * colorSpace() const
void moveTo(qint32 x, qint32 y)
QRect boundingRect() const
#define KIS_ASSERT_RECOVER(cond)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Rect blowRect(const Rect &rect, qreal coeff)
QRect approximateRectWithPointTransform(const QRect &rect, std::function< QPointF(QPointF)> func)