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 "ocpn_region.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();
130
131 bool GetTileBasicProps(const wxString& name);
132
133 void PrepareTiles();
134 void PrepareTilesForZoom(int zoomFactor, bool bset_geom);
135
144 bool GetTileTexture(SharedTilePtr tile);
145 void FlushTiles();
146 bool RenderTile(SharedTilePtr tile, int zoom_level, const ViewPort& vpoint);
147
148 // Protected Data
149
150 float m_lon_max;
151 float m_lon_min;
152 float m_lat_max;
153 float m_lat_min;
154
155 double m_ppm_avg; // Calculated true scale factor of the 1X chart,
156 // pixels per meter
157 MbTilesType m_tile_type;
158
159 int m_b_cdebug;
160
161 int m_min_zoom;
162 int m_max_zoom;
163 std::unique_ptr<TileCache> m_tile_cache;
164 LLRegion m_min_zoom_region;
165 wxBitmapType m_image_type;
166 int m_last_clean_zoom;
167
168 double m_zoom_scale_factor;
169
170 MbTilesScheme m_scheme;
171
172 std::shared_ptr<SQLite::Database> m_db;
173 int m_n_tiles;
174 std::string m_format;
175
176 uint32_t m_tile_count;
177 std::unique_ptr<MbtTilesThread> m_worker_thread;
178 std::thread m_thread;
179
180#ifdef ocpnUSE_GL
181 GLShaderProgram* m_tile_shader_program;
182#endif
183
190
193
194private:
195 void InitFromTiles(const wxString& name);
196 wxPoint2DDouble GetDoublePixFromLL(ViewPort& vp, double lat, double lon);
197};
198
199#endif
General chart base definitions.
Base class for all chart types.
Definition chartbase.h:126
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 ocpn_region.h:37
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:56
OpenCPN Georef utility.
Optimized wxBitmap Object.
OpenCPN region handling.
OpenGL shader interface.
Geographic projection and coordinate transformations.