1 /* 2 Scan Tailor - Interactive post-processing tool for scanned pages. 3 Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com> 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef DEWARPING_DISTORTION_MODEL_H_ 20 #define DEWARPING_DISTORTION_MODEL_H_ 21 22 #include "Curve.h" 23 24 class QDomDocument; 25 class QDomElement; 26 class QString; 27 class QRectF; 28 class QTransform; 29 30 namespace dewarping { 31 class CylindricalSurfaceDewarper; 32 33 class DistortionModel { 34 public: 35 /** 36 * \brief Constructs a null distortion model. 37 */ 38 DistortionModel(); 39 40 explicit DistortionModel(const QDomElement& el); 41 42 QDomElement toXml(QDomDocument& doc, const QString& name) const; 43 44 /** 45 * Returns true if the model is not null and in addition meets certain 46 * criteria, like curve endpoints forming a convex quadrilateral. 47 */ 48 bool isValid() const; 49 setTopCurve(const Curve & curve)50 void setTopCurve(const Curve& curve) { m_topCurve = curve; } 51 setBottomCurve(const Curve & curve)52 void setBottomCurve(const Curve& curve) { m_bottomCurve = curve; } 53 topCurve()54 const Curve& topCurve() const { return m_topCurve; } 55 bottomCurve()56 const Curve& bottomCurve() const { return m_bottomCurve; } 57 58 bool matches(const DistortionModel& other) const; 59 60 /** 61 * Model domain is a rectangle in output image coordinates that 62 * will be mapped to our curved quadrilateral. 63 */ 64 QRectF modelDomain(const CylindricalSurfaceDewarper& dewarper, 65 const QTransform& to_output, 66 const QRectF& output_content_rect) const; 67 68 private: 69 /** 70 * \return The bounding box of the shape formed by two curves 71 * and vertical segments connecting them. 72 * \param transform Transforms from the original image coordinates 73 * where curve points are defined, to the desired coordinate 74 * system, for example to output image coordinates. 75 */ 76 QRectF boundingBox(const QTransform& transform) const; 77 78 Curve m_topCurve; 79 Curve m_bottomCurve; 80 }; 81 } // namespace dewarping 82 #endif // ifndef DEWARPING_DISTORTION_MODEL_H_ 83