Katabatic - Routing Toolbox


Grid.h
1 // -*- C++ -*-
2 //
3 // This file is part of the Coriolis Software.
4 // Copyright (c) UPMC 2008-2018, All Rights Reserved
5 //
6 // +-----------------------------------------------------------------+
7 // | C O R I O L I S |
8 // | K a t a b a t i c - Routing Toolbox |
9 // | |
10 // | Author : Jean-Paul CHAPUT |
11 // | E-mail : Jean-Paul.Chaput@lip6.fr |
12 // | =============================================================== |
13 // | C++ Header : "./katabatic/Grid.h" |
14 // +-----------------------------------------------------------------+
15 
16 
17 #ifndef KATABATIC_GRID_H
18 #define KATABATIC_GRID_H
19 
20 #include <string>
21 #include <vector>
22 #include "hurricane/Point.h"
23 #include "hurricane/Box.h"
24 #include "hurricane/Collection.h"
25 
26 
27 namespace Katabatic {
28 
29  using std::string;
30  using std::vector;
31  using Hurricane::_TName;
32  using Hurricane::Record;
33  using Hurricane::DbU;
34  using Hurricane::Point;
35  using Hurricane::Box;
38  using Hurricane::getCollection;
39 
40 
41 // -------------------------------------------------------------------
42 // Class : "Katabatic::BaseGrid".
43 
44  class BaseGrid {
45 
46  public:
47  class Axis;
48  public:
49  inline void destroy ();
50  // Accessors.
51  inline bool isOnTopBorder ( unsigned int ) const;
52  inline bool isOnRightBorder ( unsigned int ) const;
53  inline const Box& getBoundingBox () const;
54  inline unsigned int getColumns () const;
55  inline unsigned int getRows () const;
56  inline unsigned int getRawSize () const;
57  inline unsigned int getIndex ( unsigned int c, unsigned int r ) const;
58  inline unsigned int getRow ( unsigned int ) const;
59  inline unsigned int getColumn ( unsigned int ) const;
60  inline const Axis& getXGrads () const;
61  inline const Axis& getYGrads () const;
62  // Inspector Managment.
63  virtual Record* _getRecord () const;
64  virtual string _getString () const = 0;
65 
66  public:
67  // Sub-Class Grid::Axis.
68  class Axis {
69  public:
70  // Modifiers.
71  inline void addGraduation ( DbU::Unit );
72  void sort ();
73  // Accessors.
74  inline unsigned int getSize () const;
75  unsigned int getGraduationNumber ( DbU::Unit pos, bool& onGraduation ) const;
76  // Operators.
77  inline const DbU::Unit& operator[] ( unsigned int i ) const;
78  // Inspector Management.
79  Record* _getRecord () const;
80  string _getString () const;
81  inline string _getTypeName () const;
82  string _print () const;
83  protected:
84  // Attributes.
85  vector<DbU::Unit> _graduations;
86  };
87 
88  protected:
89  // Attributes.
90  Box _boundingBox;
91  Axis _xGraduations;
92  Axis _yGraduations;
93  unsigned int _rows;
94  unsigned int _columns;
95  unsigned int _rawSize;
96 
97  // Constructors & Destructors.
98  protected:
99  BaseGrid ( const Box& );
100  virtual ~BaseGrid ();
101  virtual void _postCreate ();
102  virtual void _preDestroy ();
103  private:
104  BaseGrid ( const BaseGrid& );
105  BaseGrid& operator= ( const BaseGrid& );
106  };
107 
108 
109 // Inline Functions.
110  inline void BaseGrid::Axis::addGraduation ( DbU::Unit graduation ) { _graduations.push_back(graduation); }
111  inline unsigned int BaseGrid::Axis::getSize () const { return _graduations.size(); }
112  inline const DbU::Unit& BaseGrid::Axis::operator[] ( unsigned int i ) const { return _graduations[i]; }
113  inline string BaseGrid::Axis::_getTypeName () const { return _TName("BaseGrid::Axis"); }
114 
115  inline void BaseGrid::destroy () { _preDestroy(); delete this; }
116  inline const Box& BaseGrid::getBoundingBox () const { return _boundingBox; };
117  inline unsigned int BaseGrid::getColumns () const { return _columns; };
118  inline unsigned int BaseGrid::getRows () const { return _rows; };
119  inline unsigned int BaseGrid::getRawSize () const { return getColumns() * getRows(); }
120  inline unsigned int BaseGrid::getIndex ( unsigned int c, unsigned int r ) const { return c+(r*getColumns()); }
121  inline unsigned int BaseGrid::getRow ( unsigned int i ) const { return i / getColumns(); }
122  inline unsigned int BaseGrid::getColumn ( unsigned int i ) const { return i % getColumns(); }
123  inline bool BaseGrid::isOnTopBorder ( unsigned int i ) const { return getRow (i)+1 == getRows(); }
124  inline bool BaseGrid::isOnRightBorder ( unsigned int i ) const { return getColumn(i)+1 == getColumns(); }
125 
126  inline const BaseGrid::Axis& BaseGrid::getXGrads () const { return _xGraduations; }
127  inline const BaseGrid::Axis& BaseGrid::getYGrads () const { return _yGraduations; }
128 
129 
130 
131 // -------------------------------------------------------------------
132 // Template Class : "Katabatic::Grid".
133 
134 
135  template<typename GCellT>
136  class Grid : public BaseGrid {
137 
138  public:
139  // Accessors.
140  inline GCellT* getGCell ( unsigned int index ) const;
141  inline GCellT* getGCell ( const Point p ) const;
142  inline GCellT* getGCell ( const Point p1, const Point p2 ) const;
143  inline GCellT* getGCellLeft ( const GCellT* gcell ) const;
144  inline GCellT* getGCellRight ( const GCellT* gcell ) const;
145  inline GCellT* getGCellUp ( const GCellT* gcell ) const;
146  inline GCellT* getGCellDown ( const GCellT* gcell ) const;
147  inline vector<GCellT*>* getGCellVector ();
148  // Collections & Filters.
149  inline GenericCollection<GCellT*> getGCells ();
150  inline GenericCollection<GCellT*> getGCellsColumn ( unsigned int column
151  , unsigned int rowStart
152  , unsigned int rowStop );
153  inline GenericCollection<GCellT*> getGCellsRow ( unsigned int row
154  , unsigned int columnStart
155  , unsigned int columnStop );
156  // Inspector Managment.
157  virtual Record* _getRecord () const;
158 
159  protected:
160  // Attributes.
161  vector<GCellT*> _gcells;
162 
163  // Constructors & Destructors.
164  protected:
165  inline Grid ( const Box& );
166  virtual ~Grid ();
167  private:
168  Grid ( const Grid& );
169  Grid& operator= ( const Grid& );
170  };
171 
172 
173 } // End of Katabatic namespace.
174 
175 
176 #include "katabatic/GridCollections.h"
177 #include "katabatic/GridBox.h"
178 
179 
180 namespace Katabatic {
181 
182 
183 // Inline Functions.
184 
185  template<typename GCellT>
186  Grid<GCellT>::Grid ( const Box& bb )
187  : BaseGrid(bb)
188  , _gcells ()
189  { }
190 
191 
192  template<typename GCellT>
194  { }
195 
196 
197  template<typename GCellT>
198  GCellT* Grid<GCellT>::getGCell ( unsigned int index ) const
199  {
200  if ( ( index < 0 ) || ( index >= _rawSize ) ) return NULL;
201 
202  return _gcells [ index ];
203  }
204 
205 
206  template<typename GCellT>
207  GCellT* Grid<GCellT>::getGCell ( const Point p ) const
208  {
209  if (not getBoundingBox().contains(p)) return NULL;
210 
211  bool onColumn;
212  bool onRow;
213 
214  unsigned int column = _xGraduations.getGraduationNumber ( p.getX(), onColumn );
215  unsigned int row = _yGraduations.getGraduationNumber ( p.getY(), onRow );
216 
217  return getGCell ( getIndex(column,row) );
218  }
219 
220 
221  template<typename GCellT>
222  GCellT* Grid<GCellT>::getGCell ( const Point p1, const Point p2 ) const
223  {
224  if (not getBoundingBox().contains(p1)) return NULL;
225  if (not getBoundingBox().contains(p2)) return NULL;
226 
227  bool onColumn1;
228  bool onColumn2;
229  bool onRow1;
230  bool onRow2;
231 
232  unsigned int column1 = _xGraduations.getGraduationNumber ( p1.getX(), onColumn1 );
233  unsigned int column2 = _xGraduations.getGraduationNumber ( p2.getX(), onColumn2 );
234  unsigned int row1 = _yGraduations.getGraduationNumber ( p1.getY(), onRow1 );
235  unsigned int row2 = _yGraduations.getGraduationNumber ( p2.getY(), onRow2 );
236 
237  if ( row1 != row2 ) {
238  if ( onRow1 ) row1 = row2;
239  }
240 
241  if ( column1 != column2 ) {
242  if ( onColumn1 ) column1 = column2;
243  }
244 
245  return getGCell ( getIndex(column1,row1) );
246  }
247 
248 
249  template<typename GCellT>
250  GCellT* Grid<GCellT>::getGCellLeft ( const GCellT* gcell) const
251  {
252  if ( !gcell ) return NULL;
253 
254  unsigned int index = gcell->getIndex();
255  if ( !getColumn(index) ) return NULL;
256 
257  return getGCell ( index - 1 );
258  }
259 
260 
261  template<typename GCellT>
262  GCellT* Grid<GCellT>::getGCellRight ( const GCellT* gcell) const
263  {
264  if ( !gcell ) return NULL;
265 
266  unsigned int index = gcell->getIndex();
267  if ( getColumn(index) >= getColumns()-1 ) return NULL;
268 
269  return getGCell ( index + 1 );
270  }
271 
272 
273  template<typename GCellT>
274  GCellT* Grid<GCellT>::getGCellUp ( const GCellT* gcell) const
275  {
276  if ( !gcell ) return NULL;
277 
278  unsigned int index = gcell->getIndex();
279  if ( getRow(index) >= getRows()-1 ) return NULL;
280 
281  return getGCell ( index + getColumns() );
282  }
283 
284 
285  template<typename GCellT>
286  GCellT* Grid<GCellT>::getGCellDown ( const GCellT* gcell) const
287  {
288  if ( !gcell ) return NULL;
289 
290  unsigned int index = gcell->getIndex();
291  if ( !getRow(index) ) return NULL;
292 
293  return getGCell ( index - getColumns() );
294  }
295 
296 
297  template<typename GCellT>
298  inline vector<GCellT*>* Grid<GCellT>::getGCellVector ()
299  {
300  return &_gcells;
301  }
302 
303 
304  template<typename GCellT>
306  {
307  return getCollection(_gcells);
308  }
309 
310  template<typename GCellT>
312  , unsigned int rowStart
313  , unsigned int rowStop )
314  {
315  return Grid_Column<GCellT>(this,column,rowStart,rowStop);
316  }
317 
318  template<typename GCellT>
320  , unsigned int columnStart
321  , unsigned int columnStop )
322  {
323  return Grid_Row<GCellT>(this,row,columnStart,columnStop);
324  }
325 
326 
327  template<typename GCellT>
328  Record* Grid<GCellT>::_getRecord () const
329  {
330  Record* record = BaseGrid::_getRecord ();
331  record->add ( getSlot ( "_gcells", &_gcells ) );
332  return record;
333  }
334 
335 
336 } // End of Katabatic namespace.
337 
338 
339 INSPECTOR_P_SUPPORT(Katabatic::BaseGrid::Axis);
340 
341 
342 #endif // KATABATIC_GRID_H
unsigned int getRows() const
Definition: Grid.h:118
void sort()
Definition: Grid.cpp:36
void addGraduation(DbU::Unit)
Definition: Grid.h:110
Abstract Base Class for Irregular Grid.
Definition: Grid.h:44
Template Class for Regular Grid.
Definition: Grid.h:136
std::int64_t Unit
const Axis & getXGrads() const
Definition: Grid.h:126
unsigned int getGraduationNumber(DbU::Unit pos, bool &onGraduation) const
Definition: Grid.cpp:42
const Box & getBoundingBox() const
Definition: Grid.h:116
Grid
BaseGrid(const Box &)
Definition: Grid.cpp:99
void destroy()
Definition: Grid.h:115
The namespace dedicated to Katabatic.
Definition: Katabatic.dox:13
unsigned int getRawSize() const
Definition: Grid.h:119
unsigned int getColumn(unsigned int) const
Definition: Grid.h:122
unsigned int getRow(unsigned int) const
Definition: Grid.h:121
const Axis & getYGrads() const
Definition: Grid.h:127
unsigned int getSize() const
Definition: Grid.h:111
Graduations on a BaseGrid Axis (H or V).
Definition: Grid.h:68
unsigned int getColumns() const
Definition: Grid.h:117
const DbU::Unit & operator[](unsigned int i) const
Definition: Grid.h:112
unsigned int getIndex(unsigned int c, unsigned int r) const
Definition: Grid.h:120
Grid(const Box &)
Definition: Grid.h:186


Generated by doxygen 1.8.14 on Sun Nov 21 2021 Return to top of page
Katabatic - Routing Toolbox Copyright © 2008-2020 Sorbonne Universite. All rights reserved