[TASK] Add very very basic bresenham algo. TODO: enhance!
This commit is contained in:
parent
6e9cffa5e9
commit
07c350fe8e
|
@ -109,6 +109,37 @@ class HoughMachine {
|
||||||
void drawLines(int n) {
|
void drawLines(int n) {
|
||||||
// TODO: Sort stuff in hough_arr by value, get the n top values and draw them using bresenham.
|
// 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() {
|
void debugShow() {
|
||||||
|
|
|
@ -136,9 +136,16 @@ void ImageViewer::saveToOriginal() {
|
||||||
*/
|
*/
|
||||||
void ImageViewer::drawBlackLine() {
|
void ImageViewer::drawBlackLine() {
|
||||||
if(original->getImage() != NULL) {
|
if(original->getImage() != NULL) {
|
||||||
for(int i=0;i<std::min(working_copy->getImage()->width(),working_copy->getImage()->height());i++) {
|
/*for(int i=0;i<std::min(working_copy->getImage()->width(),working_copy->getImage()->height());i++) {
|
||||||
working_copy->getImage()->setPixel(i,i,0);
|
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();
|
updateImageDisplay();
|
||||||
logFile << "Black line drawn." << std::endl;
|
logFile << "Black line drawn." << std::endl;
|
||||||
renewLogging();
|
renewLogging();
|
||||||
|
|
Loading…
Reference in New Issue