From c4f6ff5790e468156ae3ec602a47379695302617 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 8 Jan 2016 02:17:38 +0100 Subject: [PATCH] [TASK] Step forward, step back. This is harder than expected. --- hough_machine.cpp | 77 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 10 deletions(-) diff --git a/hough_machine.cpp b/hough_machine.cpp index 3a8ae1d..252a3d0 100644 --- a/hough_machine.cpp +++ b/hough_machine.cpp @@ -120,6 +120,40 @@ class HoughMachine { this->bresenham_orientation_sector = this->getOrientationSector(end_x - start_x, end_y - start_y); // Now adapt input // Output will be adapted in setPixel() + switch(this->bresenham_orientation_sector) { + case 0: + // Going right, nothing to do here + this->bresenham(start_x, start_y, end_x, end_y); + break; + case 1: + // Going right, but more up + this->bresenham(start_y, start_x, end_y, end_x); + break; + case 2: + // Going left, but more up + this->bresenham(start_y, end_x, end_y, start_x); + break; + case 3: + // Going left + this->bresenham(end_x, start_y, start_x, end_y); + break; + case 4: + // Going left + this->bresenham(end_x, end_y, start_x, start_y); + break; + case 5: + // Going left, but more down + this->bresenham(end_y, end_x, start_y, start_x); + break; + case 6: + // Going right, but more down + this->bresenham(end_y, start_x, start_y, end_x); + break; + case 7: + // Going right + this->bresenham(start_x, end_y, end_x, start_y); + break; + } }; void bresenham(int start_x, int start_y, int end_x, int end_y) { @@ -158,34 +192,57 @@ class HoughMachine { // Do matrix multiplication double new_dx = dx * cosoct + dy * neg_sinoct; double new_dy = dx * sinoct + dy * cosoct; + int orientation_sector = 0; if(new_dy < 0) { new_dx = -new_dx; new_dy = -new_dy; + orientation_sector += 4; } - int orientation_sector; - if(new_dx >= 0 && new_dx >= new_dy) orientation_sector = 0; - if(new_dx >= 0 && new_dx < new_dy) orientation_sector = 1; - if(new_dx < 0 && -new_dx < new_dy) orientation_sector = 2; - if(new_dx < 0 && -new_dx >= new_dy) orientation_sector = 3; + if(new_dx >= 0 && new_dx >= new_dy) orientation_sector += 0; + if(new_dx >= 0 && new_dx < new_dy) orientation_sector += 1; + if(new_dx < 0 && -new_dx < new_dy) orientation_sector += 2; + if(new_dx < 0 && -new_dx >= new_dy) orientation_sector += 3; return orientation_sector; }; void setPixel(int x, int y) { 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: - break; + // Going right, nothing to do here + this->working_copy->getImage()->setPixel(x, y, color); + break; case 1: - //TODO + // Going right, but more up + this->working_copy->getImage()->setPixel(y, x, color); break; case 2: - + // Going left, but more up + this->working_copy->getImage()->setPixel(-y, x, color); break; case 3: - + // Going left + this->working_copy->getImage()->setPixel(-x, y, color); + break; + case 4: + // Going left + this->working_copy->getImage()->setPixel(-x, -y, color); + break; + case 5: + // Going left, but more down + this->working_copy->getImage()->setPixel(-y, -x, color); + break; + case 6: + // Going right, but more down + this->working_copy->getImage()->setPixel(y, -x, color); + break; + case 7: + // Going right + this->working_copy->getImage()->setPixel(x, -y, color); break; } - this->working_copy->getImage()->setPixel(x, y, color); + }; void debugShow() {