Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPerspectiveTransformStrategy::Private Struct Reference

Classes

struct  HandlePoints
 

Public Member Functions

QCursor getScaleCursor (const QPointF &handlePt)
 
QCursor getShearCursor (const QPointF &start, const QPointF &end)
 
 Private (KisPerspectiveTransformStrategy *_q, const KisCoordinatesConverter *_converter, ToolTransformArgs &_currentArgs, TransformTransactionProperties &_transaction)
 
void recalculateTransformations ()
 
void recalculateTransformedHandles ()
 
QTransform transformFromArgs ()
 
void transformIntoArgs (const Eigen::Matrix3f &t)
 

Public Attributes

ToolTransformArgs clickArgs
 
QPointF clickPos
 
const KisCoordinatesConverter * converter
 standard members ///
 
ToolTransformArgs & currentArgs
 
int currentDraggingHandlePoint {0}
 
QVector< QPointF > dstHandlePoints
 
StrokeFunction function {NONE}
 custom members ///
 
QTransform handlesTransform
 
bool imageTooBig {false}
 
bool isTransforming {false}
 
QImage originalImage
 
QPointF paintingOffset
 
QTransform paintingTransform
 
KisPerspectiveTransformStrategy * q
 
QVector< QPointF > srcHandlePoints
 
QTransform thumbToImageTransform
 
TransformTransactionProperties & transaction
 
QTransform transform
 
HandlePoints transformedHandles
 

Static Public Attributes

static constexpr qreal MaxPolygonVertexAngle {177.0}
 

Detailed Description

Definition at line 49 of file kis_perspective_transform_strategy.cpp.

Constructor & Destructor Documentation

◆ Private()

KisPerspectiveTransformStrategy::Private::Private ( KisPerspectiveTransformStrategy * _q,
const KisCoordinatesConverter * _converter,
ToolTransformArgs & _currentArgs,
TransformTransactionProperties & _transaction )
inline

Member Function Documentation

◆ getScaleCursor()

QCursor KisPerspectiveTransformStrategy::Private::getScaleCursor ( const QPointF & handlePt)

◆ getShearCursor()

QCursor KisPerspectiveTransformStrategy::Private::getShearCursor ( const QPointF & start,
const QPointF & end )

◆ recalculateTransformations()

void KisPerspectiveTransformStrategy::Private::recalculateTransformations ( )

Definition at line 679 of file kis_perspective_transform_strategy.cpp.

680{
682
683 QTransform viewScaleTransform = converter->imageToDocumentTransform() * converter->documentToFlakeTransform();
684 handlesTransform = transform * viewScaleTransform;
685
686 QTransform tl = QTransform::fromTranslate(transaction.originalTopLeft().x(), transaction.originalTopLeft().y());
687 paintingTransform = tl.inverted() * q->thumbToImageTransform() * tl * transform * viewScaleTransform;
689
690 imageTooBig = false;
691
692 {
693 QVector<QPointF> points;
694 points << transaction.originalRect().topLeft();
695 points << transaction.originalRect().topRight();
696 points << transaction.originalRect().bottomRight();
697 points << transaction.originalRect().bottomLeft();
698
699 for (int i = 0; i < points.size(); i++) {
700 points[i] = transform.map(points[i]);
701 }
702
703 QPolygonF poly (points);
705 imageTooBig = true;
706 }
707
708 const QRectF transformedRect = poly.boundingRect();
709 const QRectF limitRect = KisAlgebra2D::blowRect(converter->imageRectInImagePixels(), 2.0);
710 if (!limitRect.contains(transformedRect)) {
711 imageTooBig = true;
712 }
713 }
714
715 // recalculate cached handles position
717
720}
void requestShowImageTooBig(bool value)
Rect blowRect(const Rect &rect, qreal coeff)
bool isPolygonTrulyConvex(const QVector< T > &polygon, bool ensureNoLoops=true, qreal maxAngle=180.0)

References KisAlgebra2D::blowRect(), KisAlgebra2D::isPolygonTrulyConvex(), and MaxPolygonVertexAngle.

◆ recalculateTransformedHandles()

void KisPerspectiveTransformStrategy::Private::recalculateTransformedHandles ( )

Definition at line 133 of file kis_perspective_transform_strategy.cpp.

