/* Draws the outline of a blob in the specified color. * @param b the blob * @param c the color to paint */ void Ball::drawBlob(Blob b, int c) { #ifdef OFFLINE thresh->drawLine(b.getLeftTopX(), b.getLeftTopY(), b.getRightTopX(), b.getRightTopY(), c); thresh->drawLine(b.getLeftTopX(), b.getLeftTopY(), b.getLeftBottomX(), b.getLeftBottomY(), c); thresh->drawLine(b.getLeftBottomX(), b.getLeftBottomY(), b.getRightBottomX(), b.getRightBottomY(), c); thresh->drawLine(b.getRightTopX(), b.getRightTopY(), b.getRightBottomX(), b.getRightBottomY(), c); #endif }
/* Print debugging information for a blob. * @param b the blob */ void Robots::printBlob(Blob b) { #if defined OFFLINE cout << "Outputting blob" << endl; cout << b.getLeftTopX() << " " << b.getLeftTopY() << " " << b.getRightTopX() << " " << b.getRightTopY() << endl; cout << b.getLeftBottomX() << " " << b.getLeftBottomY() << " " << b.getRightBottomX() << " " << b.getRightBottomY() << endl; #endif }
/** * Update the robot values from the blob * * @param b The blob to update our object from. */ void VisualRobot::updateRobot(Blob b) { setLeftTopX(b.getLeftTopX()); setLeftTopY(b.getLeftTopY()); setLeftBottomX(b.getLeftBottomX()); setLeftBottomY(b.getLeftBottomY()); setRightTopX(b.getRightTopX()); setRightTopY(b.getRightTopY()); setRightBottomX(b.getRightBottomX()); setRightBottomY(b.getRightBottomY()); setX(b.getLeftTopX()); setY(b.getLeftTopY()); setWidth(dist(b.getRightTopX(), b.getRightTopY(), b.getLeftTopX(), b.getLeftTopY())); setHeight(dist(b.getLeftTopX(), b.getLeftTopY(), b.getLeftBottomX(), b.getLeftBottomY())); setCenterX(getLeftTopX() + ROUND2(getWidth() / 2)); setCenterY(getRightTopY() + ROUND2(getHeight() / 2)); setDistance(1); }
int Ball::ballNearGreen(Blob b) { const int EXTRA_LINES = 6; // first check the bottom int w = b.width(); int h = b.height(); int where = NOGREEN; if (greenCheck(b)) where = where * GREENBELOW; // now try the sides - happily the ball is round so we don't have to worry // about scan angles int x = b.getLeftTopX(); int y = b.getLeftTopY(); for (int i = 0; i < h && y + i < IMAGE_HEIGHT && where % GREENLEFT != 0; i= i+2) { for (int j =-1; j < EXTRA_LINES && x + j > -1 && where % GREENLEFT != 0; j++) { if (thresh->thresholded[i+y][x - j] == GREEN) { where = where * GREENLEFT; } } } for (int i = 0; i < w && x + i < IMAGE_WIDTH && where % GREENABOVE != 0; i= i+2) { for (int j = 0; j < EXTRA_LINES && y - j > 0 && where % GREENABOVE != 0; j++) { if (thresh->thresholded[i+y][j+x] == GREEN) { where = where * GREENABOVE; } } } x = b.getRightTopX(); y = b.getRightTopY(); for (int i = 0; i < h && y + i < IMAGE_HEIGHT && where % GREENRIGHT != 0; i= i+2) { for (int j = 0; j < EXTRA_LINES && x + j < IMAGE_WIDTH && where % GREENRIGHT != 0; j++) { if (thresh->thresholded[i+y][j+x] == GREEN) { where = where * GREENRIGHT; } } } // put in the case where we don't have any, but want to check the corners return where; }