voisinage.h 2.39 KB
Newer Older
Maxime Goret's avatar
Maxime Goret committed
1
//
Boris Cazic's avatar
Boris Cazic committed
2
//  voisinage.h
Maxime Goret's avatar
Maxime Goret committed
3
4
5
6
7
//  LO21-Projet
//
//  Created by Maxime Goret on 20/04/2021.
//

Boris Cazic's avatar
Boris Cazic committed
8
9
#ifndef voisinage_h
#define voisinage_h
Maxime Goret's avatar
Maxime Goret committed
10

Boris Cazic's avatar
Boris Cazic committed
11
12
#include"reseau_cellule_etats.h"
#include"coordonnees.h"
13
#include<cstdio>
Boris Cazic's avatar
Boris Cazic committed
14
15
16
#include<iostream>
#include<string>
#include<vector>
17

18

Maxime Goret's avatar
Maxime Goret committed
19
20
21
22
23
using namespace std;

class Voisinage {
private :
    const Cellule* celluleCentre;
Maxime Goret's avatar
Maxime Goret committed
24
    vector<Cellule*> voisinage;
Maxime Goret's avatar
Maxime Goret committed
25
26
27
28
    unsigned int r;
    friend class RegleVoisinage;
    friend class RegleVoisinageMoore;
    friend class RegleVoisinageNeumann;
Maxime Goret's avatar
Maxime Goret committed
29
    friend class VoisinageIterator;
Maxime Goret's avatar
Maxime Goret committed
30
public:
Maxime Goret's avatar
Maxime Goret committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    
    class VoisinageIterator {
        const Voisinage *vsn;
        int i;
        public :
        
        VoisinageIterator(const Voisinage *v){
            vsn = v;
        }
        
        void first(){
            i=0;
        }
        
        void next(){
            i++;
        }
        bool isDone(){
Maxime Goret's avatar
Maxime Goret committed
49
            return (vsn->voisinage.size() <=  i);
Maxime Goret's avatar
Maxime Goret committed
50
51
52
53
54
55
        }
        Cellule* currentItem(){
            return vsn->voisinage[i];
        }
        
    };
Maxime Goret's avatar
Maxime Goret committed
56

Boris Cazic's avatar
Boris Cazic committed
57
    Voisinage(const Cellule* centre, vector<Cellule*> v) : celluleCentre(centre), voisinage(v) {}
Maxime Goret's avatar
Maxime Goret committed
58
    ~Voisinage();
Maxime Goret's avatar
Maxime Goret committed
59
    Cellule getCelluleCentre()const {return *celluleCentre;}
Maxime Goret's avatar
Maxime Goret committed
60

Luning Yang's avatar
Luning Yang committed
61
    void setr(unsigned int rayon);
Maxime Goret's avatar
Maxime Goret committed
62
    unsigned int getr() const {return r;}
Maxime Goret's avatar
Maxime Goret committed
63
64
65
    VoisinageIterator *creerIterator()const{
        return new VoisinageIterator(this);
    }
Maxime Goret's avatar
Maxime Goret committed
66
67
68
69
    
};

class RegleVoisinage{
Boris Cazic's avatar
Boris Cazic committed
70
private :
Maxime Goret's avatar
Maxime Goret committed
71
    
Boris Cazic's avatar
Boris Cazic committed
72
73

public :
Maxime Goret's avatar
Maxime Goret committed
74
    unsigned int nbVoisin;
Maxime Goret's avatar
Maxime Goret committed
75
76
    void setNbVoisins(unsigned int r);
    unsigned int getNbVoisin() {return nbVoisin;}
77
    virtual void calculVoisinage(Voisinage& v, const Reseau& r);
Maxime Goret's avatar
Maxime Goret committed
78
79
80
81
82
    
    
};


Luning Yang's avatar
Luning Yang committed
83
class RegleVoisinageNeumann : public RegleVoisinage {
Maxime Goret's avatar
Maxime Goret committed
84
public:
Maxime Goret's avatar
Maxime Goret committed
85
86
    //void setNbVoisins(unsigned int r);
    void calculVoisinage(Voisinage& v, const Reseau& r, const unsigned int rayon);
Maxime Goret's avatar
Maxime Goret committed
87
88
89
90
91
92

};


class RegleVoisinageMoore : public RegleVoisinage {
public:
Maxime Goret's avatar
Maxime Goret committed
93
94
    //void setNbVoisins(unsigned int r);
    void calculVoisinage(Voisinage& v, const Reseau& r, const unsigned int rayon);
Maxime Goret's avatar
Maxime Goret committed
95
96

};
Maxime Goret's avatar
Maxime Goret committed
97

Boris Cazic's avatar
Boris Cazic committed
98
99
class RegleVoisinageArbitraire : public RegleVoisinage { //définit la règle pour le voisinage arbitraire
public:
100
101
102
103
104

    vector<Coordonnees> coordonnees;

    void calculVoisinage(Voisinage& v, const Reseau& r, const Coordonnes co) const; // Calcul du voisinage en fonction de la cellule centre
    coordonnees getVoisinage(const Reseau& r); // Dééfinition des coordonnées relatives pour le calcul du voisinage
Boris Cazic's avatar
Boris Cazic committed
105
106
107
};


Maxime Goret's avatar
Maxime Goret committed
108

Boris Cazic's avatar
Boris Cazic committed
109
#endif /* voisinage_h */