Rev 671 | Rev 717 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 671 | Rev 697 | ||
---|---|---|---|
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/layeredgrid.h': |
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/layeredgrid.h': |
2 | /********************************************************************************************
|
2 | /********************************************************************************************
|
3 | ** iLand - an individual based forest landscape and disturbance model
|
3 | ** iLand - an individual based forest landscape and disturbance model
|
4 | ** http://iland.boku.ac.at
|
4 | ** http://iland.boku.ac.at
|
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl
|
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl
|
6 | **
|
6 | **
|
7 | ** This program is free software: you can redistribute it and/or modify
|
7 | ** This program is free software: you can redistribute it and/or modify
|
8 | ** it under the terms of the GNU General Public License as published by
|
8 | ** it under the terms of the GNU General Public License as published by
|
9 | ** the Free Software Foundation, either version 3 of the License, or
|
9 | ** the Free Software Foundation, either version 3 of the License, or
|
10 | ** (at your option) any later version.
|
10 | ** (at your option) any later version.
|
11 | **
|
11 | **
|
12 | ** This program is distributed in the hope that it will be useful,
|
12 | ** This program is distributed in the hope that it will be useful,
|
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | ** GNU General Public License for more details.
|
15 | ** GNU General Public License for more details.
|
16 | **
|
16 | **
|
17 | ** You should have received a copy of the GNU General Public License
|
17 | ** You should have received a copy of the GNU General Public License
|
18 | ** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 | ** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 | ********************************************************************************************/
|
19 | ********************************************************************************************/
|
20 | 20 | ||
21 | #ifndef LAYEREDGRID_H
|
21 | #ifndef LAYEREDGRID_H
|
22 | #define LAYEREDGRID_H
|
22 | #define LAYEREDGRID_H
|
23 | 23 | ||
24 | #include "grid.h"
|
24 | #include "grid.h"
|
25 | 25 | ||
26 | /** LayeredGrid
|
26 | /** LayeredGrid
|
27 | - | ||
- | 27 | @ingroup tools
|
|
28 | */
|
28 | */
|
29 | 29 | ||
30 | class LayeredGridBase
|
30 | class LayeredGridBase
|
31 | {
|
31 | {
|
32 | public: |
32 | public: |
33 | // access to properties
|
33 | // access to properties
|
34 | virtual int sizeX() const=0; |
34 | virtual int sizeX() const=0; |
35 | virtual int sizeY() const=0; |
35 | virtual int sizeY() const=0; |
36 | virtual QRectF metricRect() const=0; |
36 | virtual QRectF metricRect() const=0; |
37 | virtual QRectF cellRect(const QPoint &p) const=0; |
37 | virtual QRectF cellRect(const QPoint &p) const=0; |
38 | // available variables
|
38 | // available variables
|
39 | virtual const QStringList names() const=0; |
39 | virtual const QStringList names() const=0; |
40 | // statistics
|
40 | // statistics
|
41 | /// retrieve min and max of variable 'index'
|
41 | /// retrieve min and max of variable 'index'
|
42 | virtual void range(double &rMin, double &rMax, const int index) const=0; |
42 | virtual void range(double &rMin, double &rMax, const int index) const=0; |
43 | 43 | ||
44 | // data access functions
|
44 | // data access functions
|
45 | virtual double value(const float x, const float y, const int index) const = 0; |
45 | virtual double value(const float x, const float y, const int index) const = 0; |
46 | virtual double value(const QPointF &world_coord, const int index) const = 0; |
46 | virtual double value(const QPointF &world_coord, const int index) const = 0; |
47 | virtual double value(const int ix, const int iy, const int index) const = 0; |
47 | virtual double value(const int ix, const int iy, const int index) const = 0; |
48 | virtual double value(const int grid_index, const int index) const = 0; |
48 | virtual double value(const int grid_index, const int index) const = 0; |
49 | }; |
49 | }; |
50 | 50 | ||
51 | template <class T> |
51 | template <class T> |
52 | class LayeredGrid: public LayeredGridBase |
52 | class LayeredGrid: public LayeredGridBase |
53 | {
|
53 | {
|
54 | public: |
54 | public: |
55 | LayeredGrid(const Grid<T>& grid) { mGrid = &grid; } |
55 | LayeredGrid(const Grid<T>& grid) { mGrid = &grid; } |
56 | LayeredGrid() { mGrid = 0; } |
56 | LayeredGrid() { mGrid = 0; } |
57 | QRectF cellRect(const QPoint &p) const { return mGrid->cellRect(p); } |
57 | QRectF cellRect(const QPoint &p) const { return mGrid->cellRect(p); } |
58 | QRectF metricRect() const { return mGrid->metricRect(); } |
58 | QRectF metricRect() const { return mGrid->metricRect(); } |
59 | int sizeX() const { return mGrid->sizeX(); } |
59 | int sizeX() const { return mGrid->sizeX(); } |
60 | int sizeY() const { return mGrid->sizeY();} |
60 | int sizeY() const { return mGrid->sizeY();} |
61 | 61 | ||
62 | virtual double value(const T& data, const int index) const = 0; |
62 | virtual double value(const T& data, const int index) const = 0; |
63 | double value(const T* ptr, const int index) const { return value(mGrid->constValueAtIndex(mGrid->indexOf(ptr)), index); } |
63 | double value(const T* ptr, const int index) const { return value(mGrid->constValueAtIndex(mGrid->indexOf(ptr)), index); } |
64 | double value(const int grid_index, const int index) const { return value(mGrid->constValueAtIndex(grid_index), index); } |
64 | double value(const int grid_index, const int index) const { return value(mGrid->constValueAtIndex(grid_index), index); } |
65 | double value(const float x, const float y, const int index) const { return value(mGrid->constValueAt(x,y), index); } |
65 | double value(const float x, const float y, const int index) const { return value(mGrid->constValueAt(x,y), index); } |
66 | double value(const QPointF &world_coord, const int index) const { return value(mGrid->constValueAt(world_coord), index); } |
66 | double value(const QPointF &world_coord, const int index) const { return value(mGrid->constValueAt(world_coord), index); } |
67 | double value(const int ix, const int iy, const int index) const { return value(mGrid->constValueAtIndex(ix, iy), index); } |
67 | double value(const int ix, const int iy, const int index) const { return value(mGrid->constValueAtIndex(ix, iy), index); } |
68 | void range(double &rMin, double &rMax, const int index) const { rMin=9999999999.; rMax=-99999999999.; |
68 | void range(double &rMin, double &rMax, const int index) const { rMin=9999999999.; rMax=-99999999999.; |
69 | for (int i=0;i<mGrid->count(); ++i) { |
69 | for (int i=0;i<mGrid->count(); ++i) { |
70 | rMin=qMin(rMin, value(i, index)); |
70 | rMin=qMin(rMin, value(i, index)); |
71 | rMax=qMax(rMax, value(i,index));}} |
71 | rMax=qMax(rMax, value(i,index));}} |
72 | 72 | ||
73 | protected: |
73 | protected: |
74 | const Grid<T> *mGrid; |
74 | const Grid<T> *mGrid; |
75 | }; |
75 | }; |
76 | 76 | ||
77 | #endif // LAYEREDGRID_H
|
77 | #endif // LAYEREDGRID_H
|
78 | 78 |