OpenCPN Partial API docs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
24class OCPNRegion;
25class LLRegion;
26
27#if !defined(NAN)
28static const long long lNaN = 0xfff8000000000000;
29#define NAN (*(double *)&lNaN)
30#endif
31
32#if 0
33// ChartType constants
34typedef enum ChartTypeEnum
35{
36 CHART_TYPE_UNKNOWN = 0,
37 CHART_TYPE_DUMMY,
38 CHART_TYPE_DONTCARE,
39 CHART_TYPE_KAP,
40 CHART_TYPE_GEO,
41 CHART_TYPE_S57,
42 CHART_TYPE_CM93,
43 CHART_TYPE_CM93COMP,
44 CHART_TYPE_PLUGIN
45}_ChartTypeEnum;
46
47// ChartFamily constants
48typedef enum ChartFamilyEnum
49{
50 CHART_FAMILY_UNKNOWN = 0,
51 CHART_FAMILY_RASTER,
52 CHART_FAMILY_VECTOR,
53 CHART_FAMILY_DONTCARE
54}_ChartFamilyEnum;
55
56typedef enum ColorScheme
57{
58 GLOBAL_COLOR_SCHEME_RGB,
59 GLOBAL_COLOR_SCHEME_DAY,
60 GLOBAL_COLOR_SCHEME_DUSK,
61 GLOBAL_COLOR_SCHEME_NIGHT,
62 N_COLOR_SCHEMES
63}_ColorScheme;
64#endif
65
66#define INVALID_COORD (-2147483647 - 1)
67
81class ViewPort {
82public:
83 ViewPort();
84
95 wxPoint GetPixFromLL(double lat, double lon);
105 void GetLLFromPix(const wxPoint &p, double *lat, double *lon) {
106 GetLLFromPix(wxPoint2DDouble(p), lat, lon);
107 }
115 void GetLLFromPix(const wxPoint2DDouble &p, double *lat, double *lon);
123 wxPoint2DDouble GetDoublePixFromLL(double lat, double lon);
124
125 LLRegion GetLLRegion(const OCPNRegion &region);
134 const LLRegion &llregion,
135 int chart_native_scale);
136
147 OCPNRegion GetVPRegionIntersect(const OCPNRegion &Region, int nPoints,
148 float *llpoints, int chart_native_scale,
149 wxPoint *ppoints);
156 wxRect GetVPRectIntersect(size_t n, float *llpoints);
157 ViewPort BuildExpandedVP(int width, int height);
158
188 void SetBoxes(void);
200 void SetPixelScale(double scale);
201
202 // Accessors
203 void Invalidate() { bValid = false; }
204 void Validate() { bValid = true; }
205 bool IsValid() const { return bValid; }
206
207 void SetRotationAngle(double angle_rad) { rotation = angle_rad; }
208 void SetProjectionType(int type) { m_projection_type = type; }
209
210 LLBBox &GetBBox() { return vpBBox; }
211
212 void SetBBoxDirect(const LLBBox &bbox) { vpBBox = bbox; }
213 void SetBBoxDirect(double latmin, double lonmin, double latmax,
214 double lonmax);
215
216 bool ContainsIDL();
217 void InvalidateTransformCache() { lat0_cache = NAN; }
218 void SetVPTransformMatrix();
219
220 // Generic
222 double clat;
224 double clon;
237 double skew;
239 double rotation;
241 double tilt;
242
246 double ref_scale;
247
259
260 bool b_quilt;
261 bool b_FullScreenQuilt;
262
263 int m_projection_type;
264 bool b_MercatorProjectionOverride;
265 wxRect rv_rect;
266
267 // #ifdef USE_ANDROID_GLES2
268 float vp_matrix_transform[16];
269 float norm_transform[16];
270 // #endif
271
272 bool operator==(const ViewPort &rhs) const {
273 return (clat == rhs.clat) && (clon == rhs.clon) &&
274 (view_scale_ppm == rhs.view_scale_ppm) && (skew == rhs.skew) &&
275 (rotation == rhs.rotation) && (tilt == rhs.tilt) &&
276 (chart_scale == rhs.chart_scale) && (ref_scale == rhs.ref_scale) &&
277 (pix_width == rhs.pix_width) && (pix_height == rhs.pix_height) &&
278 (b_quilt == rhs.b_quilt) &&
279 (b_FullScreenQuilt == rhs.b_FullScreenQuilt) &&
280 (m_projection_type == rhs.m_projection_type) &&
281 (b_MercatorProjectionOverride == rhs.b_MercatorProjectionOverride);
282 }
283
284private:
287 LLBBox vpBBox;
288
289 bool bValid; // This VP is valid
290
291 double lat0_cache, cache0, cache1;
292
294 double m_displayScale;
295};
296
297#endif
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:81
double view_scale_ppm
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition viewport.h:229
double ref_scale
The nominal scale of the "reference chart" for this view.
Definition viewport.h:246
int pix_height
Height of the viewport in physical pixels.
Definition viewport.h:258
void SetBoxes(void)
Computes the bounding box coordinates for the current viewport.
Definition viewport.cpp:823
double rotation
Rotation angle of the viewport in radians.
Definition viewport.h:239
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:800
int pix_width
Width of the viewport in physical pixels.
Definition viewport.h:256
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:241
double skew
Angular distortion (shear transform) applied to the viewport in radians.
Definition viewport.h:237
void GetLLFromPix(const wxPoint &p, double *lat, double *lon)
Convert physical pixel coordinates on the ViewPort to latitude and longitude.
Definition viewport.h:105
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:421
double clon
Center longitude of the viewport in degrees.
Definition viewport.h:224
double clat
Center latitude of the viewport in degrees.
Definition viewport.h:222
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:244