File indexing completed on 2024-05-12 15:58:36
0001 /* 0002 * This file is part of Krita 0003 * 0004 * SPDX-FileCopyrightText: 2006 Cyrille Berger <cberger@cberger.net> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef _KIS_PERSPECTIVE_MATH_H_ 0010 #define _KIS_PERSPECTIVE_MATH_H_ 0011 0012 #include "kis_vec.h" 0013 #include <QPointF> 0014 #include <Eigen/Geometry> 0015 0016 typedef Eigen::Matrix<qreal, 3, 3> Matrix3qreal; 0017 typedef Eigen::Matrix<qreal, 9, 9> Matrix9qreal; 0018 typedef Eigen::Matrix<qreal, 9, 1> Vector9qreal; 0019 typedef Eigen::Hyperplane<qreal, 2> LineEquation; 0020 0021 #include <kritaimage_export.h> 0022 0023 class QRect; 0024 0025 class KRITAIMAGE_EXPORT KisPerspectiveMath 0026 { 0027 private: 0028 KisPerspectiveMath() { } 0029 public: 0030 static Matrix3qreal computeMatrixTransfo(const QPointF& topLeft1, const QPointF& topRight1, const QPointF& bottomLeft1, const QPointF& bottomRight1, const QPointF& topLeft2, const QPointF& topRight2, const QPointF& bottomLeft2, const QPointF& bottomRight2); 0031 static Matrix3qreal computeMatrixTransfoToPerspective(const QPointF& topLeft, const QPointF& topRight, const QPointF& bottomLeft, const QPointF& bottomRight, const QRect& r); 0032 static Matrix3qreal computeMatrixTransfoFromPerspective(const QRect& r, const QPointF& topLeft, const QPointF& topRight, const QPointF& bottomLeft, const QPointF& bottomRight); 0033 /// TODO: get rid of this in 2.0 0034 static inline QPointF matProd(const Matrix3qreal& m, const QPointF& p) { 0035 qreal s = qreal(1) / (p.x() * m.coeff(2, 0) + p.y() * m.coeff(2, 1) + 1.0); 0036 return QPointF((p.x() * m.coeff(0, 0) + p.y() * m.coeff(0, 1) + m.coeff(0, 2)) * s, 0037 (p.x() * m.coeff(1, 0) + p.y() * m.coeff(1, 1) + m.coeff(1, 2)) * s); 0038 } 0039 }; 0040 0041 #endif