voisinage.cpp 2.28 KB
Newer Older
Boris Cazic's avatar
Boris Cazic committed
1
2
3
4
#include"voisinage.h"
#include"reseau_cellule_etats.h"
#include<cmath>
#include<iostream>
Luning Yang's avatar
Luning Yang committed
5

6
void RegleVoisinageNeumann::calculVoisinage(Voisinage& v, const Reseau& r) const {
Maxime Goret's avatar
Maxime Goret committed
7
	v.voisinage = std::vector<Cellule*>();
8
9
	unsigned int cellX = v.celluleCentre->abs;
	unsigned int cellY = v.celluleCentre->ord;
10
11
	unsigned int hauteur = r.getHauteur();
	unsigned int largeur = r.getLargeur();
Luning Yang's avatar
Luning Yang committed
12

Romain De Laage De Bellefaye's avatar
Romain De Laage De Bellefaye committed
13
14
15
	for (int i = -static_cast<int>(rayon); i <= static_cast<int>(rayon); i++)
		for (int j = -static_cast<int>(rayon); j <= static_cast<int>(rayon); j++)
			if (abs(i) + abs(j) <= static_cast<int>(rayon) && i != 0 && j != 0)
16
				v.voisinage.push_back(&r.getReseau()[(cellY+i)%hauteur][(cellX+j)%largeur]);
Luning Yang's avatar
Luning Yang committed
17
18
}

19
void RegleVoisinageMoore::calculVoisinage(Voisinage& v, const Reseau& r) const {
20
	v.voisinage = std::vector<Cellule*>();
21
22
	unsigned int cellX = v.celluleCentre->abs;
	unsigned int cellY = v.celluleCentre->ord;
23
24
	unsigned int hauteur = r.getHauteur();
	unsigned int largeur = r.getLargeur();
Maxime Goret's avatar
Maxime Goret committed
25

Romain De Laage De Bellefaye's avatar
Romain De Laage De Bellefaye committed
26
27
28
	for (int i = -static_cast<int>(rayon); i <= static_cast<int>(rayon); i++)
		for (int j = -static_cast<int>(rayon); j <= static_cast<int>(rayon); j++)
			if (abs(i) <= static_cast<int>(rayon) && abs(j) <= static_cast<int>(rayon) && i != 0 && j != 0)
29
				v.voisinage.push_back(&r.getReseau()[(cellY+i)%hauteur][(cellX+j)%largeur]);
Luning Yang's avatar
Luning Yang committed
30
31
32
}

Voisinage::~Voisinage() {
33
	voisinage.clear();
Maxime Goret's avatar
Maxime Goret committed
34
}
35

36
void RegleVoisinageArbitraire::calculVoisinage(Voisinage &v, const Reseau& r) const { //définir get?
Maxime Goret's avatar
Maxime Goret committed
37
38
39
40
41
42
    v.voisinage = std::vector<Cellule*>();

    unsigned int abs = v.celluleCentre->abs;
    unsigned int ord = v.celluleCentre->ord;
    unsigned int hauteur = r.getHauteur();
    unsigned int largeur = r.getLargeur();
43

Maxime Goret's avatar
Maxime Goret committed
44
45
46
    for (size_t nb = 0; nb < coordonnees.size(); nb++){
        v.voisinage[nb] = &r.getReseau()[(abs - coordonnees[nb].x)%hauteur] [(ord - coordonnees[nb].y)%largeur];
    }
47
48
}

Maxime Goret's avatar
Maxime Goret committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
vector<Coordonnees> RegleVoisinageArbitraire::getVoisinage(const Reseau& r,const QTableWidget* grid)
{
    vector<Coordonnees> coordonnees;
    int k = 0;

    for (unsigned int i = 0; i < 5; i++) {
        for (unsigned int j = 0; j < 5; j++){
            if (grid->item(i,j)->background() == Qt::red){
               coordonnees[k].x = (2-i);
               coordonnees[k].y = (2-j);
               k += 1;
            }
        }

      }

    return coordonnees;
}