134{
135 srcHandlePoints.resize(HANDLE_COUNT);
136 srcHandlePoints[HANDLE_TOP_LEFT] = transaction.originalTopLeft();
137 srcHandlePoints[HANDLE_TOP_RIGHT] = transaction.originalTopRight();
138 srcHandlePoints[HANDLE_BOTTOM_LEFT] = transaction.originalBottomLeft();
139 srcHandlePoints[HANDLE_BOTTOM_RIGHT] = transaction.originalBottomRight();
140 srcHandlePoints[HANDLE_MIDDLE_TOP] = transaction.originalMiddleTop();
141 srcHandlePoints[HANDLE_MIDDLE_BOTTOM] = transaction.originalMiddleBottom();
142 srcHandlePoints[HANDLE_MIDDLE_LEFT] = transaction.originalMiddleLeft();
143 srcHandlePoints[HANDLE_MIDDLE_RIGHT] = transaction.originalMiddleRight();
144
145 dstHandlePoints.clear();
146 Q_FOREACH (const QPointF &pt, srcHandlePoints) {
147 dstHandlePoints << transform.map(pt);
148 }
149
150 QMatrix4x4 realMatrix(transform);
151 QVector4D v;
152
153 v = QVector4D(1, 0, 0, 0);
154 v = realMatrix * v;
156 transformedHandles.xVanishing = v.toVector2DAffine().toPointF();
157
158 v = QVector4D(0, 1, 0, 0);
159 v = realMatrix * v;
161 transformedHandles.yVanishing = v.toVector2DAffine().toPointF();
162}
qreal v
static bool qFuzzyCompare(half p1, half p2)

References dstHandlePoints, TransformTransactionProperties::originalBottomLeft(), TransformTransactionProperties::originalBottomRight(), TransformTransactionProperties::originalMiddleBottom(), TransformTransactionProperties::originalMiddleLeft(), TransformTransactionProperties::originalMiddleRight(), TransformTransactionProperties::originalMiddleTop(), TransformTransactionProperties::originalTopLeft(), TransformTransactionProperties::originalTopRight(), qFuzzyCompare(), srcHandlePoints, transaction, transform, transformedHandles, v, KisPerspectiveTransformStrategy::Private::HandlePoints::xVanishing, KisPerspectiveTransformStrategy::Private::HandlePoints::xVanishingExists, KisPerspectiveTransformStrategy::Private::HandlePoints::yVanishing, and KisPerspectiveTransformStrategy::Private::HandlePoints::yVanishingExists.

◆ transformFromArgs()

QTransform KisPerspectiveTransformStrategy::Private::transformFromArgs ( )

◆ transformIntoArgs()

void KisPerspectiveTransformStrategy::Private::transformIntoArgs ( const Eigen::Matrix3f & t)

We disabled decomposed transformation due to bug https://bugs.kde.org/show_bug.cgi?id=447255

In some cases decomposed preliminary transformation shrinks the image into a very small size, which is later inflated by the perspective transform. It creates a really bad and blurry result.

Even though the usage of preliminary rotation makes the bug much less obvious, but the image is still really blurred.

Definition at line 412 of file kis_perspective_transform_strategy.cpp.

413{
414 Eigen::Matrix3f TS = fromTranslate(-currentArgs.originalCenter());
415
416 Eigen::Matrix3f m = t * TS.inverse();
417
418 qreal tX = m(0,2) / m(2,2);
419 qreal tY = m(1,2) / m(2,2);
420
421 Eigen::Matrix3f T = fromTranslate(QPointF(tX, tY));
422
423 m = T.inverse() * m;
424
438#if 0
439 // Decomposition according to:
440 // https://www.w3.org/TR/css-transforms-1/#decomposing-a-3d-matrix
442
443 currentArgs.setScaleX(dm.scaleX);
444 currentArgs.setScaleY(dm.scaleY);
445
446 currentArgs.setShearX(dm.shearXY);
448
450
451 QTransform pre = dm.scaleTransform() * dm.shearTransform() * dm.rotateTransform();
452 m = m * fromQTransform(pre.inverted());
453#else
458 currentArgs.setAZ(0.0);
459#endif
460
461 currentArgs.setTransformedCenter(QPointF(tX, tY));
463}
void setShearX(double shearX)
void setScaleX(double scaleX)
void setTransformedCenter(QPointF transformedCenter)
void setScaleY(double scaleY)
QPointF originalCenter() const
void setShearY(double shearY)
void setFlattenedPerspectiveTransform(const QTransform &value)
T kisDegreesToRadians(T degrees)
Definition kis_global.h:176
Eigen::Matrix3f fromTranslate(const QPointF &pt)
Eigen::Matrix3f fromQTransform(const QTransform &t)
QTransform toQTransform(const Eigen::Matrix3f &m)

