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