Rev 1032 | Rev 1211 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
989 | werner | 2 | //#include <QtGui> |
15 | Werner | 3 | #include "grid.h" |
285 | werner | 4 | #include "exception.h" |
373 | werner | 5 | #include "global.h" |
15 | Werner | 6 | |
599 | werner | 7 | QString gridToString(const FloatGrid &grid, const QChar sep, const int newline_after) |
36 | Werner | 8 | { |
9 | QString res; |
||
599 | werner | 10 | int newl_counter = newline_after; |
709 | werner | 11 | for (int y=grid.sizeY()-1;y>=0;--y) { |
46 | Werner | 12 | for (int x=0;x<grid.sizeX();x++) { |
599 | werner | 13 | res+=QString::number(grid.constValueAtIndex(QPoint(x,y))) + sep; |
14 | if (--newl_counter==0) { |
||
15 | res += "\r\n"; |
||
16 | newl_counter = newline_after; |
||
17 | } |
||
36 | Werner | 18 | } |
19 | res+="\r\n"; |
||
20 | } |
||
21 | return res; |
||
22 | } |
||
989 | werner | 23 | #ifdef ILAND_GUI |
991 | werner | 24 | #include <QImage> |
36 | Werner | 25 | |
26 | QImage gridToImage(const FloatGrid &grid, |
||
27 | bool black_white, |
||
28 | double min_value, double max_value, |
||
29 | bool reverse) |
||
30 | { |
||
31 | QImage res(grid.sizeX(), grid.sizeY(), QImage::Format_ARGB32); |
||
32 | QRgb col; |
||
33 | int grey; |
||
34 | double rval; |
||
35 | for (int x=0;x<grid.sizeX();x++){ |
||
36 | for (int y=0;y<grid.sizeY();y++) { |
||
37 | rval = grid.constValueAtIndex(QPoint(x,y)); |
||
38 | rval = std::max(min_value, rval); |
||
39 | rval = std::min(max_value, rval); |
||
40 | if (reverse) rval = max_value - rval; |
||
41 | if (black_white) { |
||
373 | werner | 42 | grey = int(255 * ( (rval-min_value) / (max_value-min_value))); |
36 | Werner | 43 | col = QColor(grey,grey,grey).rgb(); |
44 | } else { |
||
45 | col = QColor::fromHsvF(0.66666666666*rval, 0.95, 0.95).rgb(); |
||
46 | } |
||
47 | res.setPixel(x,y,col); |
||
48 | //res+=QString::number(grid.constValueAtIndex(QPoint(x,y))) + ";"; |
||
49 | } |
||
50 | //res+="\r\n"; |
||
51 | } |
||
52 | return res; |
||
53 | } |
||
285 | werner | 54 | |
556 | werner | 55 | |
56 | |||
285 | werner | 57 | bool loadGridFromImage(const QString &fileName, FloatGrid &rGrid) |
58 | { |
||
59 | QImage image; |
||
60 | if (!image.load(fileName)) |
||
61 | throw IException(QString("Grid::loadFromImage: could not load image file %1.").arg(fileName)); |
||
375 | werner | 62 | if (rGrid.isEmpty()) |
63 | rGrid.setup(1., image.size().width(), image.size().height() ); |
||
285 | werner | 64 | double value; |
65 | for (int x=0;x<image.width(); x++) |
||
66 | for (int y=0;y<image.height(); y++) { |
||
67 | value = qGray(image.pixel(x,y))/255.; |
||
68 | if (rGrid.isIndexValid(QPoint(x,y))) |
||
69 | rGrid.valueAtIndex(x,y) = value; |
||
70 | } |
||
71 | return true; |
||
72 | } |
||
989 | werner | 73 | #else |
74 | //QImage gridToImage(const FloatGrid &grid, |
||
75 | // bool black_white, |
||
76 | // double min_value, double max_value, |
||
77 | // bool reverse) |
||
78 | //{ |
||
79 | //} |
||
80 | |||
81 | bool loadGridFromImage(const QString &fileName, FloatGrid &rGrid) { |
||
1032 | werner | 82 | Q_UNUSED(fileName); Q_UNUSED(rGrid); |
989 | werner | 83 | return false; |
84 | } |
||
85 | #endif |
||
86 |