iLand
stamp.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
20#ifndef STAMP_H
21#define STAMP_H
22
23#include <QtCore>
24#include "grid.h"
31class Stamp
32{
33public:
36 enum StampType { est4x4=4, est8x8=8, est12x12=12, est16x16=16, est24x24=24, est32x32=32, est48x48=48, est64x64=64 };
37 Stamp();
38 ~Stamp();
39 Stamp(const int size):m_data(NULL) { setup(size); }
40 void setOffset(const int offset) { m_offset = offset; }
41 static void setDistanceGrid(const Grid<float> *grid) { mDistanceGrid = grid; }
42 int offset() const { return m_offset; }
43 int count() const { return m_size*m_size; }
44 int size() const { return m_offset*2+1; }
45 int dataSize() const { return m_size; }
47 float *data() { return m_data; }
49 const float *end() const { return &m_data[m_size*m_size]; }
51 inline float *data(const int x, const int y) const { return m_data + index(x,y); }
52 void setData(const int x, const int y, const float value) { *data(x,y) = value; }
54 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 inline float operator()(const int x, const int y) const { return *data(x,y); }
57 inline float offsetValue(const int x, const int y, const int offset) const { return *data(x+offset, y+offset); }
58 const Stamp *reader() const { return m_reader; }
59 void setReader(Stamp *reader) { m_reader = reader; setCrownRadius(reader->crownRadius()); /*calculates also the Area*/ }
60
61 // property crown radius
62 float crownRadius() const { return m_crownRadius; }
63 float crownArea() const { return m_crownArea; }
64 void setCrownRadius(const float r) { m_crownRadius = r; m_crownArea=r*r*M_PI; }
65 float distanceToCenter(const int ix, const int iy) const { return mDistanceGrid->constValueAtIndex(abs(ix-m_offset), abs(iy-m_offset)); }
66 // loading/saving
67 void loadFromFile(const QString &fileName);
68 void load(QDataStream &in);
69 void save(QDataStream &out);
70 QString dump() const;
71private:
72 void setup(const int size);
73 float *m_data;
74 float m_crownRadius;
75 float m_crownArea;
76 int m_size;
77 int m_offset;
78 Stamp *m_reader;
79 static const Grid<float> *mDistanceGrid;
80};
81
82// global functions
83
88Stamp *stampFromGrid(const FloatGrid& grid, const int width);
89
90#endif // STAMP_H
const T & constValueAtIndex(const QPoint &pos) const
value at position defined by a (integer) QPoint
Definition: grid.h:109
Stamp is the basic class for the LIP field of a individual tree.
Definition: stamp.h:32
Stamp()
Definition: stamp.cpp:28
~Stamp()
Definition: stamp.cpp:33
Stamp(const int size)
Definition: stamp.h:39
int index(const int x, const int y) const
get index (e.g. for data()[index]) for indices x and y
Definition: stamp.h:54
float crownRadius() const
Definition: stamp.h:62
float crownArea() const
Definition: stamp.h:63
static void setDistanceGrid(const Grid< float > *grid)
Definition: stamp.h:41
int offset() const
delta between edge of the stamp and the logical center point (of the tree). e.g. a 5x5 stamp in an 8x...
Definition: stamp.h:42
QString dump() const
Definition: stamp.cpp:62
void setCrownRadius(const float r)
Definition: stamp.h:64
const Stamp * reader() const
Definition: stamp.h:58
int count() const
count of pixels (rectangle)
Definition: stamp.h:43
void save(QDataStream &out)
save to stream (predefined binary structure)
Definition: stamp.cpp:109
StampType
defines different grid sizes for stamps (4x4 floats, ... 48x48 floats).
Definition: stamp.h:36
@ est12x12
Definition: stamp.h:36
@ est64x64
Definition: stamp.h:36
@ est32x32
Definition: stamp.h:36
@ est4x4
Definition: stamp.h:36
@ est24x24
Definition: stamp.h:36
@ est48x48
Definition: stamp.h:36
@ est8x8
Definition: stamp.h:36
@ est16x16
Definition: stamp.h:36
int dataSize() const
internal size of the stamp; e.g.
Definition: stamp.h:45
const float * end() const
get pointer to the element after the last element (iterator style)
Definition: stamp.h:49
float distanceToCenter(const int ix, const int iy) const
Definition: stamp.h:65
float * data()
get a full access pointer to internal data
Definition: stamp.h:47
void load(QDataStream &in)
load from stream (predefined binary structure)
Definition: stamp.cpp:95
float offsetValue(const int x, const int y, const int offset) const
Definition: stamp.h:57
int size() const
logical size of the stamp
Definition: stamp.h:44
void setReader(Stamp *reader)
Definition: stamp.h:59
void setData(const int x, const int y, const float value)
Definition: stamp.h:52
float * data(const int x, const int y) const
get pointer to data item with indices x and y
Definition: stamp.h:51
void loadFromFile(const QString &fileName)
Definition: stamp.cpp:77
void setOffset(const int offset)
Definition: stamp.h:40
float operator()(const int x, const int y) const
retrieve the value of the stamp at given indices x and y
Definition: stamp.h:56
Stamp * stampFromGrid(const FloatGrid &grid, const int width)
create a stamp from a FloatGrid with any size
Definition: stamp.cpp:119