OpenCPN Partial API docs
Loading...
Searching...
No Matches
viewport.h
1/***************************************************************************
2 * Copyright (C) 2015 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 __OCPNVIEWPORT_H__
21#define __OCPNVIEWPORT_H__
22
23#include "bbox.h"
24#include "color_types.h"
25class OCPNRegion;
26class LLRegion;
27
28#if !defined(NAN)
29static const long long lNaN = 0xfff8000000000000;
30#define NAN (*(double *)&lNaN)
31#endif
32
33#if 0
34// ChartType constants
35typedef enum ChartTypeEnum
36{
37 CHART_TYPE_UNKNOWN = 0,
38 CHART_TYPE_DUMMY,
39 CHART_TYPE_DONTCARE,
40 CHART_TYPE_KAP,
41 CHART_TYPE_GEO,
42 CHART_TYPE_S57,
43 CHART_TYPE_CM93,
44 CHART_TYPE_CM93COMP,
45 CHART_TYPE_PLUGIN
46}_ChartTypeEnum;
47
48// ChartFamily constants
49typedef enum ChartFamilyEnum
50{
51 CHART_FAMILY_UNKNOWN = 0,
52 CHART_FAMILY_RASTER,
53 CHART_FAMILY_VECTOR,
54 CHART_FAMILY_DONTCARE
55}_ChartFamilyEnum;
56
57typedef enum ColorScheme
58{
59 GLOBAL_COLOR_SCHEME_RGB,
60 GLOBAL_COLOR_SCHEME_DAY,
61 GLOBAL_COLOR_SCHEME_DUSK,
62 GLOBAL_COLOR_SCHEME_NIGHT,
63 N_COLOR_SCHEMES
64}_ColorScheme;
65#endif
66
67extern ColorScheme global_color_scheme;
68
69#define INVALID_COORD (-2147483647 - 1)
70
84class ViewPort {
85public:
86 ViewPort();
87
98 wxPoint GetPixFromLL(double lat, double lon);
108 void GetLLFromPix(const wxPoint &p, double *lat, double *lon) {
109 GetLLFromPix(wxPoint2DDouble(p), lat, lon);
110 }
118 void GetLLFromPix(const wxPoint2DDouble &p, double *lat, double *lon);
126 wxPoint2DDouble GetDoublePixFromLL(double lat, double lon);
127
128 LLRegion GetLLRegion(const OCPNRegion &region);
137 const LLRegion &llregion,
138 int chart_native_scale);
139
150 OCPNRegion GetVPRegionIntersect(const OCPNRegion &Region, int nPoints,
151 float *llpoints, int chart_native_scale,
152 wxPoint *ppoints);
159 wxRect GetVPRectIntersect(size_t n, float *llpoints);
160 ViewPort BuildExpandedVP(int width, int height);
161
191 void SetBoxes(void);
203 void SetPixelScale(double scale);
204
205 // Accessors
206 void Invalidate() { bValid = false; }
207 void Validate() { bValid = true; }
208 bool IsValid() const { return bValid; }
209
210 void SetRotationAngle(double angle_rad) { rotation = angle_rad; }
211 void SetProjectionType(int type) { m_projection_type = type; }
212
213 LLBBox &GetBBox() { return vpBBox; }
214
215 void SetBBoxDirect(const LLBBox &bbox) { vpBBox = bbox; }
216 void SetBBoxDirect(double latmin, double lonmin, double latmax,
217 double lonmax);
218
219 bool ContainsIDL();
220 void InvalidateTransformCache() { lat0_cache = NAN; }
221 void SetVPTransformMatrix();
222
223 // Generic
225 double clat;
227 double clon;
240 double skew;
242 double rotation;
244 double tilt;
245
249 double ref_scale;
250
262
263 bool b_quilt;
264 bool b_FullScreenQuilt;
265
266 int m_projection_type;
267 bool b_MercatorProjectionOverride;
268 wxRect rv_rect;
269
270 // #ifdef USE_ANDROID_GLES2
271 float vp_matrix_transform[16];
272 float norm_transform[16];
273 // #endif
274
275 bool operator==(const ViewPort &rhs) const {
276 return (clat == rhs.clat) && (clon == rhs.clon) &&
277 (view_scale_ppm == rhs.view_scale_ppm) && (skew == rhs.skew) &&
278 (rotation == rhs.rotation) && (tilt == rhs.tilt) &&
279 (chart_scale == rhs.chart_scale) && (ref_scale == rhs.ref_scale) &&
280 (pix_width == rhs.pix_width) && (pix_height == rhs.pix_height) &&
281 (b_quilt == rhs.b_quilt) &&
282 (b_FullScreenQuilt == rhs.b_FullScreenQuilt) &&
283 (m_projection_type == rhs.m_projection_type) &&
284 (b_MercatorProjectionOverride == rhs.b_MercatorProjectionOverride);
285 }
286
287private:
290 LLBBox vpBBox;
291
292 bool bValid; // This VP is valid
293
294 double lat0_cache, cache0, cache1;
295
297 double m_displayScale;
298};
299
300#endif
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:84
double view_scale_ppm
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition viewport.h:232
double ref_scale
The nominal scale of the "reference chart" for this view.
Definition viewport.h:249
int pix_height
Height of the viewport in physical pixels.
Definition viewport.h:261
void SetBoxes(void)
Computes the bounding box coordinates for the current viewport.
Definition viewport.cpp:825
double rotation
Rotation angle of the viewport in radians.
Definition viewport.h:242
void SetPixelScale(double scale)
Set the physical to logical pixel ratio for the display.
Definition viewport.cpp:135
wxRect GetVPRectIntersect(size_t n, float *llpoints)
Get the viewport rectangle intersecting with a set of lat/lon points.
Definition viewport.cpp:802
int pix_width
Width of the viewport in physical pixels.
Definition viewport.h:259
wxPoint2DDouble GetDoublePixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.
Definition viewport.cpp:147
double tilt
Tilt angle for perspective view in radians.
Definition viewport.h:244
double skew
Angular distortion (shear transform) applied to the viewport in radians.
Definition viewport.h:240
void GetLLFromPix(const wxPoint &p, double *lat, double *lon)
Convert physical pixel coordinates on the ViewPort to latitude and longitude.
Definition viewport.h:108
OCPNRegion GetVPRegionIntersect(const OCPNRegion &region, const LLRegion &llregion, int chart_native_scale)
Get the intersection of the viewport with a given region.
Definition viewport.cpp:423
double clon
Center longitude of the viewport in degrees.
Definition viewport.h:227
double clat
Center latitude of the viewport in degrees.
Definition viewport.h:225
wxPoint GetPixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates.
Definition viewport.cpp:138
double chart_scale
Chart scale denominator (e.g., 50000 for a 1:50000 scale).
Definition viewport.h:247