Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | werner | 1 | /******************************************************************************************** |
2 | ** iLand - an individual based forest landscape and disturbance model |
||
3 | ** http://iland.boku.ac.at |
||
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 | |||
33 | Werner | 20 | #ifndef STAMPCONTAINER_H |
21 | #define STAMPCONTAINER_H |
||
22 | |||
23 | #include "stamp.h" |
||
24 | #include "grid.h" |
||
25 | |||
247 | werner | 26 | /** Collection of Stamp for one tree species. |
697 | werner | 27 | @ingroup core |
33 | Werner | 28 | Per species several stamps are stored (different BHD, different HD relations). This class |
29 | encapsulates storage and access to these stamps. The design goal is to deliver high |
||
38 | Werner | 30 | access speeds for the "stamp()" method. |
33 | Werner | 31 | Use getStamp(bhd, hd) or getStamp(bhd, height) to access. */ |
32 | class StampContainer |
||
33 | { |
||
34 | public: |
||
35 | StampContainer(); |
||
36 | ~StampContainer(); |
||
37 | void useLookup(const bool use) { m_useLookup = use; } |
||
38 | /// addStamp() add a pre-allocated stamp @param stamp to internal collection. Caller must allocate stamp on the heap, |
||
39 | /// freeing is done by this class. |
||
65 | Werner | 40 | void addStamp(Stamp* stamp, const float dbh, const float hd_value, const float crown_radius); |
64 | Werner | 41 | void addReaderStamp(Stamp *stamp, const float crown_radius_m); |
39 | Werner | 42 | const Stamp* stamp(const float bhd_cm, const float height_m) const; |
40 | Werner | 43 | const Stamp* readerStamp(const float crown_radius_m) const; ///< retrieve reader-stamp. @param radius of crown in m. @return the appropriate stamp or NULL if not found. |
145 | Werner | 44 | int count() const { return m_stamps.count(); } |
33 | Werner | 45 | /// save the content of the StampContainer to the output stream (binary encoding) |
46 | void save(QDataStream &out); |
||
34 | Werner | 47 | /// load the content of the StampContainer to the output stream (binary encoding) |
33 | Werner | 48 | void load(QDataStream &in); |
99 | Werner | 49 | void load(const QString &fileName); |
34 | Werner | 50 | |
47 | Werner | 51 | /** this functions attaches the appropriate reader (dep. on crown radius) to each stamp of the container. |
52 | The reader-stamp is returned by a call to the reader()-function of the Stamp itself. |
||
53 | @param Container holding the reader stamps.*/ |
||
54 | void attachReaderStamps(const StampContainer &source); |
||
401 | werner | 55 | /// static function to retrieve distance grid. See Stamp::distanceToCenter |
56 | static const Grid<float> &distanceGrid() { return m_distance; } |
||
51 | Werner | 57 | void invert(); ///< invert stamps (value = 1. - value) (for multiplicative overlay) |
63 | Werner | 58 | // description |
59 | const QString &description() { return m_desc; } |
||
60 | void setDescription(const QString s) { m_desc = s; } |
||
35 | Werner | 61 | QString dump(); |
62 | |||
33 | Werner | 63 | private: |
58 | Werner | 64 | void finalizeSetup(); ///< complete lookup-grid by filling up zero values |
401 | werner | 65 | void setupDistanceGrid(const int size); ///< setup the grid holding precalculated distance values |
58 | Werner | 66 | |
33 | Werner | 67 | static const int cBHDclassWidth; |
68 | static const int cHDclassWidth; |
||
61 | Werner | 69 | static const int cBHDclassLow; ///< bhd classes start with 4: class 0 = 4..8, class1 = 8..12 |
33 | Werner | 70 | static const int cHDclassLow; ///< hd classes offset is 40: class 0 = 40-50, class 1 = 50-60 |
71 | static const int cBHDclassCount; ///< class count, 50: highest class = 50*4 +- 2 = 198 - 202 |
||
72 | static const int cHDclassCount; ///< class count. highest class: 140-150 |
||
73 | struct StampItem { |
||
74 | Stamp* stamp; |
||
64 | Werner | 75 | float dbh; |
33 | Werner | 76 | float hd; |
47 | Werner | 77 | float crown_radius; |
33 | Werner | 78 | }; |
64 | Werner | 79 | inline void getKey(const float dbh, const float hd_value, int &dbh_class, int &hd_class) const; |
80 | void addStamp(Stamp* stamp, const int cls_dbh, const int cls_hd, const float crown_radius_m, const float dbh, const float hd_value); |
||
33 | Werner | 81 | int m_maxBhd; |
82 | bool m_useLookup; // use lookup table? |
||
83 | QList<StampItem> m_stamps; |
||
84 | Grid<Stamp*> m_lookup; |
||
401 | werner | 85 | static Grid<float> m_distance; ///< grid holding precalculated distances to the stamp center |
63 | Werner | 86 | QString m_desc; |
429 | werner | 87 | QString m_fileName; |
33 | Werner | 88 | }; |
89 | |||
90 | #endif // STAMPCONTAINER_H |