11#include <fits_debug.h>
23 setP1(RotatePoint(0, r, theta, width, height));
24 setP2(RotatePoint(width - 1, r, theta, width, height));
27QPointF HoughLine::RotatePoint(
int x1,
double r,
double theta,
int width,
int height)
31 hx = qFloor((width + 1) / 2.0);
32 hy = qFloor((height + 1) / 2.0);
34 double sinAngle = qSin(-theta);
35 double cosAngle = qCos(-theta);
42 double xnew =
x2 * cosAngle -
y2 * sinAngle;
43 double ynew =
x2 * sinAngle +
y2 * cosAngle;
52int HoughLine::getScore()
const
57double HoughLine::getR()
const
62double HoughLine::getTheta()
const
67void HoughLine::setTheta(
const double theta)
74 return (line1->getScore() < line2->getScore());
79 return (line1->getTheta() < line2->getTheta());
82void HoughLine::printHoughLine()
84 qCDebug(KSTARS_FITS) <<
"Houghline: [score: " << score <<
", r: " << r <<
", theta: " << theta <<
" [rad]="
85 << (theta * 180.0 / M_PI) <<
" [deg], p1: " <<
p1().
x() <<
", " <<
p1().
y() <<
", p2: "
86 <<
p2().
x() <<
", " <<
p2().
y() <<
"]";
96 double denom = ((other_line.
p2().y() - other_line.
p1().
y()) * (
p2().x() -
p1().x())) -
97 ((other_line.
p2().x() - other_line.
p1().
x()) * (
p2().y() -
p1().y()));
99 double nume_a = ((other_line.
p2().x() - other_line.
p1().
x()) * (
p1().y() - other_line.
p1().
y())) -
100 ((other_line.
p2().y() - other_line.
p1().
y()) * (
p1().x() - other_line.
p1().
x()));
102 double nume_b = ((
p2().
x() -
p1().
x()) * (
p1().
y() - other_line.
p1().
y())) -
103 ((
p2().y() -
p1().y()) * (
p1().x() - other_line.
p1().
x()));
107 if(nume_a == 0.0f && nume_b == 0.0f)
114 double ua = nume_a / denom;
115 double ub = nume_b / denom;
117 if(ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f)
120 intersection.
setX(qreal(
p1().x() + ua * (
p2().x() -
p1().x())));
121 intersection.
setY(qreal(
p1().y() + ua * (
p2().y() -
p1().y())));
122 return INTERESECTING;
125 return NOT_INTERESECTING;
128double HoughLine::Magnitude(
const QPointF& point1,
const QPointF& point2)
130 QPointF vector = point2 - point1;
131 return qSqrt(vector.
x() * vector.
x() + vector.
y() * vector.
y());
134bool HoughLine::DistancePointLine(
const QPointF& point,
QPointF& intersection,
double& distance)
136 double lineMag =
length();
138 double U = qreal((((point.
x() -
p1().x()) * (
p2().x() -
p1().x())) +
139 ((point.
y() -
p1().y()) * (
p2().y() -
p1().y()))) /
140 (lineMag * lineMag));
142 if (U < 0.0 || U > 1.0) {
146 intersection.
setX(
p1().x() + U * (
p2().x() -
p1().x()));
147 intersection.
setY(
p1().y() + U * (
p2().y() -
p1().y()));
149 distance = Magnitude(point, intersection);
154void HoughLine::Offset(
const int offsetX,
const int offsetY)
156 setP1(QPointF(
p1().x() + offsetX,
p1().y() + offsetY));
157 setP2(QPointF(
p2().x() + offsetX,
p2().y() + offsetY));
164 std::sort(houghLines.
begin(), houghLines.
end(), HoughLine::compareByScore);
167 top3Lines = houghLines.
mid(0, 3);
172 double thetaR = lineR->getTheta();
173 double thetaG = lineG->getTheta();
174 double thetaB = lineB->getTheta();
176 double bahtinovMaskAngle = qDegreesToRadians(20.0 + 5.0);
177 double dGR = thetaR - thetaG;
178 double dBG = thetaB - thetaG;
179 double dBR = thetaB - thetaR;
180 if (dGR > bahtinovMaskAngle && dBR > bahtinovMaskAngle) {
184 lineR->setTheta(thetaR);
186 if (dBR > bahtinovMaskAngle && dBG > bahtinovMaskAngle) {
190 lineB->setTheta(thetaB);
192 if (dGR > bahtinovMaskAngle && dBG > bahtinovMaskAngle) {
196 lineG->setTheta(thetaG);
199 std::sort(top3Lines.
begin(),top3Lines.
end(), HoughLine::compareByTheta);
Line representation for HoughTransform Based on the java implementation found on http://vase....
IntersectResult Intersect(const HoughLine &other_line, QPointF &intersection)
Sources for intersection and distance calculations came from http://paulbourke.net/geometry/pointline...
HoughLine(double theta, double r, int width, int height, int score)
Initialises the hough line.
int distance(const GeoCoordinates &coord1, const GeoCoordinates &coord2)
qreal length() const const
void setP1(const QPointF &p1)
void setP2(const QPointF &p2)
QList< T > mid(qsizetype pos, qsizetype length) const const