Subversion Repositories public iLand

Rev

Rev 170 | Rev 187 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1
 
3 Werner 2
#ifndef TREE_H
3
#define TREE_H
4
#include <QPointF>
5
 
83 Werner 6
#include "grid.h"
158 werner 7
// forwards
90 Werner 8
class Species;
38 Werner 9
class Stamp;
106 Werner 10
class RessourceUnit;
151 iland 11
struct HeightGridValue;
159 werner 12
struct TreeGrowthData;
3 Werner 13
 
14
class Tree
15
{
16
public:
141 Werner 17
    // lifecycle
3 Werner 18
    Tree();
141 Werner 19
    void setup();
20
 
21
    // access to properties
145 Werner 22
    int id() const { return mId; }
169 werner 23
    int age() const { return mAge; }
156 werner 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); }
158 werner 26
    float dbh() const { return mDbh; }
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.
29
    const RessourceUnit *ru() const { Q_ASSERT(mRU!=0); return mRU; } ///< pointer to the ressource unit the tree belongs to.
30
 
31
    float lightRessourceIndex() 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.
180 werner 33
    double basalArea() const; ///< basal area of the tree at breast height in m2
158 werner 34
    bool isDead() const { return flag(Tree::TreeDead); } ///< returns true if the tree is already dead.
35
    // actions
36
    void die() { setFlag(Tree::TreeDead, true); } ///< kills the tree.
37
    void enableDebugging(const bool enable=true) {setFlag(Tree::TreeDebugging, enable); }
38
 
39
    // setters for initialization
40
    void setNewId() { mId = m_nextId++; } ///< force a new id for this object (after copying trees)
156 werner 41
    void setPosition(const QPointF pos) { Q_ASSERT(mGrid!=0); mPositionIndex = mGrid->indexAt(pos); }
106 Werner 42
    void setDbh(const float dbh) { mDbh=dbh; }
43
    void setHeight(const float height) { mHeight=height; }
44
    void setSpecies(Species *ts) { mSpecies=ts; }
45
    void setRU(RessourceUnit *ru) { mRU = ru; }
170 werner 46
    void setAge(const int age) { mAge = age; }
158 werner 47
 
107 Werner 48
    // grid based light-concurrency functions
158 werner 49
    void applyLIP(); ///< apply LightInfluencePattern onto the global grid
50
    void readLIF(); ///< calculate the lightRessourceIndex with multiplicative approach
107 Werner 51
    void heightGrid(); ///< calculate the height grid
39 Werner 52
 
158 werner 53
    void applyLIP_torus(); ///< apply LightInfluencePattern on a closed 1ha area
54
    void readLIF_torus(); ///< calculate LRI from a closed 1ha area
55
    void heightGrid_torus(); ///< calculate the height grid
155 werner 56
 
107 Werner 57
    // growth, etc.
158 werner 58
    void grow(); ///< main growth function to update the tree state.
107 Werner 59
 
60
    // static functions
151 iland 61
    static void setGrid(FloatGrid* gridToStamp, Grid<HeightGridValue> *dominanceGrid);
40 Werner 62
    // statistics
63
    static void resetStatistics();
145 Werner 64
    static int statPrints() { return m_statPrint; }
65
    static int statCreated() { return m_statCreated; }
40 Werner 66
 
135 Werner 67
    QString dump();
145 Werner 68
    void dumpList(QList<QVariant> &rTargetList);
135 Werner 69
 
3 Werner 70
private:
110 Werner 71
    // helping functions
159 werner 72
    void partitioning(TreeGrowthData &d); ///< split NPP into various plant pools.
158 werner 73
    double relative_height_growth(); ///< estimate height growth based on light status.
159 werner 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
76
 
107 Werner 77
    // state variables
169 werner 78
    int mId; ///< unique ID of tree
79
    int mAge; ///< age of tree in years
125 Werner 80
    float mDbh; ///< diameter at breast height [cm]
81
    float mHeight; ///< tree height [m]
156 werner 82
    QPoint mPositionIndex; ///< index of the trees position on the basic LIF grid
107 Werner 83
    // biomass compartements
149 werner 84
    float mLeafArea; ///< m2 leaf area
85
    float mOpacity; ///< multiplier on LIP weights, depending on leaf area status (opacity of the crown)
136 Werner 86
    float mFoliageMass; // kg
87
    float mWoodyMass; // kg
107 Werner 88
    float mRootMass; // kg
116 Werner 89
    // production relevant
90
    float mNPPReserve; // kg
159 werner 91
    float mLRI; ///< resulting lightRessourceIndex
92
    // auxiliary
125 Werner 93
    float mDbhDelta; ///< diameter growth [cm]
159 werner 94
    float mStressIndex; ///< stress index (used for mortality)
95
 
107 Werner 96
    // Stamp, Species, Ressource Unit
106 Werner 97
    const Stamp *mStamp;
98
    Species *mSpecies;
99
    RessourceUnit *mRU;
107 Werner 100
 
157 werner 101
    // various flags
102
    int mFlags;
103
    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
    bool flag(const Tree::Flags flag) const { return mFlags & flag; }
139 Werner 106
 
117 Werner 107
    // special functions
157 werner 108
    bool isDebugging() { return flag(Tree::TreeDebugging); }
135 Werner 109
 
107 Werner 110
    // static data
106 Werner 111
    static FloatGrid *mGrid;
151 iland 112
    static Grid<HeightGridValue> *mHeightGrid;
53 Werner 113
 
40 Werner 114
    // statistics
115
    static int m_statPrint;
48 Werner 116
    static int m_statAboveZ;
105 Werner 117
    static int m_statCreated;
40 Werner 118
    static int m_nextId;
148 iland 119
 
120
    // friends
121
    friend class TreeWrapper;
180 werner 122
    friend class StandStatistics;
3 Werner 123
};
124
 
129 Werner 125
 
3 Werner 126
#endif // TREE_H