Subversion Repositories public iLand

Rev

Rev 647 | Go to most recent revision | Details | 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
15
    int sizeX() const;
16
    int sizeY() const;
17
    QRectF metricRect() const;
18
    // available variables
19
    virtual const QStringList names() const=0;
20
    // statistics
21
    /// retrieve min and max of variable 'index'
22
    void range(double &rMin, double &rMax, const int index);
23
 
24
    // data access functions
25
    double value(const float x, const float y, const int index) const;
26
    double value(const int grid_index, const int index) const;
27
};
28
 
29
template <class T>
30
class LayeredGrid: public LayeredGridBase
31
{
32
public:
33
    LayeredGrid(const Grid<T>& grid) { mGrid = &grid; }
34
    LayeredGrid() { mGrid = 0; }
35
    double value(const T& data, const int index) const;
36
    double value(const T* ptr, const int index) const { return value(mGrid->constValueAtIndex(mGrid->indexOf(ptr)), index);  }
37
    double value(const int grid_index, const int index) const { return value(mGrid->constValueAtIndex(grid_index), index); }
38
    double value(const float x, const float y, const int index) const { return value(mGrid->constValueAt(x,y), index); }
39
    void range(double &rMin, double &rMax, const int index) { rMin=9999999999.; rMax=-99999999999.;
40
                                                              for (int i=0;i<mGrid->count(); ++i) {
41
                                                                  rMin=qMin(rMin, value(i, index));
42
                                                                  rMax=qMax(rMax, value(i,index));}}
43
 
44
protected:
45
    const Grid<T> *mGrid;
46
};
47
 
48
#endif // LAYEREDGRID_H