Urbanisme  1.3.0
Projet visant à l'optimisation du placement de routes sur une surface. https://flodavid.github.io/Urbanisme
field.h
1 #pragma once
2 
3 #include <list>
4 
5 #include "Coordinates.h"
6 
7 enum State{is_undefined= -1, is_usable, is_unusable, is_road, is_in_out, max_state};
8 
15 class Field
16 {
17 
18 protected:
19 
21  unsigned nb_cols;
23  unsigned nb_rows;
25  std::list<Coordinates> ins_outs;
26 
28  State** parcels;
29 
30 public:
36  Field(unsigned width, unsigned height/*, std::list< Coordinates >& inputs_and_ouputs = *(new std::list<Coordinates>()) */);
41  Field(const Field& other);
42 
43  virtual ~Field();
44 
45  /*=== Getters ===*/
50  inline unsigned get_width() const { return nb_cols; }
55  inline unsigned get_height() const { return nb_rows; }
56 
61  inline std::list<Coordinates> & get_insOuts() { return ins_outs; }
62 
68  inline unsigned getNbParcels() const { return nb_cols * nb_rows; }
69 
70  /*=== Setters ===*/
75  inline void set_width(unsigned width)
76  { nb_cols = width; }
81  inline void set_height(unsigned height)
82  { nb_rows = height; }
83 
84  //private:
85  void deleteOldMatrix();
91  void resizeWithDimensions();
92 public:
97  void add_road(const Coordinates& coords)
98  { parcels[coords.row][coords.col]= is_road; }
104  void add_road(unsigned col, unsigned row)
105  { parcels[row][col]= is_road; }
106 
113  void addRoads(std::list<Coordinates>* roads, unsigned serveDistance);
120  void removeRoads(std::list<Coordinates>* roads, unsigned serveDistance);
121 
126  bool tryAdd_in_out(const Coordinates& coords);
132  bool tryAdd_in_out(unsigned col, unsigned row)
133  { return tryAdd_in_out(Coordinates(col, row)); }
134 
139  void add_undefined(const Coordinates& coords);
140 
146  void add_undefined(unsigned col, unsigned row)
147  { add_undefined(Coordinates(col, row)); }
148 
150 public:
156  inline State at(const Coordinates& pos) const { return parcels[pos.row][pos.col]; }
163  inline State operator[](const Coordinates& pos) const { return parcels[pos.row][pos.col]; }
168  inline Field& operator=(const Field& other)
169  {
170  assert(nb_cols == other.nb_cols && nb_rows == other.nb_cols);
171  ins_outs= other.ins_outs;
172  parcels= other.parcels;
173 
174  return *this;
175  }
176 
182 // inline std::vector<std::vector<State>>::const_iterator begin() const { return parcels.cbegin(); }
188 // inline std::vector<std::vector<State>>::const_iterator end() const { return parcels.cend(); }
194 // inline std::vector<std::vector<State>>::iterator begin() { return parcels.begin(); }
200 // inline std::vector<std::vector<State>>::iterator end() { return parcels.end(); }
201 
207  static inline Coordinates& first()
208  { return *(new Coordinates(0,0)); }
209 
210 public:
211  /*=== Affichage ===*/
215  void show_ins_and_outs() const;
216 
222  std::ostream& print(std::ostream& out) const;
230  friend std::ostream& operator<<(std::ostream& out, const Field& field)
231  { return field.print(out); }
232 
240  bool contains(int x, int y) const ;
246  bool contains(const Coordinates& coord) const ;
255  bool nextCoordinates ( Coordinates* coord ) const;
256 
262  void generateInsAndOuts(unsigned nb);
263 
264 private:
270  inline bool isRoad(const Coordinates& neighbour) const;
276  inline bool isParcel(const Coordinates &neighbour) const;
282  inline bool isUnusableParcel(const Coordinates &neighbour) const;
290  bool isRoadAndNeighbourOf(const Coordinates& neighbour, const Coordinates& coord, unsigned servingDistance) const;
291 
292 public:
293 // /**
294 // * Recherche des parcelles qui sont concomitantes à la cellule
295 // * @param coord Coordonnées de la parcelle
296 // * @return une liste de parcelle adjacentes à la cellule
297 // */
298 // std::list<Coordinates> *getNeighbourParcels( const Coordinates& coord ) const;
304  std::list<Coordinates> *getNeighbourRoads( const Coordinates& coord ) const;
305 
306 
307 // bool
308 private:
309  std::list<Coordinates> *getClose(const Coordinates &coord, unsigned maxDist, bool (Field::*neighbourVerif)(const Coordinates &) const) const;
310 
311 public:
318  std::list<Coordinates> *getCloseUnusableParcels( const Coordinates& coord, unsigned servingDistance ) const;
325  std::list<Coordinates> *getCloseParcels( const Coordinates& coord, unsigned maxDist ) const;
332  std::list<Coordinates> *getCloseRoads( const Coordinates& coord, unsigned maxDist ) const;
339  std::list<Coordinates> *getServingRoads( const Coordinates& coord, unsigned servingDistance ) const;
340 
341 //private:
348  bool hasServingRoad ( const Coordinates& coord, unsigned servingDistance ) const;
349 
350 public:
355  void setUsables(unsigned servingDistance);
360  void resetUsables(unsigned servingDistance);
365  void updateUsables(unsigned servingDistance);
366 
367  /*=== Autres méthodes utiles ===*/
372  void createExample();
373 };
int row
Definition: Coordinates.h:24
unsigned nb_rows
nb_rows Nombre de lignes de la surface
Definition: field.h:23
unsigned get_height() const
Definition: field.h:55
void set_width(unsigned width)
Definition: field.h:75
std::list< Coordinates > * getServingRoads(const Coordinates &coord, unsigned servingDistance) const
Definition: field.cpp:338
bool hasServingRoad(const Coordinates &coord, unsigned servingDistance) const
Definition: field.cpp:375
Field(unsigned width, unsigned height)
Definition: field.cpp:10
std::list< Coordinates > * getCloseRoads(const Coordinates &coord, unsigned maxDist) const
Definition: field.cpp:330
void generateInsAndOuts(unsigned nb)
Definition: field.cpp:198
void updateUsables(unsigned servingDistance)
Definition: field.cpp:446
bool nextCoordinates(Coordinates *coord) const
Definition: field.cpp:158
static Coordinates & first()
begin
Definition: field.h:207
std::list< Coordinates > * getNeighbourRoads(const Coordinates &coord) const
Definition: field.cpp:246
unsigned getNbParcels() const
Definition: field.h:68
Classe représentant la surface -le terrain- et contenant les opérations que l&#39;on effectue sur celui-c...
Definition: field.h:15
void add_road(const Coordinates &coords)
Definition: field.h:97
unsigned get_width() const
Definition: field.h:50
Field & operator=(const Field &other)
Definition: field.h:168
bool tryAdd_in_out(const Coordinates &coords)
Definition: field.cpp:89
void add_undefined(unsigned col, unsigned row)
Definition: field.h:146
void add_road(unsigned col, unsigned row)
Definition: field.h:104
State operator[](const Coordinates &pos) const
Definition: field.h:163
std::list< Coordinates > & get_insOuts()
Definition: field.h:61
void set_height(unsigned height)
Definition: field.h:81
void addRoads(std::list< Coordinates > *roads, unsigned serveDistance)
Definition: field.cpp:68
int col
Definition: Coordinates.h:20
std::list< Coordinates > ins_outs
ins_outs Liste des entrées-sorties de la surface
Definition: field.h:25
friend std::ostream & operator<<(std::ostream &out, const Field &field)
Definition: field.h:230
bool tryAdd_in_out(unsigned col, unsigned row)
Definition: field.h:132
bool contains(int x, int y) const
Definition: field.cpp:146
void deleteOldMatrix()
Definition: field.cpp:45
State at(const Coordinates &pos) const
Definition: field.h:156
void add_undefined(const Coordinates &coords)
Definition: field.cpp:100
State ** parcels
Matrice d&#39;états des cellules.
Definition: field.h:28
void show_ins_and_outs() const
Definition: field.cpp:117
unsigned nb_cols
nb_cols Nombre de colonnes de la surface
Definition: field.h:21
void resizeWithDimensions()
Definition: field.cpp:56
std::ostream & print(std::ostream &out) const
Definition: field.cpp:125
std::list< Coordinates > * getCloseParcels(const Coordinates &coord, unsigned maxDist) const
Definition: field.cpp:322
void removeRoads(std::list< Coordinates > *roads, unsigned serveDistance)
Definition: field.cpp:79
void resetUsables(unsigned servingDistance)
Definition: field.cpp:424
std::list< Coordinates > * getCloseUnusableParcels(const Coordinates &coord, unsigned servingDistance) const
Definition: field.cpp:314
Représentation et opérations simple sur des coordonnées dans un plan.
Definition: Coordinates.h:13
void setUsables(unsigned servingDistance)
Definition: field.cpp:402
void createExample()
createExample
Definition: field_others.cpp:10