From 0468c478584f556dd71f305c78864e222f670ecb Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 8 Jan 2016 01:57:16 +0100 Subject: [PATCH] [TASK] I don't know right now, but i need something like this. :| --- hough_machine.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/hough_machine.cpp b/hough_machine.cpp index fe49400..b770026 100644 --- a/hough_machine.cpp +++ b/hough_machine.cpp @@ -26,6 +26,7 @@ class HoughMachine { int* hough_arr; int matching_threshold; + int bresenham_orientation_sector; public: HoughMachine(LazyImage* original, LazyImage* working_copy) { @@ -50,6 +51,7 @@ class HoughMachine { this->hough_arr = NULL; } this->matching_threshold = 0; + this->bresenham_orientation_sector = 0; }; void setMatchingThreshold(int matching_threshold) { @@ -113,8 +115,14 @@ class HoughMachine { }; - + void drawLineBresenham(int start_x, int start_y, int end_x, int end_y) { + this->bresenham_orientation_sector = this->getOrientationSector(end_x - start_x, end_y - start_y); + // Now adapt input + // Output will be adapted in setPixel() + }; + + void bresenham(int start_x, int start_y, int end_x, int end_y) { int x, y; int delta_x, delta_y; int d; @@ -137,8 +145,46 @@ class HoughMachine { } }; + int getOrientationSector(double dx, double dy) { + // Matrix multiplication with rotation matrix pi/8 + // + // cos(pi/8) -sin(pi/8) + // sin(pi/8) cos(pi/8) + // TODO: Move these somewhere else! + double octangle = M_PI/8; + double cosoct = cos(octangle); + double sinoct = sin(octangle); + double neg_sinoct = -sinoct; + // Do matrix multiplication + double new_dx = dx * cosoct + dy * neg_sinoct; + double new_dy = dx * sinoct + dy * cosoct; + if(new_dy < 0) { + new_dx = -new_dx; + new_dy = -new_dy; + } + 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_dy >= new_dy) orientation_sector = 3; + return orientation_sector; + }; + void setPixel(int x, int y) { int color = QColor::fromRgb(0, 255, 0).rgb(); + switch(this->bresenham_orientation_sector) { + case 0: + break; + case 1: + //TODO + break; + case 2: + + break; + case 3: + + break; + } this->working_copy->getImage()->setPixel(x, y, color); };