Rev 648 | Rev 697 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
671 | werner | 2 | /******************************************************************************************** |
3 | ** iLand - an individual based forest landscape and disturbance model |
||
4 | ** http://iland.boku.ac.at |
||
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl |
||
6 | ** |
||
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 |
||
9 | ** the Free Software Foundation, either version 3 of the License, or |
||
10 | ** (at your option) any later version. |
||
11 | ** |
||
12 | ** This program is distributed in the hope that it will be useful, |
||
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | ** GNU General Public License for more details. |
||
16 | ** |
||
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/>. |
||
19 | ********************************************************************************************/ |
||
20 | |||
646 | werner | 21 | #ifndef LAYEREDGRID_H |
22 | #define LAYEREDGRID_H |
||
23 | |||
24 | #include "grid.h" |
||
25 | |||
26 | /** LayeredGrid |
||
27 | |||
28 | */ |
||
29 | |||
30 | class LayeredGridBase |
||
31 | { |
||
32 | public: |
||
33 | // access to properties |
||
647 | werner | 34 | virtual int sizeX() const=0; |
35 | virtual int sizeY() const=0; |
||
36 | virtual QRectF metricRect() const=0; |
||
37 | virtual QRectF cellRect(const QPoint &p) const=0; |
||
646 | werner | 38 | // available variables |
39 | virtual const QStringList names() const=0; |
||
40 | // statistics |
||
41 | /// retrieve min and max of variable 'index' |
||
647 | werner | 42 | virtual void range(double &rMin, double &rMax, const int index) const=0; |
646 | werner | 43 | |
44 | // data access functions |
||
647 | werner | 45 | virtual double value(const float x, const float y, const int index) const = 0; |
648 | werner | 46 | virtual double value(const QPointF &world_coord, const int index) const = 0; |
647 | werner | 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; |
||
646 | werner | 49 | }; |
50 | |||
51 | template <class T> |
||
52 | class LayeredGrid: public LayeredGridBase |
||
53 | { |
||
54 | public: |
||
55 | LayeredGrid(const Grid<T>& grid) { mGrid = &grid; } |
||
56 | LayeredGrid() { mGrid = 0; } |
||
647 | werner | 57 | QRectF cellRect(const QPoint &p) const { return mGrid->cellRect(p); } |
58 | QRectF metricRect() const { return mGrid->metricRect(); } |
||
59 | int sizeX() const { return mGrid->sizeX(); } |
||
60 | int sizeY() const { return mGrid->sizeY();} |
||
61 | |||
62 | virtual double value(const T& data, const int index) const = 0; |
||
646 | werner | 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); } |
||
65 | double value(const float x, const float y, const int index) const { return value(mGrid->constValueAt(x,y), index); } |
||
648 | werner | 66 | double value(const QPointF &world_coord, const int index) const { return value(mGrid->constValueAt(world_coord), index); } |
647 | werner | 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.; |
||
646 | werner | 69 | for (int i=0;i<mGrid->count(); ++i) { |
70 | rMin=qMin(rMin, value(i, index)); |
||
71 | rMax=qMax(rMax, value(i,index));}} |
||
72 | |||
73 | protected: |
||
74 | const Grid<T> *mGrid; |
||
75 | }; |
||
76 | |||
77 | #endif // LAYEREDGRID_H |