Commit 8e533605 authored by Maxime Goret's avatar Maxime Goret
Browse files

Modif Voisinage

parent 3d6ae910
......@@ -11,6 +11,11 @@ private:
//inline Cellule():indEtat(0), abs(0), ord(0){};
void initCellule(const unsigned int ind, const unsigned int &x, const unsigned int &y);
friend class Reseau;
friend class RegleVoisinage;
friend class RegleVoisinageNeumann;
friend class RegleVoisinageMoore;
};
class Etat{
......@@ -56,6 +61,9 @@ private:
unsigned int hauteur;
unsigned int largeur;
Cellule** reseau;
friend class RegleVoisinage;
friend class RegleVoisinageNeumann;
friend class RegleVoisinageMoore;
public:
/* inline Reseau(const unsigned int &h, const unsigned int &l):hauteur(h),largeur(l){
......
......@@ -42,7 +42,7 @@ void RegleVoisinageMoore::setNbVoisins(unsigned int r) {
}
void RegleVoisinage::calculVoisinage(Voisinage& v, const Reseau& r) {
v.voisinage = new Cellule* [nbVoisin];
v.voisinage = std::vector<Cellule*>();
for (int k = 0; k < nbVoisin; k++) {
unsigned int i, j;
while (i >= r.hauteur || j >= r.largeur) {
......@@ -59,7 +59,7 @@ void RegleVoisinage::calculVoisinage(Voisinage& v, const Reseau& r) {
}
void RegleVoisinageNeumann::calculVoisinage(Voisinage& v, const Reseau& r) {
v.voisinage = new Cellule * [nbVoisin];
v.voisinage = std::vector<Cellule*>();
int nb = 0;
unsigned int abs = v.celluleCentre->abs;
unsigned int ord = v.celluleCentre->ord;
......@@ -122,7 +122,7 @@ void RegleVoisinageNeumann::calculVoisinage(Voisinage& v, const Reseau& r) {
}
void RegleVoisinageMoore::calculVoisinage(Voisinage& v, const Reseau& r){
v.voisinage = new Cellule * [nbVoisin];
v.voisinage = std::vector<Cellule*>();
int nb = 0;
unsigned int abs = v.celluleCentre->abs;
unsigned int ord = v.celluleCentre->ord;
......@@ -185,15 +185,5 @@ void RegleVoisinageMoore::calculVoisinage(Voisinage& v, const Reseau& r){
}
Voisinage::~Voisinage() {
VoisinageIterator *cellules = creerIterator();
cellules->first();
int nb = 0;
while (!cellules->isDone()){
delete voisinage[nb];
nb++;
}
delete[] voisinage;
voisinage.clear();
}
......@@ -10,26 +10,56 @@
#include <stdio.h>
#include <iostream>
#include "../Reseau_Cellule_Etat/reseau_cellule_etats.h"
#include <string.h>
using namespace std;
#include <vector>
class Voisinage {
private :
const Cellule* celluleCentre;
Cellule** voisinage;
vector<Cellule*> voisinage;
unsigned int r;
friend class RegleVoisinage;
friend class RegleVoisinageMoore;
friend class RegleVoisinageNeumann;
friend class VoisinageIterator;
public:
class VoisinageIterator {
const Voisinage *vsn;
int i;
public :
VoisinageIterator(const Voisinage *v){
vsn = v;
}
void first(){
i=0;
}
void next(){
i++;
}
bool isDone(){
return (vsn->voisinage.size() <= i);
}
Cellule* currentItem(){
return vsn->voisinage[i];
}
};
Voisinage();
~Voisinage();
Cellule* getCelluleCentre()const {return celluleCentre;}
Cellule getCelluleCentre()const {return *celluleCentre;}
void setr(unsigned int rayon);
unsigned int getr() const {return r;}
VoisinageIterator *creerIterator()const{
......@@ -72,31 +102,6 @@ public:
};
class VoisinageIterator {
const Voisinage *vsn;
int i;
public :
VoisinageIterator(const Voisinage *v){
vsn = v;
}
void first(){
i=0;
}
void next(){
i++;
}
bool isDone(){
return (vsn->voisinage.size() <= i);
}
int currentItem(){
return vsn->voisinage[i];
}
};
#endif /* voisinnage_hpp */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment