OpenCPN Partial API docs
Loading...
Searching...
No Matches
mbtiles.h
1/***************************************************************************
2 * Copyright (C) 2018 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19
20#ifndef _CHARTMBTILES_H_
21#define _CHARTMBTILES_H_
22
23#include <cstdint>
24#include <thread>
25
26#include "chartbase.h"
27#include "model/georef.h" // for GeoRef type
28#include "OCPNRegion.h"
29#include "ocpn_pixel.h"
30#include "viewport.h"
31#include "tile_descr.h"
32#include "tile_thread.h"
33#include "tile_cache.h"
34
35#ifdef ocpnUSE_GL
36#include "shaders.h"
37#endif
38
40enum class MbTilesType : std::int8_t {
41 BASE,
42 OVERLAY
43};
44
46enum class MbTilesScheme : std::int8_t {
47 XYZ,
49 TMS
51};
52
69class ChartMbTiles : public ChartBase {
70public:
72 virtual ~ChartMbTiles();
73
74 // Accessors
75
80 virtual ThumbData* GetThumbData(int tnx, int tny, float lat, float lon);
81 virtual ThumbData* GetThumbData();
82 virtual bool UpdateThumbData(double lat, double lon);
83
84 virtual bool AdjustVP(ViewPort& vp_last, ViewPort& vp_proposed);
85
86 int GetNativeScale() { return m_Chart_Scale; }
87
92 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
93
98 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
99
100 virtual InitReturn Init(const wxString& name, ChartInitFlag init_flags);
101
102 bool RenderRegionViewOnDC(wxMemoryDC& dc, const ViewPort& VPoint,
103 const OCPNRegion& Region);
104
105 virtual bool RenderRegionViewOnGL(const wxGLContext& glc,
106 const ViewPort& vpoint,
107 const OCPNRegion& rect_region,
108 const LLRegion& region);
109
110 virtual double GetNearestPreferredScalePPM(double target_scale_ppm);
111
112 virtual void GetValidCanvasRegion(const ViewPort& v_point,
113 OCPNRegion* valid_region);
114 virtual LLRegion GetValidRegion();
115
116 virtual bool GetChartExtent(Extent* pext);
117
118 void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
119
120 double GetPPM() { return m_ppm_avg; }
121 double GetZoomFactor() { return m_zoom_scale_factor; }
122 MbTilesType GetTileType() { return m_tile_type; }
123
124protected:
125 // Methods
126 bool RenderViewOnDC(wxMemoryDC& dc, const ViewPort& VPoint);
127 InitReturn PreInit(const wxString& name, ChartInitFlag init_flags,
128 ColorScheme cs);
129 InitReturn PostInit(void);
130
131 void PrepareTiles();
132 void PrepareTilesForZoom(int zoomFactor, bool bset_geom);
133
142 bool GetTileTexture(SharedTilePtr tile);
143 void FlushTiles(void);
144 bool RenderTile(SharedTilePtr tile, int zoom_level, const ViewPort& vpoint);
145
146 // Protected Data
147
148 float m_lon_max;
149 float m_lon_min;
150 float m_lat_max;
151 float m_lat_min;
152
153 double m_ppm_avg; // Calculated true scale factor of the 1X chart,
154 // pixels per meter
155 MbTilesType m_tile_type;
156
157 int m_b_cdebug;
158
159 int m_min_zoom;
160 int m_max_zoom;
161 std::unique_ptr<TileCache> m_tile_cache;
162 LLRegion m_min_zoom_region;
163 wxBitmapType m_image_type;
164 int m_last_clean_zoom;
165
166 double m_zoom_scale_factor;
167
168 MbTilesScheme m_scheme;
169
170 std::shared_ptr<SQLite::Database> m_db;
171 int m_n_tiles;
172 std::string m_format;
173
174 uint32_t m_tile_count;
175 std::unique_ptr<MbtTilesThread> m_worker_thread;
176 std::thread m_thread;
177
178#ifdef ocpnUSE_GL
179 GLShaderProgram* m_tile_shader_program;
180#endif
181
188
191
192private:
193 void InitFromTiles(const wxString& name);
194 wxPoint2DDouble GetDoublePixFromLL(ViewPort& vp, double lat, double lon);
195};
196
197#endif
Base class for all chart types.
Definition chartbase.h:119
Represents an MBTiles format chart.
Definition mbtiles.h:69
void StopThread()
Stop and delete the worker thread.
virtual ThumbData * GetThumbData(int tnx, int tny, float lat, float lon)
Get the Chart thumbnail data structure, creating the thumbnail bitmap as required.
double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom)
Report recommended minimum scale values for which use of this chart is valid.
bool StartThread()
Create and start the worker thread.
double GetNormalScaleMax(double canvas_scale_factor, int canvas_width)
Report recommended maximum scale values for which use of this chart is valid.
bool GetTileTexture(SharedTilePtr tile)
Loads a tile into OpenGL's texture memory for rendering.
Wrapper class for OpenGL shader programs.
Definition shaders.h:57
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
Represents the view port for chart display in OpenCPN.
Definition viewport.h:84