OpenCPN Partial API docs
Loading...
Searching...
No Matches
gshhs.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: GSHHS Chart Object (Global Self-consistent, Hierarchical,
5 *High-resolution Shoreline) Author: Jesper Weissglas for the OpenCPN port.
6 *
7 * Derived from http://www.zygrib.org/ and
8 *http://sourceforge.net/projects/qtvlm/ which has the original copyright:
9 * zUGrib: meteorologic GRIB file data viewer
10 * Copyright (C) 2008 - Jacques Zaninetti - http://www.zygrib.org
11 *
12 ***************************************************************************
13 * Copyright (C) 2012 by David S. Register *
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
19 * *
20 * This program is distributed in the hope that it will be useful, *
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23 * GNU General Public License for more details. *
24 * *
25 * You should have received a copy of the GNU General Public License *
26 * along with this program; if not, write to the *
27 * Free Software Foundation, Inc., *
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
29 ***************************************************************************
30 *
31 *
32 */
33
34#ifndef GSHHS_H
35#define GSHHS_H
36
37#include <stdio.h>
38#include <string>
39#include <math.h>
40#include <assert.h>
41#include <vector>
42
43#include <wx/geometry.h>
44
45#include "ocpn_types.h"
46//#include "ocpndc.h"
47#include "viewport.h"
48#include "cutil.h"
49#include "poly_math.h"
50#include "color_types.h"
51
52#ifdef __MSVC__
53#pragma warning(disable : 4251) // relates to std::string fpath
54#endif
55
56//-------------------------------------------------------------------------
57// Subset of original Projection, only whats needed for GSHHS.
58
59#ifndef M_PI_2
60#define M_PI_2 1.57079632679489661923
61#endif
62#ifndef M_PI_4
63#define M_PI_4 0.785398163397448309616
64#endif
65
66//-------------------------------------------------------------------------
67class wxLineF {
68public:
69 wxLineF(double x1, double y1, double x2, double y2) {
70 m_p1 = wxRealPoint(x1, y1);
71 m_p2 = wxRealPoint(x2, y2);
72 }
73 wxRealPoint &p1() { return m_p1; }
74 wxRealPoint &p2() { return m_p2; }
75 wxRealPoint m_p1, m_p2;
76};
77
79 int version;
80 int pasx;
81 int pasy;
82 int xmin;
83 int ymin;
84 int xmax;
85 int ymax;
86 int p1;
87 int p2;
88 int p3;
89 int p4;
90 int p5;
91};
92
93typedef std::vector<wxRealPoint> contour;
94typedef std::vector<contour> contour_list;
95#define GSSH_SUBM 16 // divide each cell to 16x16 sub cells
96
97//==========================================================================
98
100public:
101 GshhsPolyCell(FILE *fpoly, int x0, int y0, PolygonFileHeader *header);
103
104 void ClearPolyV();
105
106 void drawMapPlain(ocpnDC &pnt, double dx, ViewPort &vp, wxColor seaColor,
107 wxColor landColor, bool idl);
108
109 void drawSeaBorderLines(ocpnDC &pnt, double dx, ViewPort &vp);
110 std::vector<wxLineF> *getCoasts() { return &coasts; }
111 contour_list &getPoly1() { return poly1; }
112
113 /* we remap the segments into a high resolution map to
114 greatly reduce intersection testing time */
115 std::vector<wxLineF> *high_res_map[GSSH_SUBM * GSSH_SUBM];
116
117private:
118 int nbpoints;
119 int x0cell, y0cell;
120
121 FILE *fpoly;
122
123 std::vector<wxLineF> coasts;
124 PolygonFileHeader *header;
125 contour_list poly1, poly2, poly3, poly4, poly5;
126
127 // used for opengl vertex cache
128 float_2Dpt *polyv[6];
129 int polyc[6];
130
131 void DrawPolygonFilled(ocpnDC &pnt, contour_list *poly, double dx,
132 ViewPort &vp, wxColor const &color);
133#ifdef ocpnUSE_GL
134 void DrawPolygonFilledGL(ocpnDC &pnt, contour_list *p, float_2Dpt **pv, int *pvc,
135 ViewPort &vp, wxColor const &color, bool idl);
136#endif
137 void DrawPolygonContour(ocpnDC &pnt, contour_list *poly, double dx,
138 ViewPort &vp);
139
140 void ReadPoly(contour_list &poly);
141 void ReadPolygonFile();
142};
143
145public:
146 GshhsPolyReader(int quality);
148
149 void drawGshhsPolyMapPlain(ocpnDC &pnt, ViewPort &vp, wxColor const &seaColor,
150 wxColor const &landColor);
151
152 void drawGshhsPolyMapSeaBorders(ocpnDC &pnt, ViewPort &vp);
153
154 void InitializeLoadQuality(int quality); // 5 levels: 0=low ... 4=full
155 bool crossing1(wxLineF trajectWorld);
156 int currentQuality;
157 int ReadPolyVersion();
158 int GetPolyVersion() { return polyHeader.version; }
159
160private:
161 FILE *fpoly;
162 GshhsPolyCell *allCells[360][180];
163
164 PolygonFileHeader polyHeader;
165 void readPolygonFileHeader(FILE *polyfile, PolygonFileHeader *header);
166
167 wxMutex mutex1, mutex2;
168
169 ViewPort last_rendered_vp;
170};
171
172// GSHHS file format:
173//
174// int id; /* Unique polygon id number, starting at 0 */
175// int n; /* Number of points in this polygon */
176// int flag; /* level + version << 8 + greenwich << 16 + source <<
177// 24 */ int west, east, south, north; /* min/max extent in micro-degrees */ int
178// area; /* Area of polygon in 1/10 km^2 */
179//
180// Here, level, version, greenwhich, and source are
181// level: 1 land, 2 lake, 3 island_in_lake, 4 pond_in_island_in_lake
182// version: Set to 4 for GSHHS version 1.4
183// greenwich: 1 if Greenwich is crossed
184// source: 0 = CIA WDBII, 1 = WVS
185
186//==========================================================
188public:
189 double lon, lat; // longitude, latitude
190 GshhsPoint(double lo, double la) {
191 lon = lo;
192 lat = la;
193 }
194};
195
196//==========================================================
197
199public:
200 GshhsPolygon(FILE *file);
201
202 virtual ~GshhsPolygon();
203
204 int getLevel() { return flag & 255; }
205 int isGreenwich() { return greenwich; }
206 int isAntarctic() { return antarctic; }
207 bool isOk() { return ok; }
208 int readInt4();
209 int readInt2();
210
211 int id; /* Unique polygon id number, starting at 0 */
212 int n; /* Number of points in this polygon */
213 int flag; /* level + version << 8 + greenwich << 16 + source << 24 */
214 double west, east, south, north; /* min/max extent in DEGREES */
215 int area; /* Area of polygon in 1/10 km^2 */
216 int areaFull, container, ancestor;
217
218 std::vector<GshhsPoint *> lsPoints;
219
220protected:
221 FILE *file;
222 bool ok;
223 bool greenwich, antarctic;
224};
225
226//==========================================================
227
229public:
230 GshhsReader();
231 ~GshhsReader();
232
233 void drawContinents(ocpnDC &pnt, ViewPort &vp, wxColor const &seaColor,
234 wxColor const &landColor);
235
236 void drawSeaBorders(ocpnDC &pnt, ViewPort &vp);
237 void drawBoundaries(ocpnDC &pnt, ViewPort &vp);
238 void drawRivers(ocpnDC &pnt, ViewPort &vp);
239
240 int GetPolyVersion() { return gshhsPoly_reader->GetPolyVersion(); }
241
242 static wxString getNameExtension(int quality);
243 static wxString getFileName_boundaries(int quality);
244 static wxString getFileName_rivers(int quality);
245 static wxString getFileName_Land(int quality);
246 static bool gshhsFilesExists(int quality);
247
248 int getQuality() { return quality; }
249
250 // bool crossing( wxLineF traject, wxLineF trajectWorld ) const;
251 bool crossing1(wxLineF trajectWorld);
252 int ReadPolyVersion();
253 bool qualityAvailable[6];
254
255 void LoadQuality(int quality);
256 int GetMinAvailableQuality() { return minQualityAvailable; }
257 int GetMaxAvailableQuality() { return maxQualityAvailable; }
258
259private:
260 int quality; // 5 levels: 0=low ... 4=full
261 int selectBestQuality(void);
262 int selectBestQuality(ViewPort &vp);
263
264 int maxQualityAvailable;
265 int minQualityAvailable;
266
267 std::string fpath; // directory containing gshhs files
268
269 GshhsPolyReader *gshhsPoly_reader;
270
271 std::vector<GshhsPolygon *> *lsPoly_boundaries[5];
272 std::vector<GshhsPolygon *> *lsPoly_rivers[5];
273
274 std::vector<GshhsPolygon *> &getList_boundaries();
275 std::vector<GshhsPolygon *> &getList_rivers();
276 //-----------------------------------------------------
277
278 int GSHHS_scaledPoints(GshhsPolygon *pol, wxPoint *pts, double decx,
279 ViewPort &vp);
280
281 void GsshDrawLines(ocpnDC &pnt, std::vector<GshhsPolygon *> &lst,
282 ViewPort &vp, bool isClosed);
283 void clearLists();
284};
285
286inline bool GshhsReader::crossing1(wxLineF trajectWorld) {
287 return this->gshhsPoly_reader->crossing1(trajectWorld);
288}
289#define GSHHS_SCL 1.0e-6 /* Convert micro-degrees to degrees */
290
291//-------------------------------------------------------------------------------
292
294public:
295 GSHHSChart();
296 ~GSHHSChart();
297 void SetColorScheme(ColorScheme scheme);
298 void RenderViewOnDC(ocpnDC &dc, ViewPort &VPoint);
299 void Reset();
300 void SetColorsDirect(wxColour newLand, wxColour newWater);
301
302 wxColor land;
303 wxColor water;
304 int GetMinAvailableQuality();
305 int GetMaxAvailableQuality();
306
307private:
308 GshhsReader *reader;
309};
310
311void gshhsCrossesLandInit();
312void gshhsCrossesLandReset();
313bool gshhsCrossesLand(double lat1, double lon1, double lat2, double lon2);
314
315#endif
Definition: ocpndc.h:55
Definition: gshhs.h:67