iLand
fmtreelist.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 FMTREELIST_H
20#define FMTREELIST_H
21
22#include <QObject>
23#include "scriptglobal.h"
24#include "grid.h"
25#include "scripttree.h"
26
27class Tree; // forward
28class Expression;
29
30namespace ABE {
31class FMStand;
32
33class FMTreeList : public QObject
34{
35 Q_OBJECT
36 Q_PROPERTY(int stand READ standId)
37 Q_PROPERTY(int count READ count)
38 Q_PROPERTY(bool simulate READ simulate WRITE setSimulate)
39public:
40
41 explicit FMTreeList(QObject *parent = 0);
42 explicit FMTreeList(FMStand *stand, QObject *parent = 0);
44 int standId() const { return mStandId; }
45 void setStand(FMStand *stand);
46 bool simulate() const {return mOnlySimulate; }
47 void setSimulate(bool do_simulate) {mOnlySimulate = do_simulate; }
48 int count() const { return mTrees.count(); }
49
51 int loadFromRect(ResourceUnit *ru, const QRectF &rect);
52
54 int loadFromRU(ResourceUnit *ru, bool append=false);
55
57 const QVector<QPair<Tree*, double> > trees() const { return mTrees; }
58
60 Grid<float> &localGrid() { prepareGrids(); return mLocalGrid; }
61
62signals:
63
64public slots:
65 // loading of trees
67 int loadAll() { return load(QString()); }
69 int load(const QString &filter);
70
73 int filter(QString filter);
74
77 int spatialFilter(QJSValue grid, QString filter);
78
81
83 int resetMarks();
84
86 QJSValue tree(int index);
88 QJSValue treeObject(int index);
89
90
95// int killPct(int pctfrom, int pctto, int number);
96// int killAll(); ///< kill all trees in the list
98// int kill(QString filter, double fraction);
99 // management
105// int managePct(int pctfrom, int pctto, int number);
106// int manageAll(); ///< manage all trees in the list
108 int kill(QString filter=QString());
109
111 int harvest(QString filter=QString(), double fraction=1.);
112
113 double percentile(int pct);
114// void killSaplings(MapGridWrapper *wrap, int key); ///< kill all saplings that are on the area denoted by 'key' of the given grid (script access)
115
118// void removeSoilCarbon(MapGridWrapper *wrap, int key, double SWDfrac, double DWDfrac, double litterFrac, double soilFrac);
122// void slashSnags(MapGridWrapper *wrap, int key, double slash_fraction);
126 void sort(QString statement);
127// int filter(QString filter); ///< apply a filter on the list of trees (expression), return number of remaining trees.
128// int filterIdList(QVariantList idList); ///< apply filter in form of a list of ids, return number of remaining trees
129 void randomize();
130
132 double mean(QString expression, QString filter=QString()) { return aggregate_function( expression, filter, "mean"); }
134 double sum(QString expression, QString filter=QString()) { return aggregate_function( expression, filter, "sum"); }
135
138 void prepareStandGrid(QString type, QString custom_expression=QString());
139 void exportStandGrid(QString file_name);
140 FloatGrid &standGrid() {return mStandGrid; }
141
143 int killSaplings(QString expression);
145 double meanSaplings(QString expression, QString filter=QString()) { return aggregate_function_sapling(expression, filter, "mean"); }
147 double sumSaplings(QString expression, QString filter=QString()) { return aggregate_function_sapling(expression, filter, "sum"); }
148
149
150
151private:
152 bool trace() const;
154 int remove_percentiles(int pctfrom, int pctto, int number, bool management);
155 int remove_trees(QString expression, double fraction, bool management);
156 double aggregate_function(QString expression, QString filter, QString type);
157 double aggregate_function_sapling(QString expression, QString filter, QString type);
158 bool remove_single_tree(int index, bool harvest=true);
159 void check_locks();
160
161 // grid functions
162 void prepareGrids();
166 void runGrid(void (*func)(float &, int &, const Tree *, const FMTreeList *) );
167
168 QVector<QPair<Tree*, double> > mTrees;
169 bool mResourceUnitsLocked;
170 int mRemoved;
171 FMStand *mStand;
172 int mStandId;
173 int mNumberOfStems;
174 bool mOnlySimulate;
175 QRectF mStandRect;
176 FloatGrid mStandGrid;
177 Grid<int> mTreeCountGrid;
178 Grid<float> mLocalGrid;
179 Expression *mRunGridCustom;
180 double *mRunGridCustomCell;
181 friend void rungrid_custom(float &cell, int &n, const Tree *tree, const FMTreeList *list);
182
183 QJSValue mTreeValue;
184 ScriptTree *mTree;
185
186
187 friend class ActThinning;
188};
189
190} // namespace
191#endif // FMTREELIST_H
The ActThinning class implements a very general interface to thinning activties.
Definition: actthinning.h:34
FMStand encapsulates a forest stand for the forest management engine.
Definition: fmstand.h:49
The FMTreeList class implements low-level functionality for selecting and harvesting of trees.
Definition: fmtreelist.h:34
double mean(QString expression, QString filter=QString())
calculate the mean value for all trees in the internal list for 'expression' (filtered by the filter ...
Definition: fmtreelist.h:132
int killSaplings(QString expression)
modify sapling
Definition: fmtreelist.cpp:685
double sum(QString expression, QString filter=QString())
calculate the sum for all trees in the internal list for the 'expression' (filtered by the filter cri...
Definition: fmtreelist.h:134
int loadFromRect(ResourceUnit *ru, const QRectF &rect)
load trees from a portion of a RU
Definition: fmtreelist.cpp:95
void randomize()
random shuffle of all trees in the list
Definition: fmtreelist.cpp:548
int spatialFilter(QJSValue grid, QString filter)
spatial filter within the stand trees are kept in the list if the expession 'filter' returns true for...
Definition: fmtreelist.cpp:179
const QVector< QPair< Tree *, double > > trees() const
access the list of trees
Definition: fmtreelist.h:57
FMTreeList(QObject *parent=0)
Definition: fmtreelist.cpp:52
void prepareStandGrid(QString type, QString custom_expression=QString())
set up internally a map (10m grid cells) of the stand with a given grid type or using a custom expres...
Definition: fmtreelist.cpp:650
Grid< float > & localGrid()
access to local grid (setup if necessary)
Definition: fmtreelist.h:60
int filter(QString filter)
apply a filter on the current tree list.
Definition: fmtreelist.cpp:158
double sumSaplings(QString expression, QString filter=QString())
calculate the sum for all trees in the internal list for the 'expression' (filtered by the filter cri...
Definition: fmtreelist.h:147
int kill(QString filter=QString())
kill "number" of stems in the percentile interval "from" - "to".
Definition: fmtreelist.cpp:274
friend void rungrid_custom(float &cell, int &n, const Tree *tree, const FMTreeList *list)
Definition: fmtreelist.cpp:641
int load(const QString &filter)
load all trees passing the filter, return number of trees (load only living trees)
Definition: fmtreelist.cpp:121
FloatGrid & standGrid()
Definition: fmtreelist.h:140
bool simulate
if 'simulate' is true, trees are only marked for removal
Definition: fmtreelist.h:38
void setSimulate(bool do_simulate)
Definition: fmtreelist.h:47
void setStand(FMStand *stand)
Definition: fmtreelist.cpp:78
void exportStandGrid(QString file_name)
Definition: fmtreelist.cpp:678
bool simulate() const
Definition: fmtreelist.h:46
int loadAll()
load all trees of the stand, return number of trees (living trees)
Definition: fmtreelist.h:67
QJSValue tree(int index)
access to single trees (returns a reference)
Definition: fmtreelist.cpp:251
int count() const
Definition: fmtreelist.h:48
int removeMarkedTrees()
load all trees of the stand and either kill or harvest trees that are marked for that operation.
Definition: fmtreelist.cpp:217
~FMTreeList()
Definition: fmtreelist.cpp:73
double percentile(int pct)
get value for the pct th percentile (1..100)
Definition: fmtreelist.cpp:534
void sort(QString statement)
hacky access function to resource units covered by a polygon.
Definition: fmtreelist.cpp:521
int stand
return stand, -1 if not set
Definition: fmtreelist.h:36
int resetMarks()
reset all marks of currently loaded trees to zero
Definition: fmtreelist.cpp:237
int standId() const
Definition: fmtreelist.h:44
QJSValue treeObject(int index)
return a copy of a tree
Definition: fmtreelist.cpp:261
int count
return the number of trees that are currently loaded
Definition: fmtreelist.h:37
int harvest(QString filter=QString(), double fraction=1.)
manage 'fraction' of all trees [0..1] with 'filter'.
Definition: fmtreelist.cpp:279
double meanSaplings(QString expression, QString filter=QString())
calculate the mean value for all trees in the internal list for 'expression' (filtered by the filter ...
Definition: fmtreelist.h:145
int loadFromRU(ResourceUnit *ru, bool append=false)
load all trees from a RU
Definition: fmtreelist.cpp:106
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
ResourceUnit is the spatial unit that encapsulates a forest stand and links to several environmental ...
Definition: resourceunit.h:49
Definition: scripttree.h:10
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
Definition: abegrid.h:22