mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 11:39:16 +02:00
Added hillshading settings
This commit is contained in:
@ -29,8 +29,6 @@ using namespace IMG;
|
||||
#define ROAD 0
|
||||
#define WATER 1
|
||||
|
||||
#define BLUR_RADIUS 3
|
||||
|
||||
static const QColor textColor(Qt::black);
|
||||
static const QColor haloColor(Qt::white);
|
||||
static const QColor shieldColor(Qt::white);
|
||||
@ -498,9 +496,14 @@ MatrixD RasterTile::elevation(int extend) const
|
||||
void RasterTile::drawHillShading(QPainter *painter) const
|
||||
{
|
||||
if (_hillShading && _zoom >= 18 && _zoom <= 24) {
|
||||
MatrixD dem(Filter::blur(elevation(BLUR_RADIUS + 1), BLUR_RADIUS));
|
||||
QImage img(HillShading::render(dem, BLUR_RADIUS + 1));
|
||||
painter->drawImage(_rect.x(), _rect.y(), img);
|
||||
if (HillShading::blur()) {
|
||||
MatrixD dem(Filter::blur(elevation(HillShading::blur() + 1),
|
||||
HillShading::blur()));
|
||||
QImage img(HillShading::render(dem, HillShading::blur() + 1));
|
||||
painter->drawImage(_rect.x(), _rect.y(), img);
|
||||
} else
|
||||
painter->drawImage(_rect.x(), _rect.y(),
|
||||
HillShading::render(elevation(1), 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,12 @@ struct Derivatives
|
||||
double dzdy;
|
||||
};
|
||||
|
||||
int HillShading::_alpha = 96;
|
||||
int HillShading::_blur = 3;
|
||||
int HillShading::_azimuth = 315;
|
||||
int HillShading::_altitude = 45;
|
||||
double HillShading::_z = 0.6;
|
||||
|
||||
static void getConstants(double azimuth, double elevation, Constants &c)
|
||||
{
|
||||
double alpha = (M_PI / 180.0) * azimuth;
|
||||
@ -59,8 +65,7 @@ static void getSubmatrix(int x, int y, const MatrixD &m, SubMatrix &sm)
|
||||
sm.z9 = m.at(bottom, right);
|
||||
}
|
||||
|
||||
QImage HillShading::render(const MatrixD &m, int extend, quint8 alpha, double z,
|
||||
double azimuth, double elevation)
|
||||
QImage HillShading::render(const MatrixD &m, int extend)
|
||||
{
|
||||
QImage img(m.w() - 2 * extend, m.h() - 2 * extend,
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
@ -71,12 +76,12 @@ QImage HillShading::render(const MatrixD &m, int extend, quint8 alpha, double z,
|
||||
SubMatrix sm;
|
||||
Derivatives d;
|
||||
|
||||
getConstants(azimuth, elevation, c);
|
||||
getConstants(_azimuth, _altitude, c);
|
||||
|
||||
for (int y = extend; y < m.h() - extend; y++) {
|
||||
for (int x = extend; x < m.w() - extend; x++) {
|
||||
getSubmatrix(x, y, m, sm);
|
||||
getDerivativesHorn(sm, z, d);
|
||||
getDerivativesHorn(sm, _z, d);
|
||||
|
||||
double L = (c.a1 - c.a2 * d.dzdx - c.a3 * d.dzdy)
|
||||
/ sqrt(1.0 + d.dzdx * d.dzdx + d.dzdy * d.dzdy);
|
||||
@ -86,8 +91,8 @@ QImage HillShading::render(const MatrixD &m, int extend, quint8 alpha, double z,
|
||||
pixel = 0;
|
||||
else {
|
||||
L = sqrt(L * 0.8 + 0.2);
|
||||
quint8 val = (L < 0) ? 0 : L * alpha;
|
||||
pixel = (alpha - val)<<24;
|
||||
quint8 val = (L < 0) ? 0 : L * _alpha;
|
||||
pixel = (_alpha - val)<<24;
|
||||
}
|
||||
|
||||
*(quint32*)(bits + (y - extend) * bpl + (x - extend) * 4) = pixel;
|
||||
|
@ -7,8 +7,22 @@
|
||||
class HillShading
|
||||
{
|
||||
public:
|
||||
static QImage render(const MatrixD &m, int extend, quint8 alpha = 96,
|
||||
double z = 0.6, double azimuth = 315, double elevation = 45);
|
||||
static QImage render(const MatrixD &m, int extend);
|
||||
|
||||
static int blur() {return _blur;}
|
||||
|
||||
static void setAlpha(int alpha) {_alpha = alpha;}
|
||||
static void setBlur(int blur) {_blur = blur;}
|
||||
static void setAzimuth(int azimuth) {_azimuth = azimuth;}
|
||||
static void setAltitude(int altitude) {_altitude = altitude;}
|
||||
static void setZFactor(double z) {_z = z;}
|
||||
|
||||
private:
|
||||
static int _alpha;
|
||||
static int _blur;
|
||||
static int _azimuth;
|
||||
static int _altitude;
|
||||
static double _z;
|
||||
};
|
||||
|
||||
#endif // HILLSHADING_H
|
||||
|
@ -442,10 +442,14 @@ void RasterTile::drawPaths(QPainter *painter, const QList<MapData::Path> &paths,
|
||||
painter->drawEllipse(ll2xy(point->coordinates), radius, radius);
|
||||
} else {
|
||||
if (_hillShading) {
|
||||
MatrixD dem(Filter::blur(elevation(BLUR_RADIUS + 1),
|
||||
BLUR_RADIUS));
|
||||
QImage img(HillShading::render(dem, BLUR_RADIUS + 1));
|
||||
painter->drawImage(_rect.x(), _rect.y(), img);
|
||||
if (HillShading::blur()) {
|
||||
MatrixD dem(Filter::blur(elevation(HillShading::blur() + 1),
|
||||
HillShading::blur()));
|
||||
QImage img(HillShading::render(dem, HillShading::blur() + 1));
|
||||
painter->drawImage(_rect.x(), _rect.y(), img);
|
||||
} else
|
||||
painter->drawImage(_rect.x(), _rect.y(),
|
||||
HillShading::render(elevation(1), 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user