Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 Werner 1
#include "ImageStamp.h"
3 Werner 2
 
30 Werner 3
bool ImageStamp::load(const QString& filename)
3 Werner 4
{
5
    if (!mImage.load(filename))
6
        return false;
7
    rScale=1.f; hScale=1.f;
8
    return true;
9
}
10
 
11
/************************************
12
** get Value at position (x,y)
13
** the return value is scaled to 0..hScale
14
** range for x/y is -1..+1
15
**************************************/
30 Werner 16
float ImageStamp::getXY(const float x, const float y)
3 Werner 17
{
18
    int ix, iy;
19
    ix = int( (x+1.f) * ( mImage.width() / 2.) );  // scale from -1..1
20
    iy = int( (y+1.f) * (mImage.height() / 2.) );
21
    if (!mImage.valid(ix, iy))
6 Werner 22
        return 1.f;
3 Werner 23
    QRgb p = mImage.pixel(ix, iy);
8 Werner 24
    // scaling: range from 0..1 is scaled to 1-hScale to 1 (e.g.: hScale=0.8 -> result: 0.2..1)
25
    if (hScale!=1)
26
        return (1.-hScale) + hScale*qGray(p)/255.;
27
    else
28
        return (qGray(p)/255.);
3 Werner 29
 
30
}
31
 
32
/************************************
33
** get Value at radius r (0..rScale) and
34
** angle phi (in radians).
35
** note: 0: East, pi/2: North, pi: West, 3pi/2: South
36
**************************************/
30 Werner 37
float ImageStamp::get(const float r, const float phi)
3 Werner 38
{
39
    if (fabs(r)>rScale)
6 Werner 40
        return 1.f;
3 Werner 41
 
42
    float x, y;
43
    float r_unit = r/rScale; // scale to size of radius
44
    x = r_unit * sin(phi);
45
    y = r_unit * cos(phi);
46
    return getXY(x,y);
47
}
48