OpenCPN Partial API docs
Loading...
Searching...
No Matches
viewport.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: OpenCPN ViewPort
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2015 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 ***************************************************************************
25 *
26 *
27 *
28 */
29
30#ifndef __OCPNVIEWPORT_H__
31#define __OCPNVIEWPORT_H__
32
33#include "bbox.h"
34class OCPNRegion;
35class LLRegion;
36
37#if !defined(NAN)
38static const long long lNaN = 0xfff8000000000000;
39#define NAN (*(double *)&lNaN)
40#endif
41
42#if 0
43// ChartType constants
44typedef enum ChartTypeEnum
45{
46 CHART_TYPE_UNKNOWN = 0,
47 CHART_TYPE_DUMMY,
48 CHART_TYPE_DONTCARE,
49 CHART_TYPE_KAP,
50 CHART_TYPE_GEO,
51 CHART_TYPE_S57,
52 CHART_TYPE_CM93,
53 CHART_TYPE_CM93COMP,
54 CHART_TYPE_PLUGIN
55}_ChartTypeEnum;
56
57// ChartFamily constants
58typedef enum ChartFamilyEnum
59{
60 CHART_FAMILY_UNKNOWN = 0,
61 CHART_FAMILY_RASTER,
62 CHART_FAMILY_VECTOR,
63 CHART_FAMILY_DONTCARE
64}_ChartFamilyEnum;
65
66typedef enum ColorScheme
67{
68 GLOBAL_COLOR_SCHEME_RGB,
69 GLOBAL_COLOR_SCHEME_DAY,
70 GLOBAL_COLOR_SCHEME_DUSK,
71 GLOBAL_COLOR_SCHEME_NIGHT,
72 N_COLOR_SCHEMES
73}_ColorScheme;
74#endif
75
76#define INVALID_COORD (-2147483647 - 1)
77
84class ViewPort {
85public:
86 ViewPort();
87
96 wxPoint GetPixFromLL(double lat, double lon);
104 void GetLLFromPix(const wxPoint &p, double *lat, double *lon) {
105 GetLLFromPix(wxPoint2DDouble(p), lat, lon);
106 }
114 void GetLLFromPix(const wxPoint2DDouble &p, double *lat, double *lon);
122 wxPoint2DDouble GetDoublePixFromLL(double lat, double lon);
123
124 LLRegion GetLLRegion(const OCPNRegion &region);
133 const LLRegion &llregion,
134 int chart_native_scale);
135
146 OCPNRegion GetVPRegionIntersect(const OCPNRegion &Region, int nPoints,
147 float *llpoints, int chart_native_scale,
148 wxPoint *ppoints);
155 wxRect GetVPRectIntersect(size_t n, float *llpoints);
156 ViewPort BuildExpandedVP(int width, int height);
157
158 void SetBoxes(void);
170 void SetPixelScale(double scale);
171
172 // Accessors
173 void Invalidate() { bValid = false; }
174 void Validate() { bValid = true; }
175 bool IsValid() const { return bValid; }
176
177 void SetRotationAngle(double angle_rad) { rotation = angle_rad; }
178 void SetProjectionType(int type) { m_projection_type = type; }
179
180 LLBBox &GetBBox() { return vpBBox; }
181
182 void SetBBoxDirect(const LLBBox &bbox) { vpBBox = bbox; }
183 void SetBBoxDirect(double latmin, double lonmin, double latmax,
184 double lonmax);
185
186 bool ContainsIDL();
187 void InvalidateTransformCache() { lat0_cache = NAN; }
188 void SetVPTransformMatrix();
189
190 // Generic
192 double clat;
194 double clon;
207 double skew;
209 double rotation;
211 double tilt;
212
216 double ref_scale;
217
222
223 bool b_quilt;
224 bool b_FullScreenQuilt;
225
226 int m_projection_type;
227 bool b_MercatorProjectionOverride;
228 wxRect rv_rect;
229
230 // #ifdef USE_ANDROID_GLES2
231 float vp_matrix_transform[16];
232 float norm_transform[16];
233 // #endif
234
235 bool operator==(const ViewPort &rhs) const {
236 return (clat == rhs.clat) && (clon == rhs.clon) &&
237 (view_scale_ppm == rhs.view_scale_ppm) && (skew == rhs.skew) &&
238 (rotation == rhs.rotation) && (tilt == rhs.tilt) &&
239 (chart_scale == rhs.chart_scale) && (ref_scale == rhs.ref_scale) &&
240 (pix_width == rhs.pix_width) && (pix_height == rhs.pix_height) &&
241 (b_quilt == rhs.b_quilt) &&
242 (b_FullScreenQuilt == rhs.b_FullScreenQuilt) &&
243 (m_projection_type == rhs.m_projection_type) &&
244 (b_MercatorProjectionOverride == rhs.b_MercatorProjectionOverride);
245 }
246
247private:
248 LLBBox vpBBox; // An un-skewed rectangular lat/lon bounding box
249 // which contains the entire vieport
250
251 bool bValid; // This VP is valid
252
253 double lat0_cache, cache0, cache1;
254
256 double m_displayScale;
257};
258
259#endif
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
double view_scale_ppm
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition viewport.h:199
double ref_scale
The nominal scale of the "reference chart" for this view.
Definition viewport.h:216
int pix_height
Height of the viewport in physical pixels.
Definition viewport.h:221
double rotation
Rotation angle of the viewport in radians.
Definition viewport.h:209
void SetPixelScale(double scale)
Set the physical to logical pixel ratio for the display.
Definition viewport.cpp:133
wxRect GetVPRectIntersect(size_t n, float *llpoints)
Get the viewport rectangle intersecting with a set of lat/lon points.
Definition viewport.cpp:798
int pix_width
Width of the viewport in physical pixels.
Definition viewport.h:219
wxPoint2DDouble GetDoublePixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.
Definition viewport.cpp:145
double tilt
Tilt angle for perspective view in radians.
Definition viewport.h:211
double skew
Angular distortion (shear transform) applied to the viewport in radians.
Definition viewport.h:207
void GetLLFromPix(const wxPoint &p, double *lat, double *lon)
Convert physical pixel coordinates on the ViewPort to latitude and longitude.
Definition viewport.h:104
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:419
double clon
Center longitude of the viewport in degrees.
Definition viewport.h:194
double clat
Center latitude of the viewport in degrees.
Definition viewport.h:192
wxPoint GetPixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates.
Definition viewport.cpp:136
double chart_scale
Chart scale denominator (e.g., 50000 for a 1:50000 scale).
Definition viewport.h:214