Changeset View
Changeset View
Standalone View
Standalone View
kstars/fitsviewer/hough/houghline.h
- This file was added.
1 | /* HoughLine | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2019 Patrick Molenaar (pr_molenaar@hotmail.com) | ||||
3 | | ||||
4 | This application is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | */ | ||||
9 | | ||||
10 | #ifndef HOUGHLINE_H_ | ||||
11 | #define HOUGHLINE_H_ | ||||
12 | | ||||
13 | #include <QLineF> | ||||
14 | #include <QPointF> | ||||
15 | #include <stdio.h> | ||||
16 | #include <qmath.h> | ||||
17 | | ||||
18 | /** | ||||
19 | * @class HoughLine | ||||
20 | * Line representation for HoughTransform | ||||
21 | * Based on the java implementation found on http://vase.essex.ac.uk/software/HoughTransform | ||||
22 | * @author Patrick Molenaar | ||||
23 | * @version 1.0 | ||||
24 | */ | ||||
25 | class HoughLine : public QLineF | ||||
26 | { | ||||
27 | public: | ||||
28 | enum IntersectResult { | ||||
29 | PARALLEL, | ||||
30 | COINCIDENT, | ||||
31 | NOT_INTERESECTING, | ||||
32 | INTERESECTING | ||||
33 | }; | ||||
34 | | ||||
35 | HoughLine(double theta, double r, int width, int height, int score); | ||||
36 | virtual ~HoughLine() = default; | ||||
37 | QPointF RotatePoint(int x1, double r, double theta, int width, int height); | ||||
38 | IntersectResult Intersect(const HoughLine& other_line, QPointF& intersection); | ||||
39 | bool DistancePointLine(const QPointF& point, QPointF& intersection, double& distance); | ||||
40 | int getScore() const; | ||||
41 | double getR() const; | ||||
42 | double getTheta() const; | ||||
43 | void setTheta(const double theta); | ||||
44 | | ||||
45 | HoughLine& operator=(const HoughLine &other) | ||||
46 | { | ||||
47 | theta = other.getTheta(); | ||||
48 | r = other.getR(); | ||||
49 | score = other.getScore(); | ||||
50 | setP1(other.p1()); | ||||
51 | setP2(other.p2()); | ||||
52 | return *this; | ||||
53 | } | ||||
54 | | ||||
55 | bool operator<(const HoughLine &other) const | ||||
56 | { | ||||
57 | return (score < other.getScore()); | ||||
58 | } | ||||
59 | | ||||
60 | static bool compareByScore(const HoughLine *line1,const HoughLine *line2); | ||||
61 | static bool compareByTheta(const HoughLine *line1,const HoughLine *line2); | ||||
62 | static void getSortedTopThreeLines(QVector<HoughLine*> &houghLines, QVector<HoughLine*> &top3Lines); | ||||
63 | | ||||
64 | void printHoughLine(); | ||||
65 | void Offset(const int offsetX, const int offsetY); | ||||
66 | | ||||
67 | private: | ||||
68 | double Magnitude(const QPointF& point1, const QPointF& point2); | ||||
69 | | ||||
70 | int score; | ||||
71 | double theta; | ||||
72 | double r; | ||||
73 | QPointF beginPoint; | ||||
74 | QPointF endPoint; | ||||
75 | }; | ||||
76 | | ||||
77 | #endif |