Subversion Repositories public iLand

Rev

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

Rev 187 Rev 212
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/tree.h':
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/tree.h':
2
#ifndef TREE_H
2
#ifndef TREE_H
3
#define TREE_H
3
#define TREE_H
4
#include <QPointF>
4
#include <QPointF>
5
5
6
#include "grid.h"
6
#include "grid.h"
7
// forwards
7
// forwards
8
class Species;
8
class Species;
9
class Stamp;
9
class Stamp;
10
class ResourceUnit;
10
class ResourceUnit;
11
struct HeightGridValue;
11
struct HeightGridValue;
12
struct TreeGrowthData;
12
struct TreeGrowthData;
13
13
14
class Tree
14
class Tree
15
{
15
{
16
public:
16
public:
17
    // lifecycle
17
    // lifecycle
18
    Tree();
18
    Tree();
19
    void setup();
19
    void setup();
20
20
21
    // access to properties
21
    // access to properties
22
    int id() const { return mId; }
22
    int id() const { return mId; }
23
    int age() const { return mAge; }
23
    int age() const { return mAge; }
24
    /// @property position The tree does not store the floating point coordinates but only the index of pixel on the LIF grid
24
    /// @property position The tree does not store the floating point coordinates but only the index of pixel on the LIF grid
25
    const QPointF position() const { Q_ASSERT(mGrid!=0); return mGrid->cellCenterPoint(mPositionIndex); }
25
    const QPointF position() const { Q_ASSERT(mGrid!=0); return mGrid->cellCenterPoint(mPositionIndex); }
26
    float dbh() const { return mDbh; }
26
    float dbh() const { return mDbh; }
27
    float height() const { return mHeight; }
27
    float height() const { return mHeight; }
28
    const Species* species() const { Q_ASSERT(mRU!=0); return mSpecies; } ///< pointer to the tree species of the tree.
28
    const Species* species() const { Q_ASSERT(mRU!=0); return mSpecies; } ///< pointer to the tree species of the tree.
29
    const ResourceUnit *ru() const { Q_ASSERT(mRU!=0); return mRU; } ///< pointer to the ressource unit the tree belongs to.
29
    const ResourceUnit *ru() const { Q_ASSERT(mRU!=0); return mRU; } ///< pointer to the ressource unit the tree belongs to.
30
30
31
    float lightResourceIndex() const { return mLRI; } ///< LRI of the tree (update during readStamp())
31
    float lightResourceIndex() const { return mLRI; } ///< LRI of the tree (update during readStamp())
32
    double volume() const; ///< volume (m3) of stem volume based on geometry and density calculated on the fly.
32
    double volume() const; ///< volume (m3) of stem volume based on geometry and density calculated on the fly.
33
    double basalArea() const; ///< basal area of the tree at breast height in m2
33
    double basalArea() const; ///< basal area of the tree at breast height in m2
34
    bool isDead() const { return flag(Tree::TreeDead); } ///< returns true if the tree is already dead.
34
    bool isDead() const { return flag(Tree::TreeDead); } ///< returns true if the tree is already dead.
35
    // actions
35
    // actions
36
    void die() { setFlag(Tree::TreeDead, true); } ///< kills the tree.
36
    void die() { setFlag(Tree::TreeDead, true); } ///< kills the tree.
37
    void enableDebugging(const bool enable=true) {setFlag(Tree::TreeDebugging, enable); }
37
    void enableDebugging(const bool enable=true) {setFlag(Tree::TreeDebugging, enable); }
38
38
39
    // setters for initialization
39
    // setters for initialization
40
    void setNewId() { mId = m_nextId++; } ///< force a new id for this object (after copying trees)
40
    void setNewId() { mId = m_nextId++; } ///< force a new id for this object (after copying trees)
41
    void setPosition(const QPointF pos) { Q_ASSERT(mGrid!=0); mPositionIndex = mGrid->indexAt(pos); }
41
    void setPosition(const QPointF pos) { Q_ASSERT(mGrid!=0); mPositionIndex = mGrid->indexAt(pos); }
42
    void setDbh(const float dbh) { mDbh=dbh; }
42
    void setDbh(const float dbh) { mDbh=dbh; }
43
    void setHeight(const float height) { mHeight=height; }
43
    void setHeight(const float height) { mHeight=height; }
44
    void setSpecies(Species *ts) { mSpecies=ts; }
44
    void setSpecies(Species *ts) { mSpecies=ts; }
45
    void setRU(ResourceUnit *ru) { mRU = ru; }
45
    void setRU(ResourceUnit *ru) { mRU = ru; }
46
    void setAge(const int age) { mAge = age; }
46
    void setAge(const int age) { mAge = age; }
47
47
48
    // grid based light-concurrency functions
48
    // grid based light-concurrency functions
49
    void applyLIP(); ///< apply LightInfluencePattern onto the global grid
49
    void applyLIP(); ///< apply LightInfluencePattern onto the global grid
50
    void readLIF(); ///< calculate the lightResourceIndex with multiplicative approach
50
    void readLIF(); ///< calculate the lightResourceIndex with multiplicative approach
51
    void heightGrid(); ///< calculate the height grid
51
    void heightGrid(); ///< calculate the height grid
52
52
53
    void applyLIP_torus(); ///< apply LightInfluencePattern on a closed 1ha area
53
    void applyLIP_torus(); ///< apply LightInfluencePattern on a closed 1ha area
54
    void readLIF_torus(); ///< calculate LRI from a closed 1ha area
54
    void readLIF_torus(); ///< calculate LRI from a closed 1ha area
55
    void heightGrid_torus(); ///< calculate the height grid
55
    void heightGrid_torus(); ///< calculate the height grid
56
56
57
    // growth, etc.
57
    // growth, etc.
58
    void grow(); ///< main growth function to update the tree state.
58
    void grow(); ///< main growth function to update the tree state.
59
59
60
    // static functions
60
    // static functions
61
    static void setGrid(FloatGrid* gridToStamp, Grid<HeightGridValue> *dominanceGrid);
61
    static void setGrid(FloatGrid* gridToStamp, Grid<HeightGridValue> *dominanceGrid);
62
    // statistics
62
    // statistics
63
    static void resetStatistics();
63
    static void resetStatistics();
64
    static int statPrints() { return m_statPrint; }
64
    static int statPrints() { return m_statPrint; }
65
    static int statCreated() { return m_statCreated; }
65
    static int statCreated() { return m_statCreated; }
66
66
67
    QString dump();
67
    QString dump();
68
    void dumpList(QList<QVariant> &rTargetList);
68
    void dumpList(QList<QVariant> &rTargetList);
69
69
70
private:
70
private:
71
    // helping functions
71
    // helping functions
72
    void partitioning(TreeGrowthData &d); ///< split NPP into various plant pools.
72
    void partitioning(TreeGrowthData &d); ///< split NPP into various plant pools.
73
    double relative_height_growth(); ///< estimate height growth based on light status.
73
    double relative_height_growth(); ///< estimate height growth based on light status.
74
    void grow_diameter(TreeGrowthData &d); ///< actual growth of the tree's stem.
74
    void grow_diameter(TreeGrowthData &d); ///< actual growth of the tree's stem.
75
    void mortality(TreeGrowthData &d); ///< main function that checks whether trees is to die
75
    void mortality(TreeGrowthData &d); ///< main function that checks whether trees is to die
76
76
77
    // state variables
77
    // state variables
78
    int mId; ///< unique ID of tree
78
    int mId; ///< unique ID of tree
79
    int mAge; ///< age of tree in years
79
    int mAge; ///< age of tree in years
80
    float mDbh; ///< diameter at breast height [cm]
80
    float mDbh; ///< diameter at breast height [cm]
81
    float mHeight; ///< tree height [m]
81
    float mHeight; ///< tree height [m]
82
    QPoint mPositionIndex; ///< index of the trees position on the basic LIF grid
82
    QPoint mPositionIndex; ///< index of the trees position on the basic LIF grid
83
    // biomass compartements
83
    // biomass compartements
84
    float mLeafArea; ///< m2 leaf area
84
    float mLeafArea; ///< m2 leaf area
85
    float mOpacity; ///< multiplier on LIP weights, depending on leaf area status (opacity of the crown)
85
    float mOpacity; ///< multiplier on LIP weights, depending on leaf area status (opacity of the crown)
86
    float mFoliageMass; // kg
86
    float mFoliageMass; // kg
87
    float mWoodyMass; // kg
87
    float mWoodyMass; // kg
88
    float mRootMass; // kg
88
    float mRootMass; // kg
89
    // production relevant
89
    // production relevant
90
    float mNPPReserve; // kg
90
    float mNPPReserve; // kg
91
    float mLRI; ///< resulting lightResourceIndex
91
    float mLRI; ///< resulting lightResourceIndex
-
 
92
    float mLightResponse; ///< light response used for distribution of biomass on RU level
92
    // auxiliary
93
    // auxiliary
93
    float mDbhDelta; ///< diameter growth [cm]
94
    float mDbhDelta; ///< diameter growth [cm]
94
    float mStressIndex; ///< stress index (used for mortality)
95
    float mStressIndex; ///< stress index (used for mortality)
95
96
96
    // Stamp, Species, Resource Unit
97
    // Stamp, Species, Resource Unit
97
    const Stamp *mStamp;
98
    const Stamp *mStamp;
98
    Species *mSpecies;
99
    Species *mSpecies;
99
    ResourceUnit *mRU;
100
    ResourceUnit *mRU;
100
101
101
    // various flags
102
    // various flags
102
    int mFlags;
103
    int mFlags;
103
    enum Flags { TreeDead=1, TreeDebugging=2 };
104
    enum Flags { TreeDead=1, TreeDebugging=2 };
104
    void setFlag(const Tree::Flags flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );}
105
    void setFlag(const Tree::Flags flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );}
105
    bool flag(const Tree::Flags flag) const { return mFlags & flag; }
106
    bool flag(const Tree::Flags flag) const { return mFlags & flag; }
106
107
107
    // special functions
108
    // special functions
108
    bool isDebugging() { return flag(Tree::TreeDebugging); }
109
    bool isDebugging() { return flag(Tree::TreeDebugging); }
109
110
110
    // static data
111
    // static data
111
    static FloatGrid *mGrid;
112
    static FloatGrid *mGrid;
112
    static Grid<HeightGridValue> *mHeightGrid;
113
    static Grid<HeightGridValue> *mHeightGrid;
113
114
114
    // statistics
115
    // statistics
115
    static int m_statPrint;
116
    static int m_statPrint;
116
    static int m_statAboveZ;
117
    static int m_statAboveZ;
117
    static int m_statCreated;
118
    static int m_statCreated;
118
    static int m_nextId;
119
    static int m_nextId;
119
120
120
    // friends
121
    // friends
121
    friend class TreeWrapper;
122
    friend class TreeWrapper;
122
    friend class StandStatistics;
123
    friend class StandStatistics;
123
};
124
};
124
125
125
126
126
#endif // TREE_H
127
#endif // TREE_H
127
 
128