2007-02-23 21:37:11 +01:00
|
|
|
#include "aigoqt.h"
|
|
|
|
#include <QtDebug>
|
2007-02-23 23:28:29 +01:00
|
|
|
#include <state.h>
|
2007-02-26 11:45:05 +01:00
|
|
|
#include "image.h"
|
2007-02-23 21:37:11 +01:00
|
|
|
|
|
|
|
AigoQt::AigoQt(QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-03-14 18:02:22 +01:00
|
|
|
cam = new StaticCam("data/bilde.bmp");
|
2007-02-23 21:37:11 +01:00
|
|
|
|
|
|
|
timer = new QTimer(this);
|
2007-03-01 14:18:20 +01:00
|
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked()));
|
2007-02-26 11:45:05 +01:00
|
|
|
timer->start(10);
|
2007-02-23 23:28:29 +01:00
|
|
|
|
2007-03-14 18:02:22 +01:00
|
|
|
copy = Image::copySurface(cam->getSurface());
|
2007-03-01 14:18:20 +01:00
|
|
|
|
2007-02-23 21:37:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AigoQt::~AigoQt( void )
|
|
|
|
{
|
|
|
|
delete cam;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AigoQt::updateImage( void )
|
|
|
|
{
|
|
|
|
cam->update();
|
2007-03-14 18:02:22 +01:00
|
|
|
SDL_Surface *s = cam->getSurface();
|
2007-03-01 14:18:20 +01:00
|
|
|
|
2007-03-01 18:07:54 +01:00
|
|
|
if (checkThreshold->isChecked()) Image::threshold(s, blackImageThreshold->value(), whiteImageThreshold->value());
|
2007-03-01 14:18:20 +01:00
|
|
|
SDL_BlitSurface(s, NULL, copy, NULL);
|
|
|
|
|
2007-03-01 18:07:54 +01:00
|
|
|
Mask::mask *mask = Mask::createCircleMask(19);
|
|
|
|
//Mask::printMask(mask);
|
2007-03-01 14:18:20 +01:00
|
|
|
|
|
|
|
if (checkErosion->isChecked()) Image::erosion(s, copy, mask);
|
|
|
|
if (checkDilation->isChecked()) Image::dilation(s, copy, mask);
|
|
|
|
|
|
|
|
delete mask;
|
|
|
|
|
2007-02-23 21:37:11 +01:00
|
|
|
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
|
2007-02-28 16:46:59 +01:00
|
|
|
//on_buttonGenerateState_clicked();
|
2007-02-23 21:37:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AigoQt::on_buttonSetCorners_clicked( void )
|
|
|
|
{
|
2007-02-23 23:28:29 +01:00
|
|
|
disconnect(image, 0, 0, 0);
|
|
|
|
connect(image, SIGNAL(clicked(int, int)), this, SLOT(handleCornerClicked(int, int)));
|
|
|
|
statusBar()->showMessage("Please click the upper left corner of the board.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AigoQt::on_buttonGenerateState_clicked( void )
|
|
|
|
{
|
2007-03-14 18:02:22 +01:00
|
|
|
State state = State::generateState(cam->getSurface(), settings);
|
2007-02-23 23:28:29 +01:00
|
|
|
state.printState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AigoQt::on_sliderBlack_valueChanged( int value)
|
|
|
|
{
|
|
|
|
settings.setBlackThreshold(value);
|
|
|
|
on_buttonGenerateState_clicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AigoQt::on_sliderWhite_valueChanged( int value)
|
|
|
|
{
|
|
|
|
settings.setWhiteThreshold(value);
|
|
|
|
on_buttonGenerateState_clicked();
|
|
|
|
}
|
2007-02-23 21:37:11 +01:00
|
|
|
|
2007-02-23 23:28:29 +01:00
|
|
|
void AigoQt::on_buttonDrawPoints_clicked( void )
|
|
|
|
{
|
2007-02-25 18:54:24 +01:00
|
|
|
updateImage();
|
2007-02-23 23:28:29 +01:00
|
|
|
for (int i = 0; i < 19; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 19; j++)
|
|
|
|
{
|
|
|
|
point p = State::positionPoint(i, j, settings);
|
2007-03-14 18:02:22 +01:00
|
|
|
((uint32_t*)cam->getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000;
|
2007-02-23 23:28:29 +01:00
|
|
|
}
|
|
|
|
}
|
2007-03-14 18:02:22 +01:00
|
|
|
SDL_Surface *s = cam->getSurface();
|
2007-02-23 23:28:29 +01:00
|
|
|
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
|
2007-02-23 21:37:11 +01:00
|
|
|
}
|
|
|
|
|
2007-02-23 23:28:29 +01:00
|
|
|
void AigoQt::handleCornerClicked( int x, int y)
|
2007-02-23 21:37:11 +01:00
|
|
|
{
|
2007-02-23 23:28:29 +01:00
|
|
|
point p;
|
|
|
|
p.x = x;
|
|
|
|
p.y = y;
|
|
|
|
|
|
|
|
QString pointString = QString::fromLatin1("(%1, %2)").arg(x).arg(y);
|
|
|
|
|
|
|
|
static int corner = -1;
|
|
|
|
++corner %= 4;
|
|
|
|
switch (corner)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
settings.setUL(p);
|
|
|
|
statusBar()->showMessage("Upper left set to " + pointString + ". Click upper right.");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
settings.setUR(p);
|
|
|
|
statusBar()->showMessage("Upper right set to " + pointString + ". Click bottom left.");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
settings.setBL(p);
|
|
|
|
statusBar()->showMessage("Bottom left set to " + pointString + ". Click bottom right.");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
settings.setBR(p);
|
|
|
|
statusBar()->showMessage("Bottom right set to " + pointString + ". All done.");
|
|
|
|
disconnect(image, NULL, this, NULL);
|
|
|
|
break;
|
|
|
|
}
|
2007-02-23 21:37:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "aigoqt.moc"
|