iLand
grasscover.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19#ifndef GRASSCOVER_H
20#define GRASSCOVER_H
21
22#include "expression.h"
23#include "grid.h"
24#include "layeredgrid.h"
25#include "random.h"
26
27class GrassCoverLayers; // forwared
28
29// define the data type that is used to store the grass-levels
30// use unsigned char for 1 byte (or quint8), unsigned short int (quint16) for two bytes per pixel
31#define grass_grid_type qint16
32
39{
40public:
41 GrassCover();
43 void setup();
44 // the number of steps used internally
45 static const int GRASSCOVERSTEPS = 32000;
46
48 void setInitialValues(const QVector<float*> &LIFpixels, const int percent);
49
51 void execute();
54
55 // access
57 bool enabled() const { return mEnabled; }
58
61 GrassAlgorithmType mode() const { return mType; }
62
63
64 float lifThreshold() const { return mGrassLIFThreshold; }
65 // access values of the underlying grid (for visualization)
66 double effect(grass_grid_type level) const { return mEffect[level]; }
67 double cover(const grass_grid_type &data) const {return mType == Pixel? data : data/double(GRASSCOVERSTEPS-1); }
68 // access value for simplified mode
69
70
72 double regenerationInhibition(QPoint &lif_index) const {
73
74 if (mType==Pixel)
75 // -1: off, out of project area, 0: off, ready to get grassy again, 1: off (waiting for LIF threshold), >1 on, counting down
76 return mGrid.constValueAtIndex(lif_index)>1 ? 1. : 0.;
77
78 // type continuous
79 return mEnabled?effect(mGrid.constValueAtIndex(lif_index)) : 0.;
80 }
81
83 const Grid<grass_grid_type> &grid() { return mGrid; }
84private:
85
87 bool mEnabled;
88 Expression mGrassPotential;
89 Expression mGrassEffect;
90 int mMaxTimeLag;
91 double mEffect[GRASSCOVERSTEPS];
93 int mGrowthRate;
94 grass_grid_type mMaxState;
95
96 RandomCustomPDF mPDF;
97 float mGrassLIFThreshold;
98 GrassCoverLayers *mLayers; // visualization
99};
100
104class GrassCoverLayers: public LayeredGrid<grass_grid_type> {
105 public:
106 void setGrid(const Grid<grass_grid_type> &grid, const GrassCover *gc) { mGrid = &grid; mGrassCover=gc; }
107 double value(const grass_grid_type &data, const int index) const;
108 const QVector<LayeredGridBase::LayerElement> &names();
109private:
110 QVector<LayeredGridBase::LayerElement> mNames;
111 const GrassCover *mGrassCover;
112};
113
114#endif // GRASSCOVER_H
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
The GrassCover class specifies the limiting effect of ground vegetation (grasses, herbs) on the regen...
Definition: grasscover.h:39
float lifThreshold() const
Definition: grasscover.h:64
~GrassCover()
Definition: grasscover.cpp:38
double cover(const grass_grid_type &data) const
Definition: grasscover.h:67
void executeAfterRegeneration()
function called after the regeneration module
Definition: grasscover.cpp:221
bool enabled() const
returns 'true' if the module is enabled
Definition: grasscover.h:57
GrassCover()
Definition: grasscover.cpp:30
static const int GRASSCOVERSTEPS
Definition: grasscover.h:45
void execute()
main function (growth/die-off of grass cover)
Definition: grasscover.cpp:169
double effect(grass_grid_type level) const
Definition: grasscover.h:66
void setInitialValues(const QVector< float * > &LIFpixels, const int percent)
set for all the pixels (LIFPixels) the corresponding grass value (in percent: 0-100)
Definition: grasscover.cpp:138
GrassAlgorithmType mode() const
Definition: grasscover.h:61
const Grid< grass_grid_type > & grid()
retrieve the grid of current grass cover
Definition: grasscover.h:83
void setup()
Definition: grasscover.cpp:43
GrassAlgorithmType
used algorithm
Definition: grasscover.h:60
@ Continuous
Definition: grasscover.h:60
@ Pixel
Definition: grasscover.h:60
@ Invalid
Definition: grasscover.h:60
@ Simplified
Definition: grasscover.h:60
double regenerationInhibition(QPoint &lif_index) const
main function
Definition: grasscover.h:72
Helper class manage and visualize data layers.
Definition: grasscover.h:104
void setGrid(const Grid< grass_grid_type > &grid, const GrassCover *gc)
Definition: grasscover.h:106
const QVector< LayeredGridBase::LayerElement > & names()
list of stored layers
Definition: grasscover.cpp:260
double value(const grass_grid_type &data, const int index) const
Definition: grasscover.cpp:240
Grid class (template).
Definition: grid.h:44
This is the base class for multi-layer grids in iLand.
Definition: layeredgrid.h:95
const Grid< grass_grid_type > * mGrid
Definition: layeredgrid.h:130
numbers with a user defined probaility density function.
Definition: random.h:62
#define grass_grid_type
Definition: grasscover.h:31