Subversion Repositories public iLand

Rev

Rev 487 | Rev 671 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1
 
30 Werner 2
#ifndef STAMP_H
3
#define STAMP_H
4
 
487 werner 5
#include <QtCore>
83 Werner 6
#include "grid.h"
30 Werner 7
/** Stamp is the basic class for the FON field of a individual tree.
8
 
9
*/
10
class Stamp
11
{
12
public:
33 Werner 13
    /// @enum StampType defines different grid sizes for stamps (4x4 floats, ... 48x48 floats).
14
    /// the numeric value indicates also the size of the grid.
131 Werner 15
    enum StampType { est4x4=4, est8x8=8, est12x12=12, est16x16=16, est24x24=24, est32x32=32, est48x48=48, est64x64=64 };
30 Werner 16
    Stamp();
17
    ~Stamp();
35 Werner 18
    Stamp(const int size):m_data(NULL) { setup(size); }
34 Werner 19
    void setOffset(const int offset) { m_offset = offset; }
487 werner 20
    static void setDistanceGrid(const Grid<float> *grid) { mDistanceGrid = grid; }
145 Werner 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.
22
    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
24
    int dataSize() const { return m_size; } ///< internal size of the stamp; e.g. 4 -> 4x4 stamp with 16 pixels.
30 Werner 25
    /// get a full access pointer to internal data
26
    float *data() { return m_data; }
27
    /// get pointer to the element after the last element (iterator style)
32 Werner 28
    const float *end() const { return &m_data[m_size*m_size]; }
30 Werner 29
    /// get pointer to data item with indices x and y
40 Werner 30
    float *data(const int x, const int y) const { return m_data + index(x,y); }
34 Werner 31
    void setData(const int x, const int y, const float value) { *data(x,y) = value; }
30 Werner 32
    /// get index (e.g. for data()[index]) for indices x and y
32 Werner 33
    int index(const int x, const int y) const { return y*m_size + x; }
40 Werner 34
    inline float operator()(const int x, const int y) const { return *data(x,y); }
58 Werner 35
    inline float offsetValue(const int x, const int y, const int offset) const { return *data(x+offset, y+offset); }
47 Werner 36
    const Stamp *reader() const { return m_reader; }
149 werner 37
    void setReader(Stamp *reader) { m_reader = reader; setCrownRadius(reader->crownRadius()); /*calculates also the Area*/ }
400 werner 38
 
149 werner 39
    // property crown radius
40
    float crownRadius() const { return m_crownRadius; }
41
    float crownArea() const { return m_crownArea; }
42
    void setCrownRadius(const float r) { m_crownRadius = r; m_crownArea=r*r*M_PI; }
487 werner 43
    float distanceToCenter(const int ix, const int iy) const { return mDistanceGrid->constValueAtIndex(abs(ix-m_offset), abs(iy-m_offset)); }
32 Werner 44
    // loading/saving
45
    void loadFromFile(const QString &fileName);
33 Werner 46
    void load(QDataStream &in); ///< load from stream (predefined binary structure)
47
    void save(QDataStream &out); ///< save to stream (predefined binary structure)
321 werner 48
    QString dump() const;
30 Werner 49
private:
32 Werner 50
    void setup(const int size);
30 Werner 51
    float *m_data;
149 werner 52
    float m_crownRadius;
53
    float m_crownArea;
32 Werner 54
    int m_size;
33 Werner 55
    int m_offset;
47 Werner 56
    Stamp *m_reader; ///< pointer to the appropriate reader stamp (if available)
487 werner 57
    static const Grid<float> *mDistanceGrid;
30 Werner 58
};
59
 
34 Werner 60
// global functions
61
 
62
/// 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)
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)
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.
66
Stamp *stampFromGrid(const FloatGrid& grid, const int width);
67
 
30 Werner 68
#endif // STAMP_H