Subversion Repositories public iLand

Rev

Rev 1104 | Rev 1217 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1104 Rev 1157
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/grasscover.h':
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/grasscover.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
#ifndef GRASSCOVER_H
20
#ifndef GRASSCOVER_H
21
#define GRASSCOVER_H
21
#define GRASSCOVER_H
22
22
23
#include "expression.h"
23
#include "expression.h"
24
#include "grid.h"
24
#include "grid.h"
25
#include "layeredgrid.h"
25
#include "layeredgrid.h"
26
#include "random.h"
26
#include "random.h"
27
27
28
class GrassCoverLayers; // forwared
28
class GrassCoverLayers; // forwared
29
29
30
// define the data type that is used to store the grass-levels
30
// define the data type that is used to store the grass-levels
31
// use unsigned char for 1 byte (or quint8), unsigned short int (quint16) for two bytes per pixel
31
// use unsigned char for 1 byte (or quint8), unsigned short int (quint16) for two bytes per pixel
32
#define grass_grid_type qint16
32
#define grass_grid_type qint16
33
33
34
/**
34
/**
35
 * @brief The GrassCover class specifies the limiting effect of ground vegetation (grasses, herbs)
35
 * @brief The GrassCover class specifies the limiting effect of ground vegetation (grasses, herbs)
36
 * on the regeneration success of the tree species.
36
 * on the regeneration success of the tree species.
37
 * The GrassCover model is very simple and operates on a 2x2m grain.
37
 * The GrassCover model is very simple and operates on a 2x2m grain.
38
 */
38
 */
