Rev 639 | Rev 697 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 639 | Rev 671 | ||
---|---|---|---|
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/stamp.h': |
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/stamp.h': |
- | 2 | /********************************************************************************************
|
|
- | 3 | ** iLand - an individual based forest landscape and disturbance model
|
|
- | 4 | ** http://iland.boku.ac.at
|
|
- | 5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl
|
|
- | 6 | **
|
|
- | 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
|
|
- | 9 | ** the Free Software Foundation, either version 3 of the License, or
|
|
- | 10 | ** (at your option) any later version.
|
|
- | 11 | **
|
|
- | 12 | ** This program is distributed in the hope that it will be useful,
|
|
- | 13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
- | 14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
- | 15 | ** GNU General Public License for more details.
|
|
- | 16 | **
|
|
- | 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/>.
|
|
- | 19 | ********************************************************************************************/
|
|
- | 20 | ||
2 | #ifndef STAMP_H
|
21 | #ifndef STAMP_H
|
3 | #define STAMP_H
|
22 | #define STAMP_H
|
4 | 23 | ||
5 | #include <QtCore>
|
24 | #include <QtCore>
|
6 | #include "grid.h"
|
25 | #include "grid.h"
|
7 | /** Stamp is the basic class for the FON field of a individual tree.
|
26 | /** Stamp is the basic class for the FON field of a individual tree.
|
8 | 27 | ||
9 | */
|
28 | */
|
10 | class Stamp
|
29 | class Stamp
|
11 | {
|
30 | {
|
12 | public: |
31 | public: |
13 | /// @enum StampType defines different grid sizes for stamps (4x4 floats, ... 48x48 floats).
|
32 | /// @enum StampType defines different grid sizes for stamps (4x4 floats, ... 48x48 floats).
|
14 | /// the numeric value indicates also the size of the grid.
|
33 | /// the numeric value indicates also the size of the grid.
|
15 | enum StampType { est4x4=4, est8x8=8, est12x12=12, est16x16=16, est24x24=24, est32x32=32, est48x48=48, est64x64=64 }; |
34 | enum StampType { est4x4=4, est8x8=8, est12x12=12, est16x16=16, est24x24=24, est32x32=32, est48x48=48, est64x64=64 }; |
16 | Stamp(); |
35 | Stamp(); |
17 | ~Stamp(); |
36 | ~Stamp(); |
18 | Stamp(const int size):m_data(NULL) { setup(size); } |
37 | Stamp(const int size):m_data(NULL) { setup(size); } |
19 | void setOffset(const int offset) { m_offset = offset; } |
38 | void setOffset(const int offset) { m_offset = offset; } |
20 | static void setDistanceGrid(const Grid<float> *grid) { mDistanceGrid = grid; } |
39 | static void setDistanceGrid(const Grid<float> *grid) { mDistanceGrid = grid; } |
21 | int offset() const { return m_offset; } ///< delta between edge of the stamp and the logical center point (of the tree). e.g. a 5x5 stamp in an 8x8-grid has an offset from 2. |
40 | int offset() const { return m_offset; } ///< delta between edge of the stamp and the logical center point (of the tree). e.g. a 5x5 stamp in an 8x8-grid has an offset from 2. |
22 | int count() const { return m_size*m_size; } ///< count of pixels (rectangle) |
41 | int count() const { return m_size*m_size; } ///< count of pixels (rectangle) |
23 | int size() const { return m_offset*2+1; } ///< logical size of the stamp |
42 | int size() const { return m_offset*2+1; } ///< logical size of the stamp |
24 | int dataSize() const { return m_size; } ///< internal size of the stamp; e.g. 4 -> 4x4 stamp with 16 pixels. |
43 | int dataSize() const { return m_size; } ///< internal size of the stamp; e.g. 4 -> 4x4 stamp with 16 pixels. |
25 | /// get a full access pointer to internal data
|
44 | /// get a full access pointer to internal data
|
26 | float *data() { return m_data; } |
45 | float *data() { return m_data; } |
27 | /// get pointer to the element after the last element (iterator style)
|
46 | /// get pointer to the element after the last element (iterator style)
|
28 | const float *end() const { return &m_data[m_size*m_size]; } |
47 | const float *end() const { return &m_data[m_size*m_size]; } |
29 | /// get pointer to data item with indices x and y
|
48 | /// get pointer to data item with indices x and y
|
30 | float *data(const int x, const int y) const { return m_data + index(x,y); } |
49 | float *data(const int x, const int y) const { return m_data + index(x,y); } |
31 | void setData(const int x, const int y, const float value) { *data(x,y) = value; } |
50 | void setData(const int x, const int y, const float value) { *data(x,y) = value; } |
32 | /// get index (e.g. for data()[index]) for indices x and y
|
51 | /// get index (e.g. for data()[index]) for indices x and y
|
33 | int index(const int x, const int y) const { return y*m_size + x; } |
52 | int index(const int x, const int y) const { return y*m_size + x; } |
34 | inline float operator()(const int x, const int y) const { return *data(x,y); } |
53 | inline float operator()(const int x, const int y) const { return *data(x,y); } |
35 | inline float offsetValue(const int x, const int y, const int offset) const { return *data(x+offset, y+offset); } |
54 | inline float offsetValue(const int x, const int y, const int offset) const { return *data(x+offset, y+offset); } |
36 | const Stamp *reader() const { return m_reader; } |
55 | const Stamp *reader() const { return m_reader; } |
37 | void setReader(Stamp *reader) { m_reader = reader; setCrownRadius(reader->crownRadius()); /*calculates also the Area*/ } |
56 | void setReader(Stamp *reader) { m_reader = reader; setCrownRadius(reader->crownRadius()); /*calculates also the Area*/ } |
38 | 57 | ||
39 | // property crown radius
|
58 | // property crown radius
|
40 | float crownRadius() const { return m_crownRadius; } |
59 | float crownRadius() const { return m_crownRadius; } |
41 | float crownArea() const { return m_crownArea; } |
60 | float crownArea() const { return m_crownArea; } |
42 | void setCrownRadius(const float r) { m_crownRadius = r; m_crownArea=r*r*M_PI; } |
61 | void setCrownRadius(const float r) { m_crownRadius = r; m_crownArea=r*r*M_PI; } |
43 | float distanceToCenter(const int ix, const int iy) const { return mDistanceGrid->constValueAtIndex(abs(ix-m_offset), abs(iy-m_offset)); } |
62 | float distanceToCenter(const int ix, const int iy) const { return mDistanceGrid->constValueAtIndex(abs(ix-m_offset), abs(iy-m_offset)); } |
44 | // loading/saving
|
63 | // loading/saving
|
45 | void loadFromFile(const QString &fileName); |
64 | void loadFromFile(const QString &fileName); |
46 | void load(QDataStream &in); ///< load from stream (predefined binary structure) |
65 | void load(QDataStream &in); ///< load from stream (predefined binary structure) |
47 | void save(QDataStream &out); ///< save to stream (predefined binary structure) |
66 | void save(QDataStream &out); ///< save to stream (predefined binary structure) |
48 | QString dump() const; |
67 | QString dump() const; |
49 | private: |
68 | private: |
50 | void setup(const int size); |
69 | void setup(const int size); |
51 | float *m_data; |
70 | float *m_data; |
52 | float m_crownRadius; |
71 | float m_crownRadius; |
53 | float m_crownArea; |
72 | float m_crownArea; |
54 | int m_size; |
73 | int m_size; |
55 | int m_offset; |
74 | int m_offset; |
56 | Stamp *m_reader; ///< pointer to the appropriate reader stamp (if available) |
75 | Stamp *m_reader; ///< pointer to the appropriate reader stamp (if available) |
57 | static const Grid<float> *mDistanceGrid; |
76 | static const Grid<float> *mDistanceGrid; |
58 | }; |
77 | }; |
59 | 78 | ||
60 | // global functions
|
79 | // global functions
|
61 | 80 | ||
62 | /// create a stamp from a FloatGrid with any size
|
81 | /// create a stamp from a FloatGrid with any size
|
63 | /// @param grid source grid. It is assumed the actual stamp data is around the center point and the grid has an uneven size (e.g 13x13 or 25x25)
|
82 | /// @param grid source grid. It is assumed the actual stamp data is around the center point and the grid has an uneven size (e.g 13x13 or 25x25)
|
64 | /// @param width number of pixels that should actually be used. e.g: grid 25x25, width=7 -> data is located from 9/9 to 16/16 (12+-3)
|
83 | /// @param width number of pixels that should actually be used. e.g: grid 25x25, width=7 -> data is located from 9/9 to 16/16 (12+-3)
|
65 | /// @return a stamp created on the heap with the fitting size. The data rect is aligned to 0/0. above example: stamp will be 8x8, with a 7x7-data-block from 0/0 to 6/6.
|
84 | /// @return a stamp created on the heap with the fitting size. The data rect is aligned to 0/0. above example: stamp will be 8x8, with a 7x7-data-block from 0/0 to 6/6.
|
66 | Stamp *stampFromGrid(const FloatGrid& grid, const int width); |
85 | Stamp *stampFromGrid(const FloatGrid& grid, const int width); |
67 | 86 | ||
68 | #endif // STAMP_H
|
87 | #endif // STAMP_H
|
69 | 88 |