Marble

ScanlineTextureMapperContext.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Andrew Manson <g.real.ate@gmail.com>
4// SPDX-FileCopyrightText: 2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
5//
6
7#ifndef MARBLE_SCANLINETEXTUREMAPPERCONTEXT_H
8#define MARBLE_SCANLINETEXTUREMAPPERCONTEXT_H
9
10#include <QImage>
11#include <QSize>
12
13#include "GeoSceneTileDataset.h"
14#include "MarbleMath.h"
15#include "MathHelper.h"
16
17namespace Marble
18{
19
20class StackedTile;
21class StackedTileLoader;
22class ViewportParams;
23
24class ScanlineTextureMapperContext
25{
26public:
27 ScanlineTextureMapperContext(StackedTileLoader *const tileLoader, int tileLevel);
28
29 void pixelValueF(const qreal lon, const qreal lat, QRgb *const scanLine);
30 void pixelValue(const qreal lon, const qreal lat, QRgb *const scanLine);
31
32 void pixelValueApproxF(const qreal lon, const qreal lat, QRgb *scanLine, const int n);
33 void pixelValueApprox(const qreal lon, const qreal lat, QRgb *scanLine, const int n);
34
35 static int interpolationStep(const ViewportParams *viewport, MapQuality mapQuality);
36
37 static QImage::Format optimalCanvasImageFormat(const ViewportParams *viewport);
38
39 int globalWidth() const;
40 int globalHeight() const;
41
42private:
43 // method for fast integer calculation
44 void nextTile(int &posx, int &posy);
45
46 // method for precise interpolation
47 void nextTile(qreal &posx, qreal &posy);
48
49 // Converts Radian to global texture coordinates
50 // ( with origin in center, measured in pixel)
51 qreal rad2PixelX(const qreal lon) const;
52 qreal rad2PixelY(const qreal lat) const;
53
54 // Checks whether the pixelValueApprox method will make use of more than
55 // one tile
56 bool isOutOfTileRange(const int itLon, const int itLat, const int itStepLon, const int itStepLat, const int n) const;
57
58 bool isOutOfTileRangeF(const qreal itLon, const qreal itLat, const qreal itStepLon, const qreal itStepLat, const int n) const;
59
60private:
61 StackedTileLoader *const m_tileLoader;
62 GeoSceneAbstractTileProjection::Type const m_textureProjection;
63 /// size of the tiles of the current texture layer
64 QSize const m_tileSize;
65
66 int const m_tileLevel;
67 int const m_globalWidth;
68 int const m_globalHeight;
69 qreal const m_normGlobalWidth;
70 qreal const m_normGlobalHeight;
71
72 const StackedTile *m_tile;
73
74 // Coordinate transformations:
75
76 // Position of the tile in global Texture Coordinates
77 // ( with origin in upper left corner, measured in pixel)
78 int m_tilePosX;
79 int m_tilePosY;
80
81 // Converts global texture coordinates
82 // ( with origin in center, measured in pixel)
83 // to tile coordinates ( measured in pixel )
84 qreal m_toTileCoordinatesLon;
85 qreal m_toTileCoordinatesLat;
86
87 // Previous coordinates
88 qreal m_prevLat;
89 qreal m_prevLon;
90 qreal m_prevPixelX;
91 qreal m_prevPixelY;
92};
93
94inline int ScanlineTextureMapperContext::globalWidth() const
95{
96 return m_globalWidth;
97}
98
99inline int ScanlineTextureMapperContext::globalHeight() const
100{
101 return m_globalHeight;
102}
103
104inline qreal ScanlineTextureMapperContext::rad2PixelX(const qreal lon) const
105{
106 return lon * m_normGlobalWidth;
107}
108
109inline qreal ScanlineTextureMapperContext::rad2PixelY(const qreal lat) const
110{
111 switch (m_textureProjection) {
112 case GeoSceneAbstractTileProjection::Equirectangular:
113 return -lat * m_normGlobalHeight;
114 case GeoSceneAbstractTileProjection::Mercator:
115 if (fabs(lat) < 1.4835) {
116 // We develop the inverse Gudermannian into a MacLaurin Series:
117 // In spite of the many elements needed to get decent
118 // accuracy this is still faster by far than calculating the
119 // trigonometric expression:
120 // return - asinh( tan( lat ) ) * 0.5 * m_normGlobalHeight;
121
122 // We are using the Horner Scheme as a polynom representation
123
124 return -gdInv(lat) * 0.5 * m_normGlobalHeight;
125 }
126 if (lat >= +1.4835)
127 // asinh( tan (1.4835)) => 3.1309587
128 return -3.1309587 * 0.5 * m_normGlobalHeight;
129 if (lat <= -1.4835)
130 // asinh( tan( -1.4835 )) => −3.1309587
131 return 3.1309587 * 0.5 * m_normGlobalHeight;
132 }
133
134 // Dummy value to avoid a warning.
135 return 0.0;
136}
137
138}
139
140#endif
Binds a QML item to a specific geodetic location in screen coordinates.
qreal gdInv(qreal x)
This method is a fast Mac Laurin power series approximation of the.
Definition MarbleMath.h:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.