References KisAlgebra2D::DecomposedMatrix::angle, fromQTransform(), fromTranslate(), kisDegreesToRadians(), KisAlgebra2D::DecomposedMatrix::rotateTransform(), KisAlgebra2D::DecomposedMatrix::scaleTransform(), KisAlgebra2D::DecomposedMatrix::scaleX, KisAlgebra2D::DecomposedMatrix::scaleY, KisAlgebra2D::DecomposedMatrix::shearTransform(), KisAlgebra2D::DecomposedMatrix::shearXY, and toQTransform().

Member Data Documentation

◆ clickArgs

ToolTransformArgs KisPerspectiveTransformStrategy::Private::clickArgs

Definition at line 106 of file kis_perspective_transform_strategy.cpp.

◆ clickPos

QPointF KisPerspectiveTransformStrategy::Private::clickPos

Definition at line 105 of file kis_perspective_transform_strategy.cpp.

◆ converter

const KisCoordinatesConverter* KisPerspectiveTransformStrategy::Private::converter

standard members ///

Definition at line 68 of file kis_perspective_transform_strategy.cpp.

◆ currentArgs

ToolTransformArgs& KisPerspectiveTransformStrategy::Private::currentArgs

Definition at line 71 of file kis_perspective_transform_strategy.cpp.

◆ currentDraggingHandlePoint

int KisPerspectiveTransformStrategy::Private::currentDraggingHandlePoint {0}

Definition at line 101 of file kis_perspective_transform_strategy.cpp.

101{0};

◆ dstHandlePoints

QVector<QPointF> KisPerspectiveTransformStrategy::Private::dstHandlePoints

Definition at line 100 of file kis_perspective_transform_strategy.cpp.

◆ function

StrokeFunction KisPerspectiveTransformStrategy::Private::function {NONE}

custom members ///

Definition at line 86 of file kis_perspective_transform_strategy.cpp.

86{NONE};
@ NONE

◆ handlesTransform

QTransform KisPerspectiveTransformStrategy::Private::handlesTransform

Definition at line 82 of file kis_perspective_transform_strategy.cpp.

◆ imageTooBig

bool KisPerspectiveTransformStrategy::Private::imageTooBig {false}

Definition at line 103 of file kis_perspective_transform_strategy.cpp.

103{false};

◆ isTransforming

bool KisPerspectiveTransformStrategy::Private::isTransforming {false}

Definition at line 107 of file kis_perspective_transform_strategy.cpp.

107{false};

◆ MaxPolygonVertexAngle

constexpr qreal KisPerspectiveTransformStrategy::Private::MaxPolygonVertexAngle {177.0}
staticconstexpr

Definition at line 117 of file kis_perspective_transform_strategy.cpp.

117{177.0};

◆ originalImage

QImage KisPerspectiveTransformStrategy::Private::originalImage

Definition at line 77 of file kis_perspective_transform_strategy.cpp.

◆ paintingOffset

QPointF KisPerspectiveTransformStrategy::Private::paintingOffset

Definition at line 80 of file kis_perspective_transform_strategy.cpp.

◆ paintingTransform

QTransform KisPerspectiveTransformStrategy::Private::paintingTransform

Definition at line 79 of file kis_perspective_transform_strategy.cpp.

◆ q

KisPerspectiveTransformStrategy* KisPerspectiveTransformStrategy::Private::q

Definition at line 64 of file kis_perspective_transform_strategy.cpp.

◆ srcHandlePoints

QVector<QPointF> KisPerspectiveTransformStrategy::Private::srcHandlePoints

Definition at line 99 of file kis_perspective_transform_strategy.cpp.

◆ thumbToImageTransform

QTransform KisPerspectiveTransformStrategy::Private::thumbToImageTransform

Definition at line 76 of file kis_perspective_transform_strategy.cpp.

◆ transaction

TransformTransactionProperties& KisPerspectiveTransformStrategy::Private::transaction

Definition at line 73 of file kis_perspective_transform_strategy.cpp.

◆ transform

QTransform KisPerspectiveTransformStrategy::Private::transform

Definition at line 97 of file kis_perspective_transform_strategy.cpp.

◆ transformedHandles

HandlePoints KisPerspectiveTransformStrategy::Private::transformedHandles

Definition at line 95 of file kis_perspective_transform_strategy.cpp.


The documentation for this struct was generated from the following file: