Subversion Repositories public iLand

Rev

Rev 1221 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1221 Rev 1222
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/stampcontainer.h':
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/stampcontainer.h':
2
/********************************************************************************************
2
/********************************************************************************************
3
**    iLand - an individual based forest landscape and disturbance model
3
**    iLand - an individual based forest landscape and disturbance model
4
**    http://iland.boku.ac.at
4
**    http://iland.boku.ac.at
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
6
**
6
**
7
**    This program is free software: you can redistribute it and/or modify
7
**    This program is free software: you can redistribute it and/or modify
8
**    it under the terms of the GNU General Public License as published by
8
**    it under the terms of the GNU General Public License as published by
9
**    the Free Software Foundation, either version 3 of the License, or
9
**    the Free Software Foundation, either version 3 of the License, or
10
**    (at your option) any later version.
10
**    (at your option) any later version.
11
**
11
**
12
**    This program is distributed in the hope that it will be useful,
12
**    This program is distributed in the hope that it will be useful,
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
**    GNU General Public License for more details.
15
**    GNU General Public License for more details.
16
**
16
**
17
**    You should have received a copy of the GNU General Public License
17
**    You should have received a copy of the GNU General Public License
18
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************************************/
19
********************************************************************************************/
20
20
21
#ifndef STAMPCONTAINER_H
21
#ifndef STAMPCONTAINER_H
22
#define STAMPCONTAINER_H
22
#define STAMPCONTAINER_H
23
23
24
#include "stamp.h"
24
#include "stamp.h"
25
#include "grid.h"
25
#include "grid.h"
26
26
27
/** Collection of Stamp for one tree species.
27
/** Collection of Stamp for one tree species.
28
  @ingroup core
28
  @ingroup core
29
  Per species several stamps are stored (different BHD, different HD relations). This class
29
  Per species several stamps are stored (different BHD, different HD relations). This class
30
  encapsulates storage and access to these stamps. The design goal is to deliver high
30
  encapsulates storage and access to these stamps. The design goal is to deliver high
31
  access speeds for the "stamp()" method.
31
  access speeds for the "stamp()" method.
32
  Use getStamp(bhd, hd) or getStamp(bhd, height) to access. */
32
  Use getStamp(bhd, hd) or getStamp(bhd, height) to access. */
