Rev 33 | Rev 35 | 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 | |||
34 | Werner | 5 | #include "core/grid.h" |
32 | Werner | 6 | #include <QtCore> |
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. |
||
15 | enum StampType { est4x4=4, est8x8=8, est12x12=12, est16x16=16, est24x24=24, est32x32=32, est48x48=48 }; |
||
30 | Werner | 16 | Stamp(); |
17 | ~Stamp(); |
||
32 | Werner | 18 | Stamp(const int size) { setup(size); } |
34 | Werner | 19 | void setOffset(const int offset) { m_offset = offset; } |
33 | Werner | 20 | const int count() const { return m_size; } |
30 | Werner | 21 | /// get a full access pointer to internal data |
22 | float *data() { return m_data; } |
||
23 | /// get pointer to the element after the last element (iterator style) |
||
32 | Werner | 24 | const float *end() const { return &m_data[m_size*m_size]; } |
30 | Werner | 25 | /// get pointer to data item with indices x and y |
26 | float *data(const int x, const int y) { return m_data + index(x,y); } |
||
34 | Werner | 27 | void setData(const int x, const int y, const float value) { *data(x,y) = value; } |
30 | Werner | 28 | /// get index (e.g. for data()[index]) for indices x and y |
32 | Werner | 29 | int index(const int x, const int y) const { return y*m_size + x; } |
30 | // loading/saving |
||
31 | void loadFromFile(const QString &fileName); |
||
33 | Werner | 32 | void load(QDataStream &in); ///< load from stream (predefined binary structure) |
33 | void save(QDataStream &out); ///< save to stream (predefined binary structure) |
||
30 | Werner | 34 | private: |
32 | Werner | 35 | void setup(const int size); |
30 | Werner | 36 | float *m_data; |
32 | Werner | 37 | int m_size; |
33 | Werner | 38 | int m_offset; |
30 | Werner | 39 | }; |
40 | |||
34 | Werner | 41 | // global functions |
42 | |||
43 | /// create a stamp from a FloatGrid with any size |
||
44 | /// @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) |
||
45 | /// @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) |
||
46 | /// @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. |
||
47 | Stamp *stampFromGrid(const FloatGrid& grid, const int width); |
||
48 | |||
30 | Werner | 49 | #endif // STAMP_H |