Rev 646 | Rev 648 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
646 | werner | 2 | #ifndef LAYEREDGRID_H |
3 | #define LAYEREDGRID_H |
||
4 | |||
5 | #include "grid.h" |
||
6 | |||
7 | /** LayeredGrid |
||
8 | |||
9 | */ |
||
10 | |||
11 | class LayeredGridBase |
||
12 | { |
||
13 | public: |
||
14 | // access to properties |
||
647 | werner | 15 | virtual int sizeX() const=0; |
16 | virtual int sizeY() const=0; |
||
17 | virtual QRectF metricRect() const=0; |
||
18 | virtual QRectF cellRect(const QPoint &p) const=0; |
||
646 | werner | 19 | // available variables |
20 | virtual const QStringList names() const=0; |
||
21 | // statistics |
||
22 | /// retrieve min and max of variable 'index' |
||
647 | werner | 23 | virtual void range(double &rMin, double &rMax, const int index) const=0; |
646 | werner | 24 | |
25 | // data access functions |
||
647 | werner | 26 | virtual double value(const float x, const float y, const int index) const = 0; |
27 | virtual double value(const int ix, const int iy, const int index) const = 0; |
||
28 | virtual double value(const int grid_index, const int index) const = 0; |
||
646 | werner | 29 | }; |
30 | |||
31 | template <class T> |
||
32 | class LayeredGrid: public LayeredGridBase |
||
33 | { |
||
34 | public: |
||
35 | LayeredGrid(const Grid<T>& grid) { mGrid = &grid; } |
||
36 | LayeredGrid() { mGrid = 0; } |
||
647 | werner | 37 | QRectF cellRect(const QPoint &p) const { return mGrid->cellRect(p); } |
38 | QRectF metricRect() const { return mGrid->metricRect(); } |
||
39 | int sizeX() const { return mGrid->sizeX(); } |
||
40 | int sizeY() const { return mGrid->sizeY();} |
||
41 | |||
42 | virtual double value(const T& data, const int index) const = 0; |
||
646 | werner | 43 | double value(const T* ptr, const int index) const { return value(mGrid->constValueAtIndex(mGrid->indexOf(ptr)), index); } |
44 | double value(const int grid_index, const int index) const { return value(mGrid->constValueAtIndex(grid_index), index); } |
||
45 | double value(const float x, const float y, const int index) const { return value(mGrid->constValueAt(x,y), index); } |
||
647 | werner | 46 | double value(const int ix, const int iy, const int index) const { return value(mGrid->constValueAtIndex(ix, iy), index); } |
47 | void range(double &rMin, double &rMax, const int index) const { rMin=9999999999.; rMax=-99999999999.; |
||
646 | werner | 48 | for (int i=0;i<mGrid->count(); ++i) { |
49 | rMin=qMin(rMin, value(i, index)); |
||
50 | rMax=qMax(rMax, value(i,index));}} |
||
51 | |||
52 | protected: |
||
53 | const Grid<T> *mGrid; |
||
54 | }; |
||
55 | |||
56 | #endif // LAYEREDGRID_H |