33
class StampContainer
33
class StampContainer
34
{
34
{
35
public:
35
public:
36
    StampContainer();
36
    StampContainer();
37
    ~StampContainer();
37
    ~StampContainer();
38
    void useLookup(const bool use) { m_useLookup = use; }
38
    void useLookup(const bool use) { m_useLookup = use; }
39
    /// addStamp() add a pre-allocated stamp @param stamp to internal collection. Caller must allocate stamp on the heap,
39
    /// addStamp() add a pre-allocated stamp @param stamp to internal collection. Caller must allocate stamp on the heap,
40
    /// freeing is done by this class.
40
    /// freeing is done by this class.
41
    void addStamp(Stamp* stamp, const float dbh, const float hd_value, const float crown_radius);
41
    void addStamp(Stamp* stamp, const float dbh, const float hd_value, const float crown_radius);
42
    void addReaderStamp(Stamp *stamp, const float crown_radius_m);
42
    void addReaderStamp(Stamp *stamp, const float crown_radius_m);
43
    const Stamp* stamp(const float bhd_cm, const float height_m) const;
43
    const Stamp* stamp(const float bhd_cm, const float height_m) const;
44
    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.
44
    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.
45
    int count() const { return m_stamps.count(); }
45
    int count() const { return m_stamps.count(); }
46
    /// save the content of the StampContainer to the output stream (binary encoding)
46
    /// save the content of the StampContainer to the output stream (binary encoding)
47
    void save(QDataStream &out);
47
    void save(QDataStream &out);
48
    /// load the content of the StampContainer to the output stream (binary encoding)
48
    /// load the content of the StampContainer to the output stream (binary encoding)
49
    void load(QDataStream &in);
49
    void load(QDataStream &in);
50
    void load(const QString &fileName);
50
    void load(const QString &fileName);
51
51
52
    /** this functions attaches the appropriate reader (dep. on crown radius) to each stamp of the container.
52
    /** this functions attaches the appropriate reader (dep. on crown radius) to each stamp of the container.
53
        The reader-stamp is returned by a call to the reader()-function of the Stamp itself.
53
        The reader-stamp is returned by a call to the reader()-function of the Stamp itself.
54
        @param Container holding the reader stamps.*/
54
        @param Container holding the reader stamps.*/
55
    void attachReaderStamps(const StampContainer &source);
55
    void attachReaderStamps(const StampContainer &source);
56
    /// static function to retrieve distance grid. See Stamp::distanceToCenter
56
    /// static function to retrieve distance grid. See Stamp::distanceToCenter
57
    static const Grid<float> &distanceGrid()  { return m_distance; }
57
    static const Grid<float> &distanceGrid()  { return m_distance; }
58
    void invert(); ///< invert stamps (value = 1. - value) (for multiplicative overlay)
58
    void invert(); ///< invert stamps (value = 1. - value) (for multiplicative overlay)
59
    // description
59
    // description
60
    const QString &description() { return m_desc; }
60
    const QString &description() { return m_desc; }
61
    void setDescription(const QString s) { m_desc = s; }
61
    void setDescription(const QString s) { m_desc = s; }
62
    QString dump();
62
    QString dump();
63
63
64
private:
64
private:
65
    void finalizeSetup(); ///< complete lookup-grid by filling up zero values
65
    void finalizeSetup(); ///< complete lookup-grid by filling up zero values
66
    void setupDistanceGrid(const int size); ///< setup the grid holding precalculated distance values
66
    void setupDistanceGrid(const int size); ///< setup the grid holding precalculated distance values
67
67
68
    static const int cBHDclassWidth;
68
    static const int cBHDclassWidth;
69
    static const int cHDclassWidth;
69
    static const int cHDclassWidth;
70
    static const int cBHDclassLow; ///< bhd classes start with 4: class 0 = 4..8, class1 = 8..12
70
    static const int cBHDclassLow; ///< bhd classes start with 4: class 0 = 4..8, class1 = 8..12
71
    static const int cHDclassLow; ///< hd classes offset is 40: class 0 = 40-50, class 1 = 50-60
71
    static const int cHDclassLow; ///< hd classes offset is 40: class 0 = 40-50, class 1 = 50-60
72
    static const int cBHDclassCount; ///< class count, 50: highest class = 50*4 +- 2 = 198 - 202
72
    static const int cBHDclassCount; ///< class count, 50: highest class = 50*4 +- 2 = 198 - 202
73
    static const int cHDclassCount; ///< class count. highest class: 140-150
73
    static const int cHDclassCount; ///< class count. highest class: 140-150
74
    struct StampItem {
74
    struct StampItem {
75
        Stamp* stamp;
75
        Stamp* stamp;
76
        float dbh;
76
        float dbh;
77
        float hd;
77
        float hd;
78
        float crown_radius;
78
        float crown_radius;
79
    };
79
    };
80
    inline void getKey(const float dbh, const float hd_value, int &dbh_class, int &hd_class) const;
80
    inline void getKey(const float dbh, const float hd_value, int &dbh_class, int &hd_class) const;
81
    void addStamp(Stamp* stamp, const int cls_dbh, const int cls_hd, const float crown_radius_m, const float dbh, const float hd_value);
81
    void addStamp(Stamp* stamp, const int cls_dbh, const int cls_hd, const float crown_radius_m, const float dbh, const float hd_value);
82
    int m_maxBhd;
82
    int m_maxBhd;
83
    bool m_useLookup; // use lookup table?
83
    bool m_useLookup; // use lookup table?
84
    QList<StampItem> m_stamps;
84
    QList<StampItem> m_stamps;
85
    Grid<Stamp*> m_lookup;
85
    Grid<Stamp*> m_lookup;
86
    static Grid<float> m_distance; ///< grid holding precalculated distances to the stamp center
86
    static Grid<float> m_distance; ///< grid holding precalculated distances to the stamp center
87
    QString m_desc;
87
    QString m_desc;
88
    QString m_fileName;
88
    QString m_fileName;
89
};
89
};
90
90
91
#endif // STAMPCONTAINER_H
91
#endif // STAMPCONTAINER_H
92
 
92