diff --git a/lib/state.cpp b/lib/state.cpp index baf24d9..0e0ab30 100644 --- a/lib/state.cpp +++ b/lib/state.cpp @@ -1,5 +1,6 @@ #include "state.h" #include +#include int State::size = 19; @@ -39,26 +40,35 @@ void State::printState( void ) State State::generateState (SDL_Surface *boardImg, Settings settings) { State state; - int i, j, x, y, r, sum; + int i, j, x, y, r, sum, bpc, wpc; point p; - r = 10; //what kind of magic number is this? + r = 5; //what kind of magic number is this? for (i = 0; i < size; ++i) { for (j = 0; j < size; ++j) { //for all points: p = positionPoint(i, j, settings); //retrieve the estimated point sum = 0; + bpc = wpc = 0; //TODO: this loop should be placed into its own function! for (y = p.y-r; y < p.y+r; ++y) { for (x = p.x-r; x < p.x+r; ++x) { //for -10 to 10 around the point uint32_t px = PX(boardImg, x, y); sum += (PXR(px) + PXG(px) + PXB(px)); //sum up the colors + if (PXR(px) + PXG(px) + PXB(px) < settings.getBlackTreshold()) + bpc++; + if (PXR(px) + PXG(px) + PXB(px) > settings.getWhiteTreshold()) + wpc++; } } sum/=400; //printf("%d\t", sum); type t = BOARD; + /* if (sum < settings.getBlackTreshold()) t = BLACK; if (sum > settings.getWhiteTreshold()) t = WHITE; + */ + if (wpc > 10) t = WHITE; + if (bpc > 10) t = BLACK; PX_(state.board, i, j, size, size) = t; } //printf("\n"); @@ -71,12 +81,21 @@ point State::positionPoint(int i, int j, Settings s) { point ul = s.getUL(), ur = s.getUR(), bl = s.getBL(), br = s.getBR(); point topp, botp, pp; + double alf = 1.1*((double)(br.x-bl.x))/(ur.x-ul.x); + double a = 2/(alf+1); + double jj = 0; + int n; + for (n = 0; n < j; n++) + jj += a+((alf-1)*a*n)/(size-1); + //printf("(%d, %d, %f)\n", i, j, jj); topp.x = ul.x + (i*(ur.x-ul.x))/(size-1); topp.y = ul.y + (i*(ur.y-ul.y))/(size-1); botp.x = bl.x + (i*(br.x-bl.x))/(size-1); botp.y = bl.y + (i*(br.y-bl.y))/(size-1); - pp.x = topp.x + (j*(botp.x-topp.x))/(size-1); - pp.y = topp.y + (j*(botp.y-topp.y))/(size-1); + pp.x = topp.x + (jj*(botp.x-topp.x))/(size-1); + pp.y = topp.y + (jj*(botp.y-topp.y))/(size-1); + //pp.y = topp.y + ((j-sin(j*(bl.y-ul.y)/(M_PI*(size-1)))/a)*(botp.y-topp.y))/(size-1); + //pp.y = topp.y + (j*(botp.y-topp.y))/(size-1); return pp; } diff --git a/qt/aigoqt.cpp b/qt/aigoqt.cpp index 922539b..f78e1f9 100644 --- a/qt/aigoqt.cpp +++ b/qt/aigoqt.cpp @@ -26,7 +26,7 @@ void AigoQt::updateImage( void ) SDL_Surface *s = cam->getSurface(); Image::threshold(s, sliderBlack->value(), sliderWhite->value()); image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32))); - on_buttonGenerateState_clicked(); + //on_buttonGenerateState_clicked(); } void AigoQt::on_buttonSetCorners_clicked( void )