[TASK] Fix bresenham.
This commit is contained in:
parent
c4f6ff5790
commit
4ce9e0e6c2
@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
#include "lazy_image.cpp"
|
#include "lazy_image.cpp"
|
||||||
|
|
||||||
|
struct houghdot {
|
||||||
|
double point;
|
||||||
|
double theta;
|
||||||
|
double r;
|
||||||
|
};
|
||||||
|
|
||||||
class HoughMachine {
|
class HoughMachine {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -85,11 +91,9 @@ class HoughMachine {
|
|||||||
pixel.getHsl(&h, &s, &l);
|
pixel.getHsl(&h, &s, &l);
|
||||||
if(this->matching_threshold > 0) {
|
if(this->matching_threshold > 0) {
|
||||||
int threshold = this->matching_threshold;
|
int threshold = this->matching_threshold;
|
||||||
std::cout << "Comparing " << l << " < " << threshold << std::endl;
|
|
||||||
if(l < threshold) this->doPixel(u, v);
|
if(l < threshold) this->doPixel(u, v);
|
||||||
} else {
|
} else {
|
||||||
int threshold = -this->matching_threshold;
|
int threshold = -this->matching_threshold;
|
||||||
std::cout << "Comparing " << l << " > " << threshold << std::endl;
|
|
||||||
if(l > threshold) this->doPixel(u, v);
|
if(l > threshold) this->doPixel(u, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,14 +172,14 @@ class HoughMachine {
|
|||||||
delta_ne = 2 * (delta_y - delta_x);
|
delta_ne = 2 * (delta_y - delta_x);
|
||||||
delta_e = 2 * delta_y;
|
delta_e = 2 * delta_y;
|
||||||
d = 2 * delta_y - delta_x;
|
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) {
|
while(x < end_x) {
|
||||||
if(d >= 0) {
|
if(d >= 0) {
|
||||||
d += delta_ne; x++; y++;
|
d += delta_ne; x++; y++;
|
||||||
} else {
|
} else {
|
||||||
d += delta_e; x++;
|
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;
|
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();
|
int color = QColor::fromRgb(0, 255, 0).rgb();
|
||||||
//TODO: Fix this! This has to happen relative to the center point! :|
|
//TODO: Fix this! This has to happen relative to the center point! :|
|
||||||
switch(this->bresenham_orientation_sector) {
|
switch(this->bresenham_orientation_sector) {
|
||||||
case 0:
|
case 0:
|
||||||
// Going right, nothing to do here
|
// 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;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// Going right, but more up
|
// 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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Going left, but more up
|
// 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;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Going left
|
// Going left
|
||||||
this->working_copy->getImage()->setPixel(-x, y, color);
|
this->working_copy->getImage()->setPixel(start_x - dx, start_y + dy, color);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// Going left
|
// Going left
|
||||||
this->working_copy->getImage()->setPixel(-x, -y, color);
|
this->working_copy->getImage()->setPixel(start_x - dx, start_y - dy, color);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// Going left, but more down
|
// 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;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
// Going right, but more down
|
// 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;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
// Going right
|
// Going right
|
||||||
this->working_copy->getImage()->setPixel(x, -y, color);
|
this->working_copy->getImage()->setPixel(start_x + dx, start_y - dy, color);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user