Subversion Repositories public iLand

Rev

Rev 648 | Rev 697 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 648 Rev 671
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
/********************************************************************************************
-
 
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
2
#ifndef LAYEREDGRID_H
21
#ifndef LAYEREDGRID_H
3
#define LAYEREDGRID_H
22
#define LAYEREDGRID_H
4
23
5
#include "grid.h"
24
#include "grid.h"
6
25
7
/** LayeredGrid
26
/** LayeredGrid
8

27

9
  */
28
  */
10
29
11
class LayeredGridBase
30
class LayeredGridBase
12
{
31
{
13
public:
32
public:
14
    // access to properties
33
    // access to properties
15
    virtual int sizeX() const=0;
34
    virtual int sizeX() const=0;
16
    virtual int sizeY() const=0;
35
    virtual int sizeY() const=0;
17
    virtual QRectF metricRect() const=0;
36
    virtual QRectF metricRect() const=0;
18
    virtual QRectF cellRect(const QPoint &p) const=0;
37
    virtual QRectF cellRect(const QPoint &p) const=0;
19
    // available variables
38
    // available variables
20
    virtual const QStringList names() const=0;
39
    virtual const QStringList names() const=0;
21
    // statistics
40
    // statistics
22
    /// retrieve min and max of variable 'index'
41
    /// retrieve min and max of variable 'index'
23
    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;
24
43
25
    // data access functions
44
    // data access functions
26
    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;
27
    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;
28
    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;
29
    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;
30
};
49
};
31
50
32
template <class T>
51
template <class T>
33
class LayeredGrid: public LayeredGridBase
52
class LayeredGrid: public LayeredGridBase
34
{
53
{
35
public:
54
public:
36
    LayeredGrid(const Grid<T>& grid) { mGrid = &grid; }
55
    LayeredGrid(const Grid<T>& grid) { mGrid = &grid; }
37
    LayeredGrid() { mGrid = 0; }
56
    LayeredGrid() { mGrid = 0; }
38
    QRectF cellRect(const QPoint &p) const { return mGrid->cellRect(p); }
57
    QRectF cellRect(const QPoint &p) const { return mGrid->cellRect(p); }
39
    QRectF metricRect() const { return mGrid->metricRect(); }
58
    QRectF metricRect() const { return mGrid->metricRect(); }
40
    int sizeX() const { return mGrid->sizeX(); }
59
    int sizeX() const { return mGrid->sizeX(); }
41
    int sizeY() const { return mGrid->sizeY();}
60
    int sizeY() const { return mGrid->sizeY();}
42
61
43
    virtual double value(const T& data, const int index) const = 0;
62
    virtual double value(const T& data, const int index) const = 0;
44
    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);  }
45
    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); }
46
    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); }
47
    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); }
48
    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); }
49
    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.;
50
                                                              for (int i=0;i<mGrid->count(); ++i) {
69
                                                              for (int i=0;i<mGrid->count(); ++i) {
51
                                                                  rMin=qMin(rMin, value(i, index));
70
                                                                  rMin=qMin(rMin, value(i, index));
52
                                                                  rMax=qMax(rMax, value(i,index));}}
71
                                                                  rMax=qMax(rMax, value(i,index));}}
53
72
54
protected:
73
protected:
55
    const Grid<T> *mGrid;
74
    const Grid<T> *mGrid;
56
};
75
};
57
76
58
#endif // LAYEREDGRID_H
77
#endif // LAYEREDGRID_H
59
 
78