File indexing completed on 2024-04-28 03:43:52
0001 /* 0002 SPDX-FileCopyrightText: 2019 Patrick Molenaar <pr_molenaar@hotmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef HOUGHLINE_H_ 0008 #define HOUGHLINE_H_ 0009 0010 #include <QLineF> 0011 #include <QPointF> 0012 #include <stdio.h> 0013 #include <qmath.h> 0014 0015 /** 0016 * @class HoughLine 0017 * Line representation for HoughTransform 0018 * Based on the java implementation found on http://vase.essex.ac.uk/software/HoughTransform 0019 * @author Patrick Molenaar 0020 * @version 1.0 0021 */ 0022 class HoughLine : public QLineF 0023 { 0024 public: 0025 enum IntersectResult { 0026 PARALLEL, 0027 COINCIDENT, 0028 NOT_INTERESECTING, 0029 INTERESECTING 0030 }; 0031 0032 HoughLine(double theta, double r, int width, int height, int score); 0033 virtual ~HoughLine() = default; 0034 QPointF RotatePoint(int x1, double r, double theta, int width, int height); 0035 IntersectResult Intersect(const HoughLine& other_line, QPointF& intersection); 0036 bool DistancePointLine(const QPointF& point, QPointF& intersection, double& distance); 0037 int getScore() const; 0038 double getR() const; 0039 double getTheta() const; 0040 void setTheta(const double theta); 0041 0042 HoughLine& operator=(const HoughLine &other) 0043 { 0044 theta = other.getTheta(); 0045 r = other.getR(); 0046 score = other.getScore(); 0047 setP1(other.p1()); 0048 setP2(other.p2()); 0049 return *this; 0050 } 0051 0052 bool operator<(const HoughLine &other) const 0053 { 0054 return (score < other.getScore()); 0055 } 0056 0057 static bool compareByScore(const HoughLine *line1,const HoughLine *line2); 0058 static bool compareByTheta(const HoughLine *line1,const HoughLine *line2); 0059 static void getSortedTopThreeLines(QVector<HoughLine*> &houghLines, QVector<HoughLine*> &top3Lines); 0060 0061 void printHoughLine(); 0062 void Offset(const int offsetX, const int offsetY); 0063 0064 private: 0065 double Magnitude(const QPointF& point1, const QPointF& point2); 0066 0067 int score; 0068 double theta; 0069 double r; 0070 QPointF beginPoint; 0071 QPointF endPoint; 0072 }; 0073 0074 #endif