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 "model/ocpn_types.h"
46// #include "ocpndc.h"
47#include "viewport.h"
48#include "model/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,
135 int *pvc, ViewPort &vp, wxColor const &color,
136 bool idl);
137#endif
138 void DrawPolygonContour(ocpnDC &pnt, contour_list *poly, double dx,
139 ViewPort &vp);
140
141 void ReadPoly(contour_list &poly);
142 void ReadPolygonFile();
143};
144
146public:
147 GshhsPolyReader(int quality);
149
150 void drawGshhsPolyMapPlain(ocpnDC &pnt, ViewPort &vp, wxColor const &seaColor,
151 wxColor const &landColor);
152
153 void drawGshhsPolyMapSeaBorders(ocpnDC &pnt, ViewPort &vp);
154
155 void InitializeLoadQuality(int quality); // 5 levels: 0=low ... 4=full
156 bool crossing1(wxLineF trajectWorld);
157 int currentQuality;
158 int ReadPolyVersion();
159 int GetPolyVersion() { return polyHeader.version; }
160
161private:
162 FILE *fpoly;
163 GshhsPolyCell *allCells[360][180];
164
165 PolygonFileHeader polyHeader;
166 void readPolygonFileHeader(FILE *polyfile, PolygonFileHeader *header);
167
168 wxMutex mutex1, mutex2;
169
170 ViewPort last_rendered_vp;
171};
172
173// GSHHS file format:
174//
175// int id; /* Unique polygon id number, starting at 0 */
176// int n; /* Number of points in this polygon */
177// int flag; /* level + version << 8 + greenwich << 16 + source <<
178// 24 */ int west, east, south, north; /* min/max extent in micro-degrees */ int
179// area; /* Area of polygon in 1/10 km^2 */
180//
181// Here, level, version, greenwhich, and source are
182// level: 1 land, 2 lake, 3 island_in_lake, 4 pond_in_island_in_lake
183// version: Set to 4 for GSHHS version 1.4
184// greenwich: 1 if Greenwich is crossed
185// source: 0 = CIA WDBII, 1 = WVS
186
187//==========================================================
189public:
190 double lon, lat; // longitude, latitude
191 GshhsPoint(double lo, double la) {
192 lon = lo;
193 lat = la;
194 }
195};
196
197//==========================================================
198
200public:
201 GshhsPolygon(FILE *file);
202
203 virtual ~GshhsPolygon();
204
205 int getLevel() { return flag & 255; }
206 int isGreenwich() { return greenwich; }
207 int isAntarctic() { return antarctic; }
208 bool isOk() { return ok; }
209 int readInt4();
210 int readInt2();
211
212 int id; /* Unique polygon id number, starting at 0 */
213 int n; /* Number of points in this polygon */
214 int flag; /* level + version << 8 + greenwich << 16 + source << 24 */
215 double west, east, south, north; /* min/max extent in DEGREES */
216 int area; /* Area of polygon in 1/10 km^2 */
217 int areaFull, container, ancestor;
218
219 std::vector<GshhsPoint *> lsPoints;
220
221protected:
222 FILE *file;
223 bool ok;
224 bool greenwich, antarctic;
225};
226
227//==========================================================
228
230public:
231 GshhsReader();
232 ~GshhsReader();
233
234 void drawContinents(ocpnDC &pnt, ViewPort &vp, wxColor const &seaColor,
235 wxColor const &landColor);
236
237 void drawSeaBorders(ocpnDC &pnt, ViewPort &vp);
238 void drawBoundaries(ocpnDC &pnt, ViewPort &vp);
239 void drawRivers(ocpnDC &pnt, ViewPort &vp);
240
241 int GetPolyVersion() { return gshhsPoly_reader->GetPolyVersion(); }
242
243 static wxString getNameExtension(int quality);
244 static wxString getFileName_boundaries(int quality);
245 static wxString getFileName_rivers(int quality);
246 static wxString getFileName_Land(int quality);
247 static bool gshhsFilesExists(int quality);
248
249 int getQuality() { return quality; }
250
251 // bool crossing( wxLineF traject, wxLineF trajectWorld ) const;
252 bool crossing1(wxLineF trajectWorld);
253 int ReadPolyVersion();
254 bool qualityAvailable[6];
255
256 void LoadQuality(int quality);
257 int GetMinAvailableQuality() { return minQualityAvailable; }
258 int GetMaxAvailableQuality() { return maxQualityAvailable; }
259
260private:
261 int quality; // 5 levels: 0=low ... 4=full
262 int selectBestQuality(void);
263 int selectBestQuality(ViewPort &vp);
264
265 int maxQualityAvailable;
266 int minQualityAvailable;
267
268 std::string fpath; // directory containing gshhs files
269
270 GshhsPolyReader *gshhsPoly_reader;
271
272 std::vector<GshhsPolygon *> *lsPoly_boundaries[5];
273 std::vector<GshhsPolygon *> *lsPoly_rivers[5];
274
275 std::vector<GshhsPolygon *> &getList_boundaries();
276 std::vector<GshhsPolygon *> &getList_rivers();
277 //-----------------------------------------------------
278
279 int GSHHS_scaledPoints(GshhsPolygon *pol, wxPoint *pts, double decx,
280 ViewPort &vp);
281
282 void GsshDrawLines(ocpnDC &pnt, std::vector<GshhsPolygon *> &lst,
283 ViewPort &vp, bool isClosed);
284 void clearLists();
285};
286
287inline bool GshhsReader::crossing1(wxLineF trajectWorld) {
288 return this->gshhsPoly_reader->crossing1(trajectWorld);
289}
290#define GSHHS_SCL 1.0e-6 /* Convert micro-degrees to degrees */
291
292//-------------------------------------------------------------------------------
293
295public:
296 GSHHSChart();
297 ~GSHHSChart();
298 void SetColorScheme(ColorScheme scheme);
299 void RenderViewOnDC(ocpnDC &dc, ViewPort &VPoint);
300 void Reset();
301 void SetColorsDirect(wxColour newLand, wxColour newWater);
302
303 wxColor land;
304 wxColor water;
305 int GetMinAvailableQuality();
306 int GetMaxAvailableQuality();
307
308private:
309 GshhsReader *reader;
310};
311
312void gshhsCrossesLandInit();
313void gshhsCrossesLandReset();
314bool gshhsCrossesLand(double lat1, double lon1, double lat2, double lon2);
315
316#endif
Represents the view port for chart display in OpenCPN.
Definition viewport.h:84
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:64