From 07c350fe8e9f8a3d7ad7d35d2a3e0717f5e9b5d5 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 8 Jan 2016 01:37:07 +0100 Subject: [PATCH] [TASK] Add very very basic bresenham algo. TODO: enhance! --- hough_machine.cpp | 31 +++++++++++++++++++++++++++++++ imageviewer-qt4.cpp | 11 +++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/hough_machine.cpp b/hough_machine.cpp index bf38c0a..fe49400 100644 --- a/hough_machine.cpp +++ b/hough_machine.cpp @@ -109,6 +109,37 @@ class HoughMachine { void drawLines(int n) { // TODO: Sort stuff in hough_arr by value, get the n top values and draw them using bresenham. + // put all of them into a custom struct (a, r, value). Now sort these fuckers! + + + }; + + void drawLineBresenham(int start_x, int start_y, int end_x, int end_y) { + int x, y; + int delta_x, delta_y; + int d; + int delta_ne, delta_e; + x = start_x; + y = start_y; + delta_x = end_x - start_x; + delta_y = end_y - start_y; + delta_ne = 2 * (delta_y - delta_x); + delta_e = 2 * delta_y; + d = 2 * delta_y - delta_x; + this->setPixel(x, y); + while(x < end_x) { + if(d >= 0) { + d += delta_ne; x++; y++; + } else { + d += delta_e; x++; + } + this->setPixel(x, y); + } + }; + + void setPixel(int x, int y) { + int color = QColor::fromRgb(0, 255, 0).rgb(); + this->working_copy->getImage()->setPixel(x, y, color); }; void debugShow() { diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index 871ff53..35b92d9 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -136,9 +136,16 @@ void ImageViewer::saveToOriginal() { */ void ImageViewer::drawBlackLine() { if(original->getImage() != NULL) { - for(int i=0;igetImage()->width(),working_copy->getImage()->height());i++) { + /*for(int i=0;igetImage()->width(),working_copy->getImage()->height());i++) { working_copy->getImage()->setPixel(i,i,0); - } + }*/ + HoughMachine* hm = new HoughMachine(original, working_copy); + hm->drawLineBresenham(10, 10, 20, 20); + hm->drawLineBresenham(10, 10, 20, 10); + hm->drawLineBresenham(10, 10, 10, 20); + hm->drawLineBresenham(10, 10, 15, 20); + hm->drawLineBresenham(10, 10, 20, 15); + delete hm; updateImageDisplay(); logFile << "Black line drawn." << std::endl; renewLogging();