From 4ce9e0e6c2b7c0e817cd306009dcb24f36fa5a86 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 8 Jan 2016 12:28:17 +0100 Subject: [PATCH] [TASK] Fix bresenham. --- hough_machine.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/hough_machine.cpp b/hough_machine.cpp index 252a3d0..bf701d5 100644 --- a/hough_machine.cpp +++ b/hough_machine.cpp @@ -11,6 +11,12 @@ #include "lazy_image.cpp" +struct houghdot { + double point; + double theta; + double r; +}; + class HoughMachine { private: @@ -85,11 +91,9 @@ class HoughMachine { pixel.getHsl(&h, &s, &l); if(this->matching_threshold > 0) { int threshold = this->matching_threshold; - std::cout << "Comparing " << l << " < " << threshold << std::endl; if(l < threshold) this->doPixel(u, v); } else { int threshold = -this->matching_threshold; - std::cout << "Comparing " << l << " > " << threshold << std::endl; if(l > threshold) this->doPixel(u, v); } } @@ -168,14 +172,14 @@ class HoughMachine { delta_ne = 2 * (delta_y - delta_x); delta_e = 2 * delta_y; d = 2 * delta_y - delta_x; - this->setPixel(x, y); + this->setPixel(start_x, start_y, x - start_x, y - start_y); while(x < end_x) { if(d >= 0) { d += delta_ne; x++; y++; } else { d += delta_e; x++; } - this->setPixel(x, y); + this->setPixel(start_x, start_y, x - start_x, y - start_y); } }; @@ -205,41 +209,41 @@ class HoughMachine { return orientation_sector; }; - void setPixel(int x, int y) { + void setPixel(int start_x, int start_y, int dx, int dy) { int color = QColor::fromRgb(0, 255, 0).rgb(); //TODO: Fix this! This has to happen relative to the center point! :| switch(this->bresenham_orientation_sector) { case 0: // Going right, nothing to do here - this->working_copy->getImage()->setPixel(x, y, color); + this->working_copy->getImage()->setPixel(start_x + dx, start_y + dy, color); break; case 1: // Going right, but more up - this->working_copy->getImage()->setPixel(y, x, color); + this->working_copy->getImage()->setPixel(start_x + dy, start_y + dx, color); break; case 2: // Going left, but more up - this->working_copy->getImage()->setPixel(-y, x, color); + this->working_copy->getImage()->setPixel(start_x - dy, start_y + dx, color); break; case 3: // Going left - this->working_copy->getImage()->setPixel(-x, y, color); + this->working_copy->getImage()->setPixel(start_x - dx, start_y + dy, color); break; case 4: // Going left - this->working_copy->getImage()->setPixel(-x, -y, color); + this->working_copy->getImage()->setPixel(start_x - dx, start_y - dy, color); break; case 5: // Going left, but more down - this->working_copy->getImage()->setPixel(-y, -x, color); + this->working_copy->getImage()->setPixel(start_x - dy, start_y - dx, color); break; case 6: // Going right, but more down - this->working_copy->getImage()->setPixel(y, -x, color); + this->working_copy->getImage()->setPixel(start_x + dy, start_y - dx, color); break; case 7: // Going right - this->working_copy->getImage()->setPixel(x, -y, color); + this->working_copy->getImage()->setPixel(start_x + dx, start_y - dy, color); break; }