[TASK] Switch to other bresenham implementation for now.
This commit is contained in:
		
							parent
							
								
									4ce9e0e6c2
								
							
						
					
					
						commit
						85f2dd2824
					
				| @ -120,66 +120,66 @@ 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); |     void setPixelDebug(int x, int y, int color=0) { | ||||||
|       // Now adapt input
 |       int our_color = QColor::fromRgb(0, 255, 0).rgb(); | ||||||
|       // Output will be adapted in setPixel()
 |       if(color == 0) color = our_color; | ||||||
|       switch(this->bresenham_orientation_sector) { |       std::cout << " --> SET (" << x << ", " << y << ")" << std::endl; | ||||||
| 	case 0: |       this->working_copy->getImage()->setPixel(x, y, color); | ||||||
| 	  // Going right, nothing to do here
 |     }; | ||||||
| 	  this->bresenham(start_x, start_y, end_x, end_y); |      | ||||||
| 	  break;  |     void otherBresenham(int x, int x2, int y, int y2) { | ||||||
| 	case 1: |       int width = x2 - x; | ||||||
| 	  // Going right, but more up
 |       int height = y2 - y; | ||||||
| 	  this->bresenham(start_y, start_x, end_y, end_x); |       int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0; | ||||||
| 	  break; |       dx1 = (width < 0) ? -1 : 1; | ||||||
| 	case 2: |       dy1 = (height < 0) ? -1 : 1; | ||||||
| 	  // Going left, but more up
 |       dx2 = (width < 0) ? -1 : 1; | ||||||
| 	  this->bresenham(start_y, end_x, end_y, start_x); |       int longest = abs(width); | ||||||
| 	  break; |       int shortest = abs(height); | ||||||
| 	case 3: |       if(longest <= shortest) { | ||||||
| 	  // Going left
 |         longest = abs(height); | ||||||
| 	  this->bresenham(end_x, start_y, start_x, end_y); |         shortest = abs(width); | ||||||
| 	  break; |         dy2 = (height < 0) ? -1 : 1; | ||||||
| 	case 4: |         dx2 = 0;             | ||||||
| 	  // Going left
 |       } | ||||||
| 	  this->bresenham(end_x, end_y, start_x, start_y); |       int numerator = longest / 2; | ||||||
| 	  break;  |       for(int i=0; i<=longest; i++) { | ||||||
| 	case 5: |         this->setPixelDebug(x, y); | ||||||
| 	  // Going left, but more down
 |         numerator += shortest; | ||||||
| 	  this->bresenham(end_y, end_x, start_y, start_x); |         if(numerator >= longest) { | ||||||
| 	  break; |           numerator -= longest; | ||||||
| 	case 6: |           x += dx1; | ||||||
| 	  // Going right, but more down
 |           y += dy1; | ||||||
| 	  this->bresenham(end_y, start_x, start_y, end_x); |         } else { | ||||||
| 	  break; |           x += dx2; | ||||||
| 	case 7: |           y += dy2; | ||||||
| 	  // Going right
 |         } | ||||||
| 	  this->bresenham(start_x, end_y, end_x, start_y); |  | ||||||
| 	  break; |  | ||||||
|       }       |       }       | ||||||
|     }; |     }; | ||||||
|      |      | ||||||
|     void bresenham(int start_x, int start_y, int end_x, int end_y) { |     void debugShow() { | ||||||
|       int x, y; |       std::cout << "Dimensions: " << this->n_ang << " x " << this->n_rad << " | " << std::endl; | ||||||
|       int delta_x, delta_y; |       int max_value = 0; | ||||||
|       int d; |       for(int i=0; i<this->n_ang*this->n_rad; i++) { | ||||||
|       int delta_ne, delta_e; | 	int current_value = this->hough_arr[i]; | ||||||
|       x = start_x; | 	if(current_value > max_value) max_value = current_value; | ||||||
|       y = start_y; |       } | ||||||
|       delta_x = end_x - start_x; |        | ||||||
|       delta_y = end_y - start_y; |       for(int x=0; x<this->n_ang; x++) { | ||||||
|       delta_ne = 2 * (delta_y - delta_x); | 	for(int y=0; y<this->n_rad; y++) { | ||||||
|       delta_e = 2 * delta_y; | 	  int value = qRound(255.0*this->hough_arr[x*this->n_ang+y] / max_value); | ||||||
|       d = 2 * delta_y - delta_x; | 	  if(value < 0) { | ||||||
|       this->setPixel(start_x, start_y, x - start_x, y - start_y); | 	    std::cout << value << std::endl; | ||||||
|       while(x < end_x) { | 	    value = 0; | ||||||
| 	if(d >= 0) { | 	  }     | ||||||
| 	  d += delta_ne; x++; y++; | 	  if(value > 255) { | ||||||
| 	} else { | 	    std::cout << value << std::endl; | ||||||
| 	  d += delta_e; x++; | 	    value = 255; | ||||||
|  | 	  } | ||||||
|  | 	  int color = QColor::fromRgb(value, value, value).rgb(); | ||||||
|  | 	  this->working_copy->getImage()->setPixel(x,y,color); | ||||||
| 	} | 	} | ||||||
|         this->setPixel(start_x, start_y, x - start_x, y - start_y); |  | ||||||
|       } |       } | ||||||
|     }; |     }; | ||||||
|      |      | ||||||
| @ -209,71 +209,120 @@ class HoughMachine { | |||||||
|       return orientation_sector; |       return orientation_sector; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     void setPixel(int start_x, int start_y, int dx, int dy) { |     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); | ||||||
|  |       std::cout << "START LINE: (" << start_x << ", " << start_y << ") -> (" << end_x << ", " << end_y << ") - O: " << this->bresenham_orientation_sector << std::endl; | ||||||
|  |       // other implementation for now.
 | ||||||
|  |       this->otherBresenham(start_x, end_x, start_y, end_y); | ||||||
|  |       // Now adapt input
 | ||||||
|  |       // Output will be adapted in setPixel()
 | ||||||
|  |       /*switch(this->bresenham_orientation_sector) {
 | ||||||
|  | 	case 0: | ||||||
|  | 	  // Going right, nothing to do here
 | ||||||
|  | 	  this->bresenham(start_x, start_y, end_x, end_y); | ||||||
|  | 	  break;  | ||||||
|  | 	case 1: | ||||||
|  | 	  // Going right, but more up
 | ||||||
|  | 	  this->bresenham(start_y, start_x, end_y, end_x); | ||||||
|  | 	  break; | ||||||
|  | 	case 2: | ||||||
|  | 	  // Going left, but more up
 | ||||||
|  | 	  this->bresenham(start_y, end_x, end_y, start_x); | ||||||
|  | 	  break; | ||||||
|  | 	case 3: | ||||||
|  | 	  // Going left
 | ||||||
|  | 	  this->bresenham(end_x, start_y, start_x, end_y); | ||||||
|  | 	  break; | ||||||
|  | 	case 4: | ||||||
|  | 	  // Going left
 | ||||||
|  | 	  this->bresenham(end_x, end_y, start_x, start_y); | ||||||
|  | 	  break;  | ||||||
|  | 	case 5: | ||||||
|  | 	  // Going left, but more down
 | ||||||
|  | 	  this->bresenham(end_y, end_x, start_y, start_x); | ||||||
|  | 	  break; | ||||||
|  | 	case 6: | ||||||
|  | 	  // Going right, but more down
 | ||||||
|  | 	  this->bresenham(start_x, end_y, end_x, start_y); | ||||||
|  | 	  break; | ||||||
|  | 	case 7: | ||||||
|  | 	  // Going right
 | ||||||
|  | 	  this->bresenham(start_x, end_y, end_x, start_y); | ||||||
|  | 	  break; | ||||||
|  |       }*/ | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     /*void bresenham(int start_x, int start_y, int end_x, int end_y) {
 | ||||||
|  |       std::cout << "BRESENHAM START LINE: (" << start_x << ", " << start_y << ") -> (" << end_x << ", " << end_y << ")" << std::endl; | ||||||
|  |       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(start_x, start_y, x, y); | ||||||
|  |       while(x < end_x) { | ||||||
|  | 	if(d >= 0) { | ||||||
|  | 	  d += delta_ne; x++; y++; | ||||||
|  | 	} else { | ||||||
|  | 	  d += delta_e; x++; | ||||||
|  | 	} | ||||||
|  |         this->setPixel(start_x, start_y, x, y); | ||||||
|  |       } | ||||||
|  |       std::cout << std::endl; | ||||||
|  |     };*/ | ||||||
|  |      | ||||||
|  |     /*void setPixel(int start_x, int start_y, int dx, int dy) {
 | ||||||
|  |       std::cout << "setPixel(" << start_x << ", " << start_y << ", " << dx << ", " << dy << ")" << std::endl; | ||||||
|  |       if(dx > start_x) dx = dx - start_x; | ||||||
|  |       else dx = start_x - dx; | ||||||
|  |       if(dy > start_y) dy = dy - start_y; | ||||||
|  |       else dy = start_y - dy; | ||||||
|  |       std::cout << " --> dx: " << dx << ", dy: " << dy << "" << std::endl;  | ||||||
|  |        | ||||||
|       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(start_x + dx, start_y + dy, color); | 	  this->setPixelDebug(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(start_x + dy, start_y + dx, color); | 	  this->setPixelDebug(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(start_x - dy, start_y + dx, color); | 	  this->setPixelDebug(start_x - dy, start_y + dx, color); | ||||||
| 	  break; | 	  break; | ||||||
| 	case 3: | 	case 3: | ||||||
| 	  // Going left
 | 	  // Going left
 | ||||||
| 	  this->working_copy->getImage()->setPixel(start_x - dx, start_y + dy, color); | 	  this->setPixelDebug(start_x - dx, start_y + dy, color); | ||||||
| 	  break; | 	  break; | ||||||
| 	case 4: | 	case 4: | ||||||
| 	  // Going left
 | 	  // Going left
 | ||||||
| 	  this->working_copy->getImage()->setPixel(start_x - dx, start_y - dy, color); | 	  this->setPixelDebug(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(start_x - dy, start_y - dx, color); | 	  this->setPixelDebug(start_x + dy, start_y + dx, color); // ok
 | ||||||
| 	  break; | 	  break; | ||||||
| 	case 6: | 	case 6: | ||||||
| 	  // Going right, but more down
 | 	  // Going right, but more down
 | ||||||
| 	  this->working_copy->getImage()->setPixel(start_x + dy, start_y - dx, color); | 	  this->setPixelDebug(start_x + dy, start_y - dx, color); // ?
 | ||||||
| 	  break; | 	  break; | ||||||
| 	case 7: | 	case 7: | ||||||
| 	  // Going right
 | 	  // Going right
 | ||||||
| 	  this->working_copy->getImage()->setPixel(start_x + dx, start_y - dy, color); | 	  this->setPixelDebug(start_x + dx, start_y - dy, color); | ||||||
| 	  break; | 	  break; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|     }; |     };*/ | ||||||
|      |  | ||||||
|     void debugShow() { |  | ||||||
|       std::cout << "Dimensions: " << this->n_ang << " x " << this->n_rad << " | " << std::endl; |  | ||||||
|        |  | ||||||
|       int max_value = 0; |  | ||||||
|       for(int i=0; i<this->n_ang*this->n_rad; i++) { |  | ||||||
| 	int current_value = this->hough_arr[i]; |  | ||||||
| 	if(current_value > max_value) max_value = current_value; |  | ||||||
|       } |  | ||||||
|        |  | ||||||
|       for(int x=0; x<this->n_ang; x++) { |  | ||||||
| 	for(int y=0; y<this->n_rad; y++) { |  | ||||||
| 	  int value = qRound(255.0*this->hough_arr[x*this->n_ang+y] / max_value); |  | ||||||
| 	  if(value < 0) { |  | ||||||
| 	    std::cout << value << std::endl; |  | ||||||
| 	    value = 0; |  | ||||||
| 	  }     |  | ||||||
| 	  if(value > 255) { |  | ||||||
| 	    std::cout << value << std::endl; |  | ||||||
| 	    value = 255; |  | ||||||
| 	  } |  | ||||||
| 	  int color = QColor::fromRgb(value, value, value).rgb(); |  | ||||||
| 	  this->working_copy->getImage()->setPixel(x,y,color); |  | ||||||
| 	} |  | ||||||
|       } |  | ||||||
|     }; |  | ||||||
| 
 | 
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -140,11 +140,17 @@ void ImageViewer::drawBlackLine() { | |||||||
|       working_copy->getImage()->setPixel(i,i,0); |       working_copy->getImage()->setPixel(i,i,0); | ||||||
|     }*/ |     }*/ | ||||||
|     HoughMachine* hm = new HoughMachine(original, working_copy); |     HoughMachine* hm = new HoughMachine(original, working_copy); | ||||||
|     hm->drawLineBresenham(10, 10, 20, 20); |     //star centered around 20/20
 | ||||||
|     hm->drawLineBresenham(10, 10, 20, 10); |     hm->drawLineBresenham(20, 20, 10, 10); | ||||||
|     hm->drawLineBresenham(10, 10, 10, 20); |     hm->drawLineBresenham(20, 20, 20, 10); | ||||||
|     hm->drawLineBresenham(10, 10, 15, 20); |     hm->drawLineBresenham(20, 20, 30, 10); | ||||||
|     hm->drawLineBresenham(10, 10, 20, 15); |     hm->drawLineBresenham(20, 20, 30, 20); | ||||||
|  |     hm->drawLineBresenham(20, 20, 30, 30); | ||||||
|  |     hm->drawLineBresenham(20, 20, 20, 30); | ||||||
|  |     hm->drawLineBresenham(20, 20, 10, 30); | ||||||
|  |     hm->drawLineBresenham(20, 20, 10, 20); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     delete hm; |     delete hm; | ||||||
|     updateImageDisplay(); |     updateImageDisplay(); | ||||||
|     logFile << "Black line drawn." << std::endl; |     logFile << "Black line drawn." << std::endl; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user