Rev 391 | Rev 439 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 391 | Rev 438 | ||
---|---|---|---|
Line 114... | Line 114... | ||
114 | int mSizeY; ///< count of cells in y-direction |
114 | int mSizeY; ///< count of cells in y-direction |
115 | int mCount; ///< total number of cells in the grid |
115 | int mCount; ///< total number of cells in the grid |
116 | }; |
116 | }; |
117 | 117 | ||
118 | typedef Grid<float> FloatGrid; |
118 | typedef Grid<float> FloatGrid; |
- | 119 | ||
- | 120 | /** @class GridRunner is a helper class to iterate over a rectangular fraction of a grid
|
|
- | 121 | */
|
|
- | 122 | template <class T> |
|
- | 123 | class GridRunner { |
|
- | 124 | public: |
|
- | 125 | GridRunner(Grid<T> &target_grid, const QRectF &rectangle); |
|
- | 126 | T* next(); ///< to to next element, return NULL if finished |
|
- | 127 | private: |
|
- | 128 | T* mLast; |
|
- | 129 | T* mCurrent; |
|
- | 130 | size_t mLineLength; |
|
- | 131 | size_t mCols; |
|
- | 132 | size_t mCurrentCol; |
|
- | 133 | }; |
|
- | 134 | ||
119 | 135 | ||
120 | // copy constructor
|
136 | // copy constructor
|
121 | template <class T> |
137 | template <class T> |
122 | Grid<T>::Grid(const Grid<T>& toCopy) |
138 | Grid<T>::Grid(const Grid<T>& toCopy) |
123 | {
|
139 | {
|
Line 342... | Line 358... | ||
342 | template <class T> |
358 | template <class T> |
343 | const QPoint Grid<T>::randomPosition() const |
359 | const QPoint Grid<T>::randomPosition() const |
344 | {
|
360 | {
|
345 | return QPoint(irandom(0,mSizeX-1), irandom(0, mSizeY-1)); |
361 | return QPoint(irandom(0,mSizeX-1), irandom(0, mSizeY-1)); |
346 | }
|
362 | }
|
- | 363 | ||
- | 364 | ////////////////////////////////////////////////////////////
|
|
- | 365 | // grid runner
|
|
- | 366 | ////////////////////////////////////////////////////////////
|
|
- | 367 | template <class T> |
|
- | 368 | GridRunner<T>::GridRunner(Grid<T> &target_grid, const QRectF &rectangle) |
|
- | 369 | {
|
|
- | 370 | QPoint upper_left = target_grid.indexAt(rectangle.topLeft()); |
|
- | 371 | QPoint lower_right = target_grid.indexAt(rectangle.bottomRight()); |
|
- | 372 | mCurrent = target_grid.ptr(upper_left.x(), upper_left.y()); |
|
- | 373 | mLast = target_grid.ptr(lower_right.x()-1, lower_right.y()-1); |
|
- | 374 | mCols = lower_right.x() - upper_left.x(); // |
|
- | 375 | mLineLength = target_grid.sizeX() - mCols; |
|
- | 376 | mCurrentCol = 0; |
|
- | 377 | }
|
|
- | 378 | ||
- | 379 | template <class T> |
|
- | 380 | T* GridRunner<T>::next() |
|
- | 381 | {
|
|
- | 382 | if (mCurrent>mLast) |
|
- | 383 | return NULL; |
|
- | 384 | T* t = mCurrent; |
|
- | 385 | mCurrent++; |
|
- | 386 | mCurrentCol++; |
|
- | 387 | if (mCurrentCol >= mCols) { |
|
- | 388 | mCurrent += mLineLength; // skip to next line |
|
- | 389 | mCurrentCol = 0; |
|
- | 390 | }
|
|
- | 391 | return t; |
|
- | 392 | }
|
|
- | 393 | ||
347 | ////////////////////////////////////////////////////////////
|
394 | ////////////////////////////////////////////////////////////
|
348 | // global functions
|
395 | // global functions
|
349 | ////////////////////////////////////////////////////////////
|
396 | ////////////////////////////////////////////////////////////
|
350 | 397 | ||
351 | /// dumps a FloatGrid to a String.
|
398 | /// dumps a FloatGrid to a String.
|