-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrowcutwindow.cpp
70 lines (56 loc) · 1.66 KB
/
growcutwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "growcutwindow.h"
#include "ui_growcutwindow.h"
#include <QFileDialog>
#include <QMessageBox>
#include "ImageConverter.h"
#include <string>
#include "myqlabel.h"
GrowCutWindow::GrowCutWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::GrowCutWindow)
{
ui->setupUi(this);
connect(ui->pictureLabel, SIGNAL(Mouse_Pos()), this, SLOT(Mouse_current_pos()));
}
GrowCutWindow::~GrowCutWindow()
{
delete ui;
}
void GrowCutWindow::on_actionOpen_triggered()
{
QString filename = QFileDialog::getOpenFileName(
this,
tr("Open image"),
"",
"All (*.*)"
);
QPixmap pix(filename);
int w = ui->pictureLabel->width();
int h = ui->pictureLabel->height();
// set a scaled pixmap to a w x h window keeping its aspect ratio
QPixmap newpix = pix.scaled(w,h,Qt::KeepAspectRatio);
ui->pictureLabel->setPixmap(newpix);
img = newpix.toImage();
Matrix<float3> imageMatrix = ImageConverter::getMatrix(img);
automata.setField(imageMatrix);
}
void GrowCutWindow::on_runPushButton_clicked()
{
automata.iterate();
ImageConverter::saveImage(automata.getField(), img);
QPixmap temp = QPixmap::fromImage(img);
ui->pictureLabel->setPixmap(temp);
}
void GrowCutWindow::Mouse_current_pos()
{
if (ui->pictureLabel->pressed)
{
if (ui->objectRadioButton->isChecked())
automata.setCell(ui->pictureLabel->x , ui->pictureLabel->y , object, 0.9f);
else automata.setCell(ui->pictureLabel->x , ui->pictureLabel->y , background, 0.9f);
}
}
void GrowCutWindow::on_actionSave_triggered()
{
img.save("picture.jpg");
}