39
class GrassCover
39
class GrassCover
40
{
40
{
41
public:
41
public:
42
    GrassCover();
42
    GrassCover();
43
    ~GrassCover();
43
    ~GrassCover();
44
    void setup();
44
    void setup();
45
    // the number of steps used internally
45
    // the number of steps used internally
46
    static const int GRASSCOVERSTEPS = 32000;
46
    static const int GRASSCOVERSTEPS = 32000;
47
47
48
    /// set for all the pixels (LIFPixels) the corresponding grass value (in percent: 0-100)
48
    /// set for all the pixels (LIFPixels) the corresponding grass value (in percent: 0-100)
49
    void setInitialValues(const QVector<float*> &LIFpixels, const int percent);
49
    void setInitialValues(const QVector<float*> &LIFpixels, const int percent);
50
50
51
    /// main function (growth/die-off of grass cover)
51
    /// main function (growth/die-off of grass cover)
52
    void execute();
52
    void execute();
53
53
54
    // access
54
    // access
55
    /// returns 'true' if the module is enabled
55
    /// returns 'true' if the module is enabled
56
    bool enabled() const { return mEnabled; }
56
    bool enabled() const { return mEnabled; }
57
    ///
57
    ///
58
    double effect(grass_grid_type level) const { return mEffect[level]; }
58
    double effect(grass_grid_type level) const { return mEffect[level]; }
59
    double cover(const grass_grid_type &data) const  {return mType == Pixel? data : data/double(GRASSCOVERSTEPS-1);  }
59
    double cover(const grass_grid_type &data) const  {return mType == Pixel? data : data/double(GRASSCOVERSTEPS-1);  }
60
60
61
61
62
    /// main function
62
    /// main function
63
    double regenerationInhibition(QPoint &lif_index) const {
63
    double regenerationInhibition(QPoint &lif_index) const {
-
 
64
64
        if (mType==Pixel)
65
        if (mType==Pixel)
65
            return mGrid.constValueAtIndex(lif_index)>0 ? 1. : 0.;
-
 
66
        return mEnabled?effect(mGrid.constValueAtIndex(lif_index)) : 0.; }
-
 
-
 
66
            // -1: off, out of project area, 0: off, ready to get grassy again, 1: off (waiting for LIF threshold), >1 on, counting down
-
 
67
            return mGrid.constValueAtIndex(lif_index)>1 ? 1. : 0.;
-
 
68
-
 
69
        // type continuous
-
 
70
        return mEnabled?effect(mGrid.constValueAtIndex(lif_index)) : 0.;
-
 
71
    }
67
72
68
    /// retrieve the grid of current grass cover
73
    /// retrieve the grid of current grass cover
69
    const Grid<grass_grid_type> &grid() { return mGrid; }
74
    const Grid<grass_grid_type> &grid() { return mGrid; }
70
private:
75
private:
71
    enum GrassAlgorithmType { Invalid, Continuous, Pixel };
76
    enum GrassAlgorithmType { Invalid, Continuous, Pixel };
72
    GrassAlgorithmType mType;
77
    GrassAlgorithmType mType;
73
    bool mEnabled; ///< is module enabled?
78
    bool mEnabled; ///< is module enabled?
74
    Expression mGrassPotential; ///< function defining max. grass cover [0..1] as function of the LIF pixel value
79
    Expression mGrassPotential; ///< function defining max. grass cover [0..1] as function of the LIF pixel value
75
    Expression mGrassEffect; ///< equation giving probability of *prohibiting* regeneration as a function of grass level [0..1]
80
    Expression mGrassEffect; ///< equation giving probability of *prohibiting* regeneration as a function of grass level [0..1]
76
    int mMaxTimeLag; ///< maximum duration (years) from 0 to full cover
81
    int mMaxTimeLag; ///< maximum duration (years) from 0 to full cover
77
    double mEffect[GRASSCOVERSTEPS]; ///< effect lookup table
82
    double mEffect[GRASSCOVERSTEPS]; ///< effect lookup table
78
    Grid<grass_grid_type> mGrid; ///< grid covering state of grass cover (in integer steps)
83
    Grid<grass_grid_type> mGrid; ///< grid covering state of grass cover (in integer steps)
79
    int mGrowthRate; ///< max. annual growth rate of herbs and grasses (in 1/256th)
84
    int mGrowthRate; ///< max. annual growth rate of herbs and grasses (in 1/256th)
80
    grass_grid_type mMaxState; ///< potential at lif=1
85
    grass_grid_type mMaxState; ///< potential at lif=1
81
86
82
    RandomCustomPDF mPDF; ///< probability density function defining the life time of grass-pixels
87
    RandomCustomPDF mPDF; ///< probability density function defining the life time of grass-pixels
83
    float mGrassLIFThreshold; ///< if LIF>threshold, then the grass is considered as occupatied by grass
88
    float mGrassLIFThreshold; ///< if LIF>threshold, then the grass is considered as occupatied by grass
84
    GrassCoverLayers *mLayers; // visualization
89
    GrassCoverLayers *mLayers; // visualization
85
};
90
};
86
91
87
/** Helper class manage and visualize data layers.
92
/** Helper class manage and visualize data layers.
88

93

89
*/
94
*/
90
class GrassCoverLayers: public LayeredGrid<grass_grid_type> {
95
class GrassCoverLayers: public LayeredGrid<grass_grid_type> {
91
  public:
96
  public:
92
    void setGrid(const Grid<grass_grid_type> &grid, const GrassCover *gc) { mGrid = &grid; mGrassCover=gc; }
97
    void setGrid(const Grid<grass_grid_type> &grid, const GrassCover *gc) { mGrid = &grid; mGrassCover=gc; }
93
    double value(const grass_grid_type &data, const int index) const;
98
    double value(const grass_grid_type &data, const int index) const;
94
    const QVector<LayeredGridBase::LayerElement> &names();
99
    const QVector<LayeredGridBase::LayerElement> &names();
95
private:
100
private:
96
    QVector<LayeredGridBase::LayerElement> mNames;
101
    QVector<LayeredGridBase::LayerElement> mNames;
97
    const GrassCover *mGrassCover;
102
    const GrassCover *mGrassCover;
98
};
103
};
99
104
100
#endif // GRASSCOVER_H
105
#endif // GRASSCOVER_H
101
 
106