Rev 705 | Rev 779 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 705 | Rev 739 | ||
---|---|---|---|
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 | /********************************************************************************************
|
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 STAMP_H
|
21 | #ifndef STAMP_H
|
22 | #define STAMP_H
|
22 | #define STAMP_H
|
23 | 23 | ||
24 | #include <QtCore>
|
24 | #include <QtCore>
|
25 | #include "grid.h"
|
25 | #include "grid.h"
|
26 | /** Stamp is the basic class for the LIP field of a individual tree.
|
26 | /** Stamp is the basic class for the LIP field of a individual tree.
|
27 | @ingroup core
|
27 | @ingroup core
|
28 | In iLand jargon, a Stamp is a LIP (light influence pattern). These patterns are pre-calculated using the "LightRoom" (http://iland.boku.ac.at/Lightroom)
|
28 | In iLand jargon, a Stamp is a LIP (light influence pattern). These patterns are pre-calculated using the "LightRoom" (http://iland.boku.ac.at/Lightroom)
|
29 | and stand for a field of influence (w.r.t. light) of a individual tree of a given size and species.
|
29 | and stand for a field of influence (w.r.t. light) of a individual tree of a given size and species.
|
30 | see http://iland.boku.ac.at/competition+for+light
|
30 | see http://iland.boku.ac.at/competition+for+light
|
31 | */
|
31 | */
|
32 | class Stamp
|
32 | class Stamp
|
33 | {
|
33 | {
|
34 | public: |
34 | public: |
35 | /// @enum StampType defines different grid sizes for stamps (4x4 floats, ... 48x48 floats).
|
35 | /// @enum StampType defines different grid sizes for stamps (4x4 floats, ... 48x48 floats).
|
36 | /// the numeric value indicates also the size of the grid.
|
36 | /// the numeric value indicates also the size of the grid.
|
37 | enum StampType { est4x4=4, est8x8=8, est12x12=12, est16x16=16, est24x24=24, est32x32=32, est48x48=48, est64x64=64 }; |
37 | enum StampType { est4x4=4, est8x8=8, est12x12=12, est16x16=16, est24x24=24, est32x32=32, est48x48=48, est64x64=64 }; |
38 | Stamp(); |
38 | Stamp(); |
39 | ~Stamp(); |
39 | ~Stamp(); |
40 | Stamp(const int size):m_data(NULL) { setup(size); } |
40 | Stamp(const int size):m_data(NULL) { setup(size); } |
41 | void setOffset(const int offset) { m_offset = offset; } |
41 | void setOffset(const int offset) { m_offset = offset; } |
42 | static void setDistanceGrid(const Grid<float> *grid) { mDistanceGrid = grid; } |
42 | static void setDistanceGrid(const Grid<float> *grid) { mDistanceGrid = grid; } |
43 | 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. |
43 | 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. |
44 | int count() const { return m_size*m_size; } ///< count of pixels (rectangle) |
44 | int count() const { return m_size*m_size; } ///< count of pixels (rectangle) |
45 | int size() const { return m_offset*2+1; } ///< logical size of the stamp |
45 | int size() const { return m_offset*2+1; } ///< logical size of the stamp |
46 | int dataSize() const { return m_size; } ///< internal size of the stamp; e.g. 4 -> 4x4 stamp with 16 pixels. |
46 | int dataSize() const { return m_size; } ///< internal size of the stamp; e.g. 4 -> 4x4 stamp with 16 pixels. |
47 | /// get a full access pointer to internal data
|
47 | /// get a full access pointer to internal data
|
48 | float *data() { return m_data; } |
48 | float *data() { return m_data; } |
49 | /// get pointer to the element after the last element (iterator style)
|
49 | /// get pointer to the element after the last element (iterator style)
|
50 | const float *end() const { return &m_data[m_size*m_size]; } |
50 | const float *end() const { return &m_data[m_size*m_size]; } |
51 | /// get pointer to data item with indices x and y
|
51 | /// get pointer to data item with indices x and y
|
52 | inline float *data(const int x, const int y) const { return m_data + index(x,y); } |
52 | inline float *data(const int x, const int y) const { return m_data + index(x,y); } |
53 | void setData(const int x, const int y, const float value) { *data(x,y) = value; } |
53 | void setData(const int x, const int y, const float value) { *data(x,y) = value; } |
54 | /// get index (e.g. for data()[index]) for indices x and y
|
54 | /// get index (e.g. for data()[index]) for indices x and y
|
55 | inline int index(const int x, const int y) const { return y*m_size + x; } |
55 | inline int index(const int x, const int y) const { Q_ASSERT(y*m_size + x < m_size*m_size); return y*m_size + x; } |
56 | /// retrieve the value of the stamp at given indices x and y
|
56 | /// retrieve the value of the stamp at given indices x and y
|
57 | inline float operator()(const int x, const int y) const { return *data(x,y); } |
57 | inline float operator()(const int x, const int y) const { return *data(x,y); } |
58 | inline float offsetValue(const int x, const int y, const int offset) const { return *data(x+offset, y+offset); } |
58 | inline float offsetValue(const int x, const int y, const int offset) const { return *data(x+offset, y+offset); } |
59 | const Stamp *reader() const { return m_reader; } |
59 | const Stamp *reader() const { return m_reader; } |
60 | void setReader(Stamp *reader) { m_reader = reader; setCrownRadius(reader->crownRadius()); /*calculates also the Area*/ } |
60 | void setReader(Stamp *reader) { m_reader = reader; setCrownRadius(reader->crownRadius()); /*calculates also the Area*/ } |
61 | 61 | ||
62 | // property crown radius
|
62 | // property crown radius
|
63 | float crownRadius() const { return m_crownRadius; } |
63 | float crownRadius() const { return m_crownRadius; } |
64 | float crownArea() const { return m_crownArea; } |
64 | float crownArea() const { return m_crownArea; } |
65 | void setCrownRadius(const float r) { m_crownRadius = r; m_crownArea=r*r*M_PI; } |
65 | void setCrownRadius(const float r) { m_crownRadius = r; m_crownArea=r*r*M_PI; } |
66 | float distanceToCenter(const int ix, const int iy) const { return mDistanceGrid->constValueAtIndex(abs(ix-m_offset), abs(iy-m_offset)); } |
66 | float distanceToCenter(const int ix, const int iy) const { return mDistanceGrid->constValueAtIndex(abs(ix-m_offset), abs(iy-m_offset)); } |
67 | // loading/saving
|
67 | // loading/saving
|
68 | void loadFromFile(const QString &fileName); |
68 | void loadFromFile(const QString &fileName); |
69 | void load(QDataStream &in); ///< load from stream (predefined binary structure) |
69 | void load(QDataStream &in); ///< load from stream (predefined binary structure) |
70 | void save(QDataStream &out); ///< save to stream (predefined binary structure) |
70 | void save(QDataStream &out); ///< save to stream (predefined binary structure) |
71 | QString dump() const; |
71 | QString dump() const; |
72 | private: |
72 | private: |
73 | void setup(const int size); |
73 | void setup(const int size); |
74 | float *m_data; |
74 | float *m_data; |
75 | float m_crownRadius; |
75 | float m_crownRadius; |
76 | float m_crownArea; |
76 | float m_crownArea; |
77 | int m_size; |
77 | int m_size; |
78 | int m_offset; |
78 | int m_offset; |
79 | Stamp *m_reader; ///< pointer to the appropriate reader stamp (if available) |
79 | Stamp *m_reader; ///< pointer to the appropriate reader stamp (if available) |
80 | static const Grid<float> *mDistanceGrid; |
80 | static const Grid<float> *mDistanceGrid; |
81 | }; |
81 | }; |
82 | 82 | ||
83 | // global functions
|
83 | // global functions
|
84 | 84 | ||
85 | /// create a stamp from a FloatGrid with any size
|
85 | /// create a stamp from a FloatGrid with any size
|
86 | /// @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)
|
86 | /// @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)
|
87 | /// @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)
|
87 | /// @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)
|
88 | /// @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.
|
88 | /// @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.
|
89 | Stamp *stampFromGrid(const FloatGrid& grid, const int width); |
89 | Stamp *stampFromGrid(const FloatGrid& grid, const int width); |
90 | 90 | ||
91 | #endif // STAMP_H
|
91 | #endif // STAMP_H
|
92 | 92 |