Fixed triangle-textures bugs
This commit is contained in:
parent
f2b4a19de8
commit
902a512061
BIN
QT/triangle-textures/c.jpg
Normal file
BIN
QT/triangle-textures/c.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
@ -98,7 +98,7 @@ MyWindow::MyWindow(QWidget *parent) :
|
|||||||
f1_img = new QImage(szer,wys,QImage::Format_RGB32);
|
f1_img = new QImage(szer,wys,QImage::Format_RGB32);
|
||||||
f2_img = new QImage(szer,wys,QImage::Format_RGB32);
|
f2_img = new QImage(szer,wys,QImage::Format_RGB32);
|
||||||
|
|
||||||
loaded_img1 = new QImage("/home/davp/umk/2022_2023/GK/QT/alpha-blending/f.png");
|
loaded_img1 = new QImage("/Users/dawidpietrykowski/Desktop/projects/umk/GK/QT/triangle-textures/c.jpg");
|
||||||
|
|
||||||
// int width = loaded_img1->width();
|
// int width = loaded_img1->width();
|
||||||
// int height = loaded_img1->height();
|
// int height = loaded_img1->height();
|
||||||
@ -139,26 +139,6 @@ void MyWindow::on_exitButton_clicked()
|
|||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_erosion_clicked(){
|
|
||||||
Erosion(loaded_img1);
|
|
||||||
UpdateImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::on_dilation_clicked(){
|
|
||||||
Dilation(loaded_img1);
|
|
||||||
UpdateImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::on_opening_clicked(){
|
|
||||||
Open(loaded_img1);
|
|
||||||
UpdateImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::on_closing_clicked(){
|
|
||||||
Close(loaded_img1);
|
|
||||||
UpdateImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::UpdateImage(){
|
void MyWindow::UpdateImage(){
|
||||||
ClearImage(f1_img);
|
ClearImage(f1_img);
|
||||||
ClearImage(f2_img);
|
ClearImage(f2_img);
|
||||||
@ -170,62 +150,6 @@ void MyWindow::UpdateImage(){
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyWindow::IsLit(QImage* im, int x, int y, int val){
|
|
||||||
int width = im->width();
|
|
||||||
int height = im->height();
|
|
||||||
if(x < 0 || y < 0 || x >= width || y >= height)
|
|
||||||
return false;
|
|
||||||
QColor pix = GetPixel(im, x, y);
|
|
||||||
return pix.red() == val && pix.green() == val && pix.blue() == val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::Erosion(QImage* im){
|
|
||||||
int width = im->width();
|
|
||||||
int height = im->height();
|
|
||||||
|
|
||||||
memcpy(loaded_img2->bits(), loaded_img1->bits(), width * height * 4);
|
|
||||||
|
|
||||||
for(int x = 0; x < width; x++)
|
|
||||||
for(int y = 0; y < height; y++){
|
|
||||||
bool active = false;
|
|
||||||
for (int x2 = x - 1; x2 <= x + 1; x2++)
|
|
||||||
for (int y2 = y - 1; y2 <= y + 1; y2++)
|
|
||||||
if(IsLit(loaded_img1, x2, y2, 0)){
|
|
||||||
DrawPixel(loaded_img2, x, y, QColor(0, 0, 0));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
memcpy(loaded_img1->bits(), loaded_img2->bits(), width * height * 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::Dilation(QImage* im){
|
|
||||||
int width = im->width();
|
|
||||||
int height = im->height();
|
|
||||||
|
|
||||||
memcpy(loaded_img2->bits(), loaded_img1->bits(), width * height * 4);
|
|
||||||
|
|
||||||
for(int x = 0; x < width; x++)
|
|
||||||
for(int y = 0; y < height; y++){
|
|
||||||
bool active = false;
|
|
||||||
for (int x2 = x - 1; x2 <= x + 1; x2++)
|
|
||||||
for (int y2 = y - 1; y2 <= y + 1; y2++)
|
|
||||||
if(IsLit(loaded_img1, x2, y2, 255)){
|
|
||||||
DrawPixel(loaded_img2, x, y, QColor(255, 255, 255));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
memcpy(loaded_img1->bits(), loaded_img2->bits(), width * height * 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::Close(QImage* im){
|
|
||||||
Dilation(im);
|
|
||||||
Erosion(im);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWindow::Open(QImage* im){
|
|
||||||
Erosion(im);
|
|
||||||
Dilation(im);
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor MyWindow::GetPixel(QImage* img, int x, int y){
|
QColor MyWindow::GetPixel(QImage* img, int x, int y){
|
||||||
QColor res;
|
QColor res;
|
||||||
|
@ -39,9 +39,9 @@ enum Mode {Add, Move, None};
|
|||||||
|
|
||||||
|
|
||||||
struct Point{
|
struct Point{
|
||||||
int x, y;
|
float x, y;
|
||||||
|
|
||||||
Point(int x, int y){
|
Point(float x, float y){
|
||||||
this->x=x;
|
this->x=x;
|
||||||
this->y=y;
|
this->y=y;
|
||||||
}
|
}
|
||||||
@ -53,10 +53,6 @@ struct Point{
|
|||||||
|
|
||||||
Point operator-(const Point& other){
|
Point operator-(const Point& other){
|
||||||
return Point(this->x - other.x, this->y - other.y);
|
return Point(this->x - other.x, this->y - other.y);
|
||||||
// float x = other.x - this->x;
|
|
||||||
// float y = other.y - this->y;
|
|
||||||
// float mag = std::sqrt(std::pow(x, 2) + std::pow(y, 2));
|
|
||||||
// return mag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Point operator*(const float mul){
|
Point operator*(const float mul){
|
||||||
@ -154,25 +150,13 @@ private:
|
|||||||
void UpdateImage();
|
void UpdateImage();
|
||||||
|
|
||||||
|
|
||||||
bool IsLit(QImage* im, int x, int y, int val);
|
|
||||||
void Erosion(QImage* im);
|
|
||||||
void Dilation(QImage* im);
|
|
||||||
void Close(QImage* im);
|
|
||||||
void Open(QImage* im);
|
|
||||||
int FindPoint(int x, int y, float radius, int frame);
|
int FindPoint(int x, int y, float radius, int frame);
|
||||||
void DrawTriangles();
|
void DrawTriangles();
|
||||||
void DrawSquare(QImage* im, int x, int y, int size, QColor color);
|
void DrawSquare(QImage* im, int x, int y, int size, QColor color);
|
||||||
void DrawLine(QImage *im, int x1, int y1, int x2, int y2);
|
void DrawLine(QImage *im, int x1, int y1, int x2, int y2);
|
||||||
// Deklaracje slotow, czyli funkcji wywolywanych
|
|
||||||
// po wystapieniu zdarzen zwiazanych z GUI
|
|
||||||
// np. klikniecie na przycisk, ruch myszka
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_exitButton_clicked();
|
void on_exitButton_clicked();
|
||||||
void paintEvent(QPaintEvent*);
|
void paintEvent(QPaintEvent*);
|
||||||
void on_erosion_clicked();
|
|
||||||
void on_dilation_clicked();
|
|
||||||
void on_opening_clicked();
|
|
||||||
void on_closing_clicked();
|
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@
|
|||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>980</x>
|
<x>10</x>
|
||||||
<y>460</y>
|
<y>610</y>
|
||||||
<width>241</width>
|
<width>200</width>
|
||||||
<height>201</height>
|
<height>201</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -61,58 +61,6 @@
|
|||||||
<string>Wyjście</string>
|
<string>Wyjście</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPushButton" name="erosion">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>30</x>
|
|
||||||
<y>80</y>
|
|
||||||
<width>80</width>
|
|
||||||
<height>25</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Erozja</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="opening">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>30</x>
|
|
||||||
<y>140</y>
|
|
||||||
<width>80</width>
|
|
||||||
<height>25</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Otwarcie</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="dilation">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>140</x>
|
|
||||||
<y>80</y>
|
|
||||||
<width>80</width>
|
|
||||||
<height>25</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Dylacja</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="closing">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>140</x>
|
|
||||||
<y>140</y>
|
|
||||||
<width>80</width>
|
|
||||||
<height>25</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Zamknięcie</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QFrame" name="frame2">
|
<widget class="QFrame" name="frame2">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -140,7 +88,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1236</width>
|
<width>1236</width>
|
||||||
<height>22</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
Reference in New Issue
